Commit 108fc3f4 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

fixed problem with non 4:3 cameras (ticket #142)

parent 873b72ed
...@@ -2893,7 +2893,7 @@ public: ...@@ -2893,7 +2893,7 @@ public:
protected: protected:
void init(); void init();
int index; int index, width, height;
IplImage* frame; IplImage* frame;
static videoInput VI; static videoInput VI;
}; };
...@@ -2911,6 +2911,7 @@ CvCaptureCAM_DShow::CvCaptureCAM_DShow() ...@@ -2911,6 +2911,7 @@ CvCaptureCAM_DShow::CvCaptureCAM_DShow()
{ {
index = -1; index = -1;
frame = 0; frame = 0;
width = height = -1;
} }
void CvCaptureCAM_DShow::close() void CvCaptureCAM_DShow::close()
...@@ -2921,6 +2922,7 @@ void CvCaptureCAM_DShow::close() ...@@ -2921,6 +2922,7 @@ void CvCaptureCAM_DShow::close()
index = -1; index = -1;
cvReleaseImage(&frame); cvReleaseImage(&frame);
} }
width = height = -1;
} }
// Initialize camera input // Initialize camera input
...@@ -2977,27 +2979,28 @@ double CvCaptureCAM_DShow::getProperty( int property_id ) ...@@ -2977,27 +2979,28 @@ double CvCaptureCAM_DShow::getProperty( int property_id )
bool CvCaptureCAM_DShow::setProperty( int property_id, double value ) bool CvCaptureCAM_DShow::setProperty( int property_id, double value )
{ {
int width = 0, height = 0;
switch( property_id ) switch( property_id )
{ {
case CV_CAP_PROP_FRAME_WIDTH: case CV_CAP_PROP_FRAME_WIDTH:
width = cvRound(value); width = cvRound(value);
height = width*3/4;
break; break;
case CV_CAP_PROP_FRAME_HEIGHT: case CV_CAP_PROP_FRAME_HEIGHT:
height = cvRound(value); height = cvRound(value);
width = height*4/3;
default: default:
return false; return false;
} }
if( width > 0 && height > 0 )
{
if( width != VI.getWidth(index) || height != VI.getHeight(index) ) if( width != VI.getWidth(index) || height != VI.getHeight(index) )
{ {
VI.stopDevice(index); VI.stopDevice(index);
VI.setupDevice(index, width, height); VI.setupDevice(index, width, height);
} }
width = height = -1;
return VI.isDeviceSetup(index); return VI.isDeviceSetup(index);
}
return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment