allow to retrieve videocapture properties before first frame reading
This commit is contained in:
parent
95d6002f16
commit
9d78a1ea9f
@ -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()
|
||||
@ -92,6 +93,7 @@ protected:
|
||||
unsigned length; // length of sequence
|
||||
|
||||
IplImage* frame;
|
||||
bool grabbedInOpen;
|
||||
};
|
||||
|
||||
|
||||
@ -100,7 +102,7 @@ void CvCapture_Images::close()
|
||||
if( filename )
|
||||
{
|
||||
free(filename);
|
||||
filename = 0;
|
||||
filename = NULL;
|
||||
}
|
||||
currentframe = firstframe = 0;
|
||||
length = 0;
|
||||
@ -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 )
|
||||
@ -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)
|
||||
@ -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) {
|
||||
@ -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");
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -290,7 +310,7 @@ CvCapture* cvCreateFileCapture_Images(const char * filename)
|
||||
return capture;
|
||||
|
||||
delete capture;
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user