int ReadVideo(char* filename, int t_start, int t_stop){
unsigned int max_num=0;
VideoCapture cap(filename);
if (!cap.isOpened())
{
printf("\nNo Videl found!\n");
return -1;
}
// Num of frames
/*
Property identifier. Can be one of the following:
CV_CAP_PROP_POS_MSEC Film current position in milliseconds or video capture timestamp
CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next
CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file (0 - start of the film, 1 - end of the film)
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 The format of the Mat objects returned by retrieve()
CV_CAP_PROP_MODE A 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 TOWRITE (note: only supported by DC1394 v 2.x backend currently)
*/
int frames = (int)cap.get(CV_CAP_PROP_FRAME_COUNT);
int fps = (int)cap.get(CV_CAP_PROP_FPS);
float vi_time = (float)frames/fps;
if(t_stop == 0 || t_stop > (int)vi_time)
{
t_stop=(int)vi_time;
}
// start frame
int f_start = t_start*fps+1;
// end frame
int f_stop = t_stop*fps;
Mat img;
namedWindow("video capture", CV_WINDOW_AUTOSIZE);
HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
int frs = 0;
while (frs <= frames)
{
cap >> img;
if (!img.data)
continue;
if(frs < f_start || frs > f_stop)
{
frs++;
continue;
}
frs++;
imshow("video capture", img);
if (waitKey(20) >= 0)
break;
}
return 0;
OpenCV读指定时间的视频
最新推荐文章于 2024-07-06 20:04:49 发布