0
点赞
收藏
分享

微信扫一扫

opencv截取任一时间段的视频帧

爪哇驿站 2023-03-17 阅读 70


videocapture.set()

我们使用opencv进行读取视频帧的时候都是从开始进行读的,可是我们应该如何从任意帧或者时间进行开始读呢?
我们可以通过​​​videocapture.set方法​​:

VideoCapture::set(int id,double value)

0  CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
1 CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
2 CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file: 0 - start of the film, 1 - end of the film.
3 CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
CV_CAP_PROP_FPS Frame rate.
CV_CAP_PROP_FOURCC 4-character code of codec.
CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
CV_CAP_PROP_FORMAT Format of the Mat objects returned by retrieve() .
CV_CAP_PROP_MODE Backend-specific value indicating the current capture mode.
CV_CAP_PROP_BRIGHTNESS Brightness of the image (only for cameras).
CV_CAP_PROP_CONTRAST Contrast of the image (only for cameras).
CV_CAP_PROP_SATURATION Saturation of the image (only for cameras).
CV_CAP_PROP_HUE Hue of the image (only for cameras).
CV_CAP_PROP_GAIN Gain of the image (only for cameras).
CV_CAP_PROP_EXPOSURE Exposure (only for cameras).
CV_CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
CV_CAP_PROP_WHITE_BALANCE Currently unsupported
CV_CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently)

CV_CAP_PROP_POS_MSEC设置开始的时间(以秒为单位):
以java程序示例:

package opencvtest;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.videoio.VideoCapture;

public class main {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture capture = new VideoCapture();
capture.open("c:/opencv/inputimg/vtest.avi");
HighGui.namedWindow("show");// 创建一个窗口,用来播放视频,窗口通过名字来区分,所以必须要命名。
Mat image = new Mat();//定义一个Mat,用来接收一帧的图像
double frameCount = capture.get(7);
System.out.println("视频总帧数:"+frameCount);
//设置从第2秒开始读
capture.set(0,2*1000);
//读取视频帧
capture.read(image);
//显示帧
HighGui.imshow("show",image);
HighGui.waitKey(0);
}

}

发现读到的就是第二秒视频:

opencv截取任一时间段的视频帧_System


同时也可以通过:

设置第几帧图像开始读;

CV_CAP_PROP_POS_FRAMES

get方法

opencv截取任一时间段的视频帧_System_02


举报

相关推荐

查询某一时间段oracle执行的sql

0 条评论