Skip to content

Commit

Permalink
allow to retrieve videocapture properties before first frame reading
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov committed Oct 26, 2015
1 parent 95d6002 commit 9d78a1e
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions modules/highgui/src/cap_images.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ class CvCapture_Images : public CvCapture
public:
CvCapture_Images()
{
filename = 0;
filename = NULL;
currentframe = firstframe = 0;
length = 0;
frame = 0;
frame = NULL;
grabbedInOpen = false;
}

virtual ~CvCapture_Images()
Expand All @@ -92,6 +93,7 @@ class CvCapture_Images : public CvCapture
unsigned length; // length of sequence

IplImage* frame;
bool grabbedInOpen;
};


Expand All @@ -100,7 +102,7 @@ void CvCapture_Images::close()
if( filename )
{
free(filename);
filename = 0;
filename = NULL;
}
currentframe = firstframe = 0;
length = 0;
Expand All @@ -113,6 +115,14 @@ bool CvCapture_Images::grabFrame()
char str[_MAX_PATH];
sprintf(str, filename, firstframe + currentframe);

if (grabbedInOpen)
{
grabbedInOpen = false;
++currentframe;

return true;
}

cvReleaseImage(&frame);
frame = cvLoadImage(str, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
if( frame )
Expand All @@ -123,7 +133,7 @@ bool CvCapture_Images::grabFrame()

IplImage* CvCapture_Images::retrieveFrame(int)
{
return frame;
return grabbedInOpen ? NULL : frame;
}

double CvCapture_Images::getProperty(int id)
Expand Down Expand Up @@ -166,6 +176,8 @@ bool CvCapture_Images::setProperty(int id, double value)
value = length - 1;
}
currentframe = cvRound(value);
if (currentframe != 0)
grabbedInOpen = false; // grabbed frame is not valid anymore
return true;
case CV_CAP_PROP_POS_AVI_RATIO:
if(value > 1) {
Expand All @@ -176,6 +188,8 @@ bool CvCapture_Images::setProperty(int id, double value)
value = 0;
}
currentframe = cvRound((length - 1) * value);
if (currentframe != 0)
grabbedInOpen = false; // grabbed frame is not valid anymore
return true;
}
CV_WARN("unknown/unhandled property\n");
Expand Down Expand Up @@ -278,6 +292,12 @@ bool CvCapture_Images::open(const char * _filename)
}

firstframe = offset;

// grab frame to enable properties retrieval
grabFrame();
grabbedInOpen = true;
currentframe = 0;

return true;
}

Expand All @@ -290,7 +310,7 @@ CvCapture* cvCreateFileCapture_Images(const char * filename)
return capture;

delete capture;
return 0;
return NULL;
}

//
Expand Down

0 comments on commit 9d78a1e

Please sign in to comment.