mirror of
https://github.com/opencv/opencv.git
synced 2025-01-19 06:53:50 +08:00
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:
|
public:
|
||||||
CvCapture_Images()
|
CvCapture_Images()
|
||||||
{
|
{
|
||||||
filename = 0;
|
filename = NULL;
|
||||||
currentframe = firstframe = 0;
|
currentframe = firstframe = 0;
|
||||||
length = 0;
|
length = 0;
|
||||||
frame = 0;
|
frame = NULL;
|
||||||
|
grabbedInOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~CvCapture_Images()
|
virtual ~CvCapture_Images()
|
||||||
@ -92,6 +93,7 @@ protected:
|
|||||||
unsigned length; // length of sequence
|
unsigned length; // length of sequence
|
||||||
|
|
||||||
IplImage* frame;
|
IplImage* frame;
|
||||||
|
bool grabbedInOpen;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -100,7 +102,7 @@ void CvCapture_Images::close()
|
|||||||
if( filename )
|
if( filename )
|
||||||
{
|
{
|
||||||
free(filename);
|
free(filename);
|
||||||
filename = 0;
|
filename = NULL;
|
||||||
}
|
}
|
||||||
currentframe = firstframe = 0;
|
currentframe = firstframe = 0;
|
||||||
length = 0;
|
length = 0;
|
||||||
@ -113,6 +115,14 @@ bool CvCapture_Images::grabFrame()
|
|||||||
char str[_MAX_PATH];
|
char str[_MAX_PATH];
|
||||||
sprintf(str, filename, firstframe + currentframe);
|
sprintf(str, filename, firstframe + currentframe);
|
||||||
|
|
||||||
|
if (grabbedInOpen)
|
||||||
|
{
|
||||||
|
grabbedInOpen = false;
|
||||||
|
++currentframe;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
cvReleaseImage(&frame);
|
cvReleaseImage(&frame);
|
||||||
frame = cvLoadImage(str, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
|
frame = cvLoadImage(str, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR);
|
||||||
if( frame )
|
if( frame )
|
||||||
@ -123,7 +133,7 @@ bool CvCapture_Images::grabFrame()
|
|||||||
|
|
||||||
IplImage* CvCapture_Images::retrieveFrame(int)
|
IplImage* CvCapture_Images::retrieveFrame(int)
|
||||||
{
|
{
|
||||||
return frame;
|
return grabbedInOpen ? NULL : frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
double CvCapture_Images::getProperty(int id)
|
double CvCapture_Images::getProperty(int id)
|
||||||
@ -166,6 +176,8 @@ bool CvCapture_Images::setProperty(int id, double value)
|
|||||||
value = length - 1;
|
value = length - 1;
|
||||||
}
|
}
|
||||||
currentframe = cvRound(value);
|
currentframe = cvRound(value);
|
||||||
|
if (currentframe != 0)
|
||||||
|
grabbedInOpen = false; // grabbed frame is not valid anymore
|
||||||
return true;
|
return true;
|
||||||
case CV_CAP_PROP_POS_AVI_RATIO:
|
case CV_CAP_PROP_POS_AVI_RATIO:
|
||||||
if(value > 1) {
|
if(value > 1) {
|
||||||
@ -176,6 +188,8 @@ bool CvCapture_Images::setProperty(int id, double value)
|
|||||||
value = 0;
|
value = 0;
|
||||||
}
|
}
|
||||||
currentframe = cvRound((length - 1) * value);
|
currentframe = cvRound((length - 1) * value);
|
||||||
|
if (currentframe != 0)
|
||||||
|
grabbedInOpen = false; // grabbed frame is not valid anymore
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CV_WARN("unknown/unhandled property\n");
|
CV_WARN("unknown/unhandled property\n");
|
||||||
@ -278,6 +292,12 @@ bool CvCapture_Images::open(const char * _filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
firstframe = offset;
|
firstframe = offset;
|
||||||
|
|
||||||
|
// grab frame to enable properties retrieval
|
||||||
|
grabFrame();
|
||||||
|
grabbedInOpen = true;
|
||||||
|
currentframe = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +310,7 @@ CvCapture* cvCreateFileCapture_Images(const char * filename)
|
|||||||
return capture;
|
return capture;
|
||||||
|
|
||||||
delete capture;
|
delete capture;
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user