I'm a beginner at OpenCV.
I'd like to add a function to jump the video according to the location of the track bar, but if you allow the track bar to move while playing the video in cvSetTrackbarPos, it will end as soon as one frame is displayed.
http://opencv.jp/opencv-2svn/cpp/reading_and_writing_images_and_video.html
I changed various settings while looking at the parameters in , but it ended as soon as one frame was displayed.
I don't understand why one frame is displayed and ends immediately.How can I play the video to the end?
#include<opencv/highgui.h>
# include <opencv/cv.h>
# include <iostream>
# include <cstdlib>
using namespace std;
intg_slider_position = 0;
intg_point = 0;
CvCapture*g_capture=NULL;
// Callback when moving the track bar
void onTrackbarSlide(intpos) {
cvSetCaptureProperty(g_capture,
CV_CAP_PROP_POS_AVI_RATIO,
pos
);
cvSetTrackbarPos("Position", "Example 3", pos);
}
int main (int argc, char**argv)
{
const char Wname [ ] = "Example 3";
cvNamedWindow(Wname, CV_WINDOW_AUTOSIZE);
g_capture=cvCreateFileCapture(argv[1]);
// To represent the current position in percentage 100
int frames = 100;
// Because I used the track bar according to the number of frames
(int) cvGetCaptureProperty(
g_capture,
CV_CAP_PROP_FRAME_COUNT
);
IplImage* frame;
if(frames!=0){
// Create Trackbar
cvCreateTrackbar(
"Position",
Wname,
&g_slider_position,
frames,
onTrackbarSlide
);
}
while(1){
frame = cvQueryFrame(g_capture);
if(!frame)break;
cvShowImage (Wname, frame);
charc = cvWaitKey (1000);
if(c==27)break;
// Does not work properly when comment is removed
// cvSetTrackbarPos ("Position", Wname, (int) cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT)*100);
}
return 0;
}
The linked sample program cvCreateTrackbar is incorrectly used.
//(2) Create a window and trackbar
cvNamedWindow("Image", CV_WINDOW_AUTOSIZE);
cvCreateTrackbar("Trackbar1", "Image", 0,100, on_trackbar1);
cvCreateTrackbar("Trackbar2", "Image", 0,100, on_trackbar2);
cvShowImage("Image", img);
cvWaitKey(0);
Please change the one around here as follows
//(2) Create a window and trackbar
cvNamedWindow("Image", CV_WINDOW_AUTOSIZE);
inta = 0, b = 50; // Add
cvCreateTrackbar("Trackbar1", "Image", & a, 100, on_trackbar1); // Change
cvCreateTrackbar("Trackbar2", "Image", & a, 100, on_trackbar2); // Change
cvShowImage("Image", img);
cvWaitKey(0);
As for b, it is my homework to know what will happen if I use it.
© 2024 OneMinuteCode. All rights reserved.