*
* \endcode
*
+ * Setting sizes is done during construction, and are not modifiable
+ * after the fact:
+ * \code
+ * QOpenCamWidget *cw = new QOpenCamWidget(this,
+ * new QSize(320, 240),
+ * new QSize(960, 720));
+ * \endcode
+ *
* \param *parent The parent widget containing this widget, defaults to NULL.
+ * \param *viewSize The size of the image displayed, thus the size of the widget,
+ * defaults to 640x480
+ * \param *resolution The actual resolution captured, and size of the snapshot
+ * created, defaults t0 960x720, should be larger than viewSize
*
**/
-QOpenCamWidget::QOpenCamWidget(QWidget *parent)
+QOpenCamWidget::QOpenCamWidget(QWidget *parent, QSize *viewSize, QSize *resolution)
: QWidget(parent)
{
// Setting sane default values (i.e. NULL) for
// private QTimer *frametimer from class definition
nextFrame = NULL;
frametimer = NULL;
+ if ( viewSize == NULL )
+ {
+ vSize = new QSize(640, 480);
+ }
+ else vSize = viewSize;
+ if ( resolution == NULL )
+ {
+ res = new QSize(960, 720);
+ }
+ else res = resolution;
+
+ this->setMinimumSize(*vSize);
+ this->setMaximumSize(*vSize);
+
}
QOpenCamWidget::~QOpenCamWidget(void)
// To make the widget as blazingly fast as possible
// we output the last captured frame direclty onto
// the widget area.
- paint->drawImage(event->rect(), *nextFrame);
+ // It has been slowed down a bit by doing a resize tho...
+ paint->drawImage(event->rect(), nextFrame->scaled( vSize->width(), vSize->height() ));
}
else
{
qDebug() << "QOpenCamWidget::grabCapture(" << source << ") failed";
return false;
}
- cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 960 );
- cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 720 );
+ cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, res->width() );
+ cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, res->height() );
cvGrabFrame(capture); // Grab a single frame, do resizing based on it.
IplImage *image = cvRetrieveFrame(capture);
- QSize t_size = QSize(image->width,image->height);
-
- this->setMinimumSize(t_size);
- this->setMaximumSize(t_size);
return true;
}
trigger->setText("Take picture");
// Create the widget, setting the Main window (this) as its parent.
- QOpenCamWidget *cwcam = new QOpenCamWidget(this);
+ QOpenCamWidget *cwcam = new QOpenCamWidget(this, new QSize(320, 240), new QSize(960,720));
// bool QOpenCamWidget::grabCapture(int source) tries to get a
// video capture handle from OpenCV, using the source number
// as the device to open. Here I use -1 as the number, meaning