- I has this problem since version 2.2 until now version 2.4
- I attached pictures from my customer to compare
C:\fakepath\Tendo - Old Program - Windows Library.jpg C:\fakepath\Tendo - New Program - OpenCV 2.4.jpg
And this is sourcecode : -
IplImage *image = 0;
// const int MAX_COUNT = 500;
// char* status = 0;
int night_mode = 0;
// int flags = 0;
CvCapture* capture = 0;
CvVideoWriter * writer = 0;
sprintf(_window_name, "CAMERA : %d", _request_cam_id+1);
cvNamedWindow( _window_name, 0 );
// Set Always on Top
int x = CAPTURE_WINDOW_OFFSET;
int y = CAPTURE_WINDOW_OFFSET;
setWindowAlwaysTop(_window_name, x, y, CAPTURE_WINDOW_WIDTH, CAPTURE_WINDOW_HEIGHT);
disableCloseWindowButton(_window_name);
capture = cvCaptureFromCAM(CV_CAP_DSHOW + _request_cam_id );
_camera = _request_cam_id;
cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, CAPTURE_FPS); // 10
qDebug() << cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH) << cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
double f = 1.0;
double w = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH) * f;
double h = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT) * f;
if(f != 1.0)
{
// set camera properties 320x240 is the best resolution
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, w); //opencv doesnt like 640x480
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, h); //as most webcams use YUYV/YUY2 codecs.
}
if( ! capture )
{
const QString errText("Could not initialize capturing...\n");
qDebug() << errText;
writeLog(errText);
return;
}
while( _request_cam_id >= 0 ) // for(;;)
{
if(_request_cam_id != _camera)
{
cvDestroyWindow(_window_name);
if(_camera < 0) break;
sprintf(_window_name, "CAMERA : %d", _request_cam_id+1);
cvNamedWindow( _window_name, 0 );
// Set Always on Top
int x = CAPTURE_WINDOW_OFFSET;
int y = CAPTURE_WINDOW_OFFSET;
setWindowAlwaysTop(_window_name, x, y, CAPTURE_WINDOW_WIDTH, CAPTURE_WINDOW_HEIGHT);
disableCloseWindowButton(_window_name);
capture = cvCaptureFromCAM(CV_CAP_DSHOW + _request_cam_id );
// set camera properties 320x240 is the best resolution
if(f != 1)
{
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, w); //opencv doesnt like 640x480
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, h); //as most webcams use YUYV/YUY2 codecs.
}
cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, CAPTURE_FPS); //Playstation Eye Only: Max FPS goes to 120!!!
_camera = _request_cam_id;
if( ! capture )
{
const QString errText("Could capture from requested camera...\n");
qDebug() << errText;
writeLog(errText);
break;
}
}
IplImage* frame = 0;
int c;
frame = cvQueryFrame( capture );
if( ! frame )
break;
if( ! image )
{
// allocate all the buffers //
// image = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 3 );
qDebug() << "Depth : " << frame->depth << " Channels : " << frame->nChannels;
image = cvCreateImage(cvSize(frame->width, frame->height), frame->depth, frame->nChannels);
image->origin = frame->origin;
// status = (char*)cvAlloc(MAX_COUNT);
// flags = 0;
}
// Clipping
if( ! _camera_clip.isEmpty() )
{
// Custom Clipping
QStringList l = _camera_clip.split(",");
if(l.count() == 4)
{
// x, y, right, bottom
long right = l.at(2).toLong();
long bottom = l.at(3).toLong();
long w = l.at(2).toLong() - l.at(0).toLong();
long h = l.at(3).toLong() - l.at(1).toLong();
qDebug() << QString("Custom camera clip recangle (%1):-\n"
"Left : %2\n"
"Top : %3\n"
"Right : %4\n"
"Bottom: %5\n"
"From %6x%7")
.arg(_camera_clip).arg(l.at(0)).arg(l.at(1)).arg(right).arg(bottom)
.arg(frame->width).arg(frame->height);
if( (right > frame->width) || (bottom > frame->height) )
{
this->error = QString("Invalid clipping value, should not over than %1x%2")
.arg(frame->width).arg(frame->height);
((CaptureForm *)captureForm)->showMessage("INVALID CLIPPING VALUE", this->error);
break;
} else {
CvRect rect = cvRect(l.at(0).toLong(), l.at(1).toLong(), w, h);
cvSetImageROI(frame, rect);
image = cvCreateImage(cvSize(rect.width, rect.height), frame->depth, frame->nChannels);
}
}
}
cvCopy( frame, image, 0 );
/** Marking for Region Of Interest **/
if(_zoom < 1.0)
{
CvRect rect = getZoomRect(image);
cvRectangle(image ...
(more)
src-code, version info, demo img ?
have a look at the faq as well, please.