From 7ff7502c4d41c597c8475566495fc39d8524c57c Mon Sep 17 00:00:00 2001 From: 020535 <020535@07accd87-1e0b-0410-939d-c05d8a058e03> Date: Sat, 17 Oct 2009 13:12:44 +0000 Subject: [PATCH] Sizes are now code-settable using c'tor parameters. Default values allow for code backwards-compat. View and output need not be the same size. git-svn-id: https://dilbert.hig.no/svn/student/020535/qopencamwidget/trunk@189 07accd87-1e0b-0410-939d-c05d8a058e03 --- Doxyfile | 2 +- qopencamwidget.cpp | 39 +++++++++++++++++++++++++++++++-------- qopencamwidget.h | 4 +++- view.cpp | 2 +- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Doxyfile b/Doxyfile index 9776e46..1762853 100644 --- a/Doxyfile +++ b/Doxyfile @@ -160,7 +160,7 @@ FILTER_SOURCE_FILES = NO # configuration options related to source browsing #--------------------------------------------------------------------------- SOURCE_BROWSER = YES -INLINE_SOURCES = YES +INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES REFERENCED_BY_RELATION = YES REFERENCES_RELATION = YES diff --git a/qopencamwidget.cpp b/qopencamwidget.cpp index eb5e676..9b91461 100644 --- a/qopencamwidget.cpp +++ b/qopencamwidget.cpp @@ -63,10 +63,22 @@ * * \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 @@ -74,6 +86,20 @@ QOpenCamWidget::QOpenCamWidget(QWidget *parent) // 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) @@ -109,7 +135,8 @@ QOpenCamWidget::paintEvent ( QPaintEvent * event ) // 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 { @@ -142,15 +169,11 @@ QOpenCamWidget::grabCapture(int source) 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; } diff --git a/qopencamwidget.h b/qopencamwidget.h index 560d78b..13602f4 100644 --- a/qopencamwidget.h +++ b/qopencamwidget.h @@ -35,10 +35,12 @@ class QOpenCamWidget CvCapture *capture; QTimer *frametimer; QImage *nextFrame; + QSize *vSize; + QSize *res; public: // Defaults, standard elements ;) - QOpenCamWidget(QWidget *parent = 0); + QOpenCamWidget(QWidget *parent = 0, QSize *viewSize = NULL, QSize *resolution = NULL); ~QOpenCamWidget(void); // Overides, reimplementation of abstract diff --git a/view.cpp b/view.cpp index bd0808a..0c81c3c 100644 --- a/view.cpp +++ b/view.cpp @@ -41,7 +41,7 @@ View::View( QWidget *parent) 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 -- 2.39.2