Updated by Andrey Kamaev almost 13 years ago

Hi,

This issue has been lingering for a while and seems to be only partially resolved now. I even tried the most recent update r7970 to the repository but the setProperty() routine to set frame position of video stream still seems to be broken. The routine works fine if the input frame number is ahead of the cur_dts (current frame?) but it fails to seek to the right position if the supplied frame number is behind the current position. I am supplying the code below that I'm using. I use r7970 built on VS 2008 with GPU (4.0), IPP (5.3), TBB (4.0) and QT (4.0). Two of the videos are also attached. Use 'n' to move forward and 'p' to move backward. Step is set to 200 frames.

<pre><code class="cpp">
int main(int argc, char* argv[])
{
char buffer[1024] = "";
char vname[512] = "inp.mov";

VideoCapture video(vname);
if(!video.isOpened()) {
cout << "Can't open video: " << vname << endl;
return 0;
}
int nFrames = video.get(CV_CAP_PROP_FRAME_COUNT);
int fWidth = video.get(CV_CAP_PROP_FRAME_WIDTH);
int fHeight = video.get(CV_CAP_PROP_FRAME_HEIGHT);

bool done = false;
bool next = false;
int key;

Mat display(fHeight + 200, fWidth, CV_8UC3);
display(Rect(0,fHeight,fWidth,200)) = 0;

namedWindow("Display");

int fNum = 0;
Mat currFrame;
while(!done) {
bool val = video.set(CV_CAP_PROP_POS_FRAMES, fNum);
video >> currFrame;
if(currFrame.empty()) {
cout << "Frame not found" << endl;
}
currFrame.copyTo(display(Rect(0, 0, fWidth, fHeight)));
sprintf(buffer,"%d",fNum);
putText(display, buffer, Point(fWidth - 50, 30), FONT_HERSHEY_PLAIN, 1, CV_RGB(0, 155, 0));
imshow("Display", display);

next = false;
while(!next) {
key = waitKey(0);
switch(key) {
case 'n':
case 'N':
case ' ':
fNum += 20;
display(Rect(0, fHeight+100, fWidth, 100)) = 0;
if(fNum >= nFrames) {
putText(display, "Reached end of the video!", Point(fWidth/2 - 100, fHeight + 180), FONT_HERSHEY_PLAIN, 1, CV_RGB(255,0,0));
fNum -= 20;
}
else
next = true;
break;
case 'p':
case 'P':
fNum -= 20;
display(Rect(0, fHeight+100, fWidth, 100)) = 0;
if(fNum < 0) {
putText(display, "Reached start of the video!", Point(fWidth/2 - 100, fHeight + 180), FONT_HERSHEY_PLAIN, 1, CV_RGB(255,0,0));
fNum += 20;
}
else {
//video.set(CV_CAP_PROP_POS_FRAMES, 0);
next = true;
}
break;
case 'q':
next = true;
done = true;
break;
}
}
}
return 0;
}
</code></pre>

Back