]> git.defcon.no Git - qopencamwidget/commitdiff
Sizes are now code-settable using c'tor parameters. Default values allow for code...
author020535 <020535@07accd87-1e0b-0410-939d-c05d8a058e03>
Sat, 17 Oct 2009 13:12:44 +0000 (13:12 +0000)
committer020535 <020535@07accd87-1e0b-0410-939d-c05d8a058e03>
Sat, 17 Oct 2009 13:12:44 +0000 (13:12 +0000)
git-svn-id: https://dilbert.hig.no/svn/student/020535/qopencamwidget/trunk@189 07accd87-1e0b-0410-939d-c05d8a058e03

Doxyfile
qopencamwidget.cpp
qopencamwidget.h
view.cpp

index 9776e462d36e3ba762a97bf215bad26c53a5d804..17628537f156267c261619d27e955d1ce78ef743 100644 (file)
--- 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
index eb5e6768d333c06a208725bb8d815c693cbd088c..9b9146165ac9d230619a9332de1b5ef7b0bba4c3 100644 (file)
  *
  * \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;
 }
index 560d78b701d3f68d31285ae746eb671842e8fc41..13602f41992d27961fc980f41ddbe3d753d8e265 100644 (file)
@@ -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
index bd0808a06a42553a5130e9dc04f3dd85075b130f..0c81c3c45813869973df3e71bd2a2f79c00da528 100644 (file)
--- 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