Page 1 of 3 123 LastLast
Results 1 to 20 of 48

Thread: OpenCV integration

  1. #1
    Join Date
    Feb 2008
    Location
    Honolulu, HI
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool OpenCV integration

    Hi Forum,

    I've been looking around on the net for this, but haven't found a satisfying solution yet. I capturing frames using my S-Video input under Linux. This works already and it works well using the OpenCV Highgui interface, their drawing functions, etc.

    I would now like to integrate what I have done so far with Qt, because of various reasons: the program gets bigger and bigger, I need network support, and would like to add a more sophisticated GUI to, for example, interactively adjust threshold values, or save video files for offline use (preferably using ffmpeg).

    I would have to add that I am new to Qt, but not to OpenCV or C++ programming. I have downloaded and compiled the latest version of Qt at the time of this writing (4.3.3) and successfully compiled some sample programs.

    Now here are my questions:

    1. is there someone out there working with both OpenCV and Qt 4.x already?
    2. How can I display the captured frames in a Qt application?
    3. Are there any recommendations as to which drawing functions should be used (e.g. which are faster?)


    Thank you guys in advance for any help or pointers.

    Cheers,
    Stephan

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: OpenCV integration

    Quote Originally Posted by sfabel View Post
    2. How can I display the captured frames in a Qt application?
    3. Are there any recommendations as to which drawing functions should be used (e.g. which are faster?)
    Ok, these two I am able to answer. Basically you have two choices - either using or not using OpenGL. The first approach requires you to use QGLWidget and to display images by binding them as textures (using bindTexture()) and using those textures on a rectangle (preferably square one) which you display in the GL widget. With the other approach you will be displaying images on a QLabel object using QLabel::setPixmap(). The GL approach will be much faster but requires more coding.

    Oh... one more thing, just to make my post complete. Since Qt 4.4 you will be able to use Phonon which is the KDE4 multimedia framework adopted for Qt that will use a platform dependent backend - GStreamer in case of Linux/Unix (or xine when using KDE4 and the GPLed version of Qt), MediaPlayer in case of Windows (I think), etc.
    Last edited by wysota; 2nd February 2008 at 01:09. Reason: updated contents

  3. The following 2 users say thank you to wysota for this useful post:

    134ms (24th March 2010), Xin Chen (25th August 2011)

  4. #3
    Join Date
    Feb 2008
    Location
    Honolulu, HI
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Smile Re: OpenCV integration

    Hi,

    thanks for your answers. I tried the Pixmap method and got it to work. If you want, you could look it over and suggest a better way but for now this works for me. I was able to develop a simple test program which would display the captured image from a video source such as a camera and the user can choose from several modes of operation: Normal feedthrough of video, the same with a sobel operator applied (in X and Y direction) and with a Hough transform.

    To convert the IplImage* to a QImage (and then to a QPixmap to be displayed in a QLabel), I did (roughly) this:

    Qt Code:
    1. // the individual channels for the IplImage
    2. tchannel0 = cvCreateImage(frame_size, IPL_DEPTH_8U, 1);
    3. tchannel1 = cvCreateImage(frame_size, IPL_DEPTH_8U, 1);
    4. tchannel2 = cvCreateImage(frame_size, IPL_DEPTH_8U, 1);
    5. tchannel3 = cvCreateImage(frame_size, IPL_DEPTH_8U, 1);
    6.  
    7. // set all elements in tchannel0 (alpha channel) to 255
    8. cvSet(tchannel0,cvScalarAll(255),0);
    9.  
    10. // with cframe being the captured frame (3 channel RGB)
    11. // and dframe the frame to be displayed
    12. cvSplit(cframe, tchannel1, tchannel2, tchannel3, NULL);
    13. cvMerge(tchannel1, tchannel2, tchannel3, tchannel0, dframe);
    14.  
    15. // point to the image data stored in the IplImage*
    16. const unsigned char * data = (unsigned char *)(dframe->imageData);
    17.  
    18. // read other parameters in local variables
    19. int width = ocv_image->width;
    20. int height = ocv_image->height;
    21. int bytesPerLine = ocv_image->widthStep;
    22.  
    23. // imageframe is my QLabel object
    24. qimage = QImage( data, width, height, bytesPerLine, QImage::Format_RGB32 );
    25. ui.imageframe->setPixmap(pixmap->fromImage(qimage, 0));
    To copy to clipboard, switch view to plain text mode 

    This is just the general outline, of course and distributed throughout my code. Basically the problem is that OpenCV per se does not support an alpha channel, however it seems that Qt needs one. So I created a "fake" alpha channel and inserted it into a IplImage with 4 instead of 3 layers.

    BTW: I think I found a bug in the documentation. In the format description, the QImage::Format_RGB32 is described as 0xffRRGGBB. However, it is 0xRRGGBBff. Or am I mistaken? But the above works!

    Hope that this is of use for some other people out there.

    Cheers,
    Stephan

  5. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenCV integration

    Quote Originally Posted by sfabel View Post
    BTW: I think I found a bug in the documentation. In the format description, the QImage::Format_RGB32 is described as 0xffRRGGBB. However, it is 0xRRGGBBff. Or am I mistaken? But the above works!
    I expect it depends on the endianness of your system...
    Current Qt projects : QCodeEdit, RotiDeCode

  6. #5
    Join Date
    Feb 2008
    Location
    Honolulu, HI
    Posts
    21
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Wink Re: OpenCV integration

    If it depended on the endianess of my system, it would be 0xBBGGRRff instead of 0xffRRGGBB, wouldn't it?

    But since only the position of the alpha channel is changed I don't think it has anything to do with it.

    Cheers,
    Stephan

  7. #6
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: OpenCV integration

    Hi Stephan,

    I'm currently putting together a small project for a computer vision grad class I'm taking. Eventually it will be a head tracker, but right now it's just the general capturing framework that I will use. I did some benchmarking on different approaches to copying opencv data to a QImage, and ended up with the code posted here: http://www.qtcentre.org/forum/p-qima...ostcount7.html

    I've also put together a simple framework for capturing and frame processing that you might find useful. I've attached the code for it. Just run qmake and make. Should work for most supported cameras.

    It's multithreaded, so the capture thread spins getting frames as fast as possible and putting them into a buffer. Then the processing thread grabs frames out of that buffer and does whatever processing you want to do on the IplImage. Then the result gets loaded into a structure and passed through a chain of filters, ending with the widget that will contain the Image in the Qt GUI. Right now I do no processing and have no filters written yet, but the framework should work well for most computer vision tasks. I used a similar architecture for our eye tracking system and it works very well.

    The display of the image uses a custom widget that paints it on the paintevent. I couldn't use OGL because my laptop video drivers are crap and it won't run. It should be about as fast as it can go without OGL though. Using Qt::WA_OpaquePaintEvent and Qt::WA_PaintOnScreen gives a nice speedup over the defaults.
    Attached Files Attached Files

  8. The following 12 users say thank you to pherthyl for this useful post:

    134ms (24th March 2010), AlexReche (25th October 2010), droetker (18th May 2012), eumesmo (16th November 2009), jagadeesr (25th December 2010), jmarone (9th February 2011), karatchov (30th July 2010), Louis Koziarz (20th July 2010), Pragmataraxia (16th August 2010), SH1SNO (23rd January 2012), superteny (22nd July 2009), yujen (5th April 2012)

  9. #7
    Join Date
    Nov 2007
    Posts
    53
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: OpenCV integration

    Hi,

    Thanks for your code sample.

    Just a question, is there any particular reason for not using the cvcam library bundled with opencv ? I have made a quick review of the code and I have noticed that you didn't used methods from cvcam.h

    Your feedback on it could be very instructive.

  10. #8
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: OpenCV integration

    I don't really have a good answer for you. I didn't use cvCam just because I haven't used it before, it seems to have less documentation (it's not even mentioned on the OpenCV wiki as far as I can tell), and highgui functions can do similar things.

    However, if you are trying to build a real application that needs robust and full featured camera access, then I would advise against both highgui and cvcam. They are both more or less hacks that give you basic camera access but have all sorts of problems once you start using them for anything serious. For example, although highgui claims to be able to set things like camera resolution, framerate, and colour balance, in reality it doesn't actually work for most cameras.

    If you have a good machine vision camera, use their provided SDK. It will always be miles better than the functions in opencv. Otherwise the way to go is to use the V4L api in Linux and the DirectX SDK in Windows. For example I have an Asus EeePC and the built in camera doesn't work properly with OpenCv at all, while it works fine in linux video apps and Windows video apps that don't use OpenCV.

  11. #9
    Join Date
    Nov 2007
    Posts
    53
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: OpenCV integration

    Thanks for your answer. Requirements for the projects are minimal for the moment so I don't think I need to deal with DirectShow or specific webcam driver.

    For the eeePC, perhaps you should try with cvcam. I have tested succesfully with my logitech cam but this evening, I'm searching more informations on the benefits of cvcam against highgui and I've read this on a french forum :

    else I know I was using capturefromcam (highgui.h) before with a logitech webcam and it was working like a charm, but when I switched to a wireless webcam and a video acquisition card, capturefromcam didn't worked anymore so I've used cvcam with the callback function and it work perfectly, so I think it support all webcams as long as drivers are installed
    Perhaps it is worth a try ? Let me know if you get it working with eeePC both on Windows and Linux.

    Here is a quick code sample :

    Qt Code:
    1. #include <QtGui>
    2. #include "mywidget.h"
    3. #include "cvcam.h"
    4. #include "cxcore.h"
    5. #include "cxtypes.h"
    6.  
    7. void callback(IplImage* frame);
    8.  
    9. MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
    10. {
    11. int ncams = cvcamGetCamerasCount();
    12. cvcamSetProperty(0, CVCAM_PROP_ENABLE, CVCAMTRUE);
    13. cvcamSetProperty(0, CVCAM_PROP_RENDER, CVCAMTRUE);
    14.  
    15. cvcamWindow myWin = (cvcamWindow) winId();
    16. cvcamSetProperty(0, CVCAM_PROP_WINDOW, &myWin);
    17.  
    18. int width = 640;
    19. int height = 480;
    20. cvcamSetProperty(0, CVCAM_RNDWIDTH, &width);
    21. cvcamSetProperty(0, CVCAM_RNDHEIGHT, &height);
    22.  
    23. cvcamSetProperty(0, CVCAM_PROP_CALLBACK, callback);
    24.  
    25. cvcamInit();
    26. cvcamStart();
    27. }
    28.  
    29.  
    30.  
    31. void callback(IplImage* frame)
    32. {
    33. // Do what you want with IplImage
    34. }
    To copy to clipboard, switch view to plain text mode 

    I haven't bundled the termination code but you will found it in the RTF doc bundled with OpenCV. As there is some mistakes in the first code sample from the doc, I think the above code should help you (even if the remaining of the RTF is useful to understand and perhaps a litte more accurate ;o))

  12. #10
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: OpenCV integration

    I put this QImage IplImageToQImage here on this thread if people like to search...
    I tested on QT4.4 and run ok....

    from QPainter p(&gd); forward is only a date print...
    I write & copy this piece to a label :
    Animated Portable Network Graphics APNG , which run on Firefox 3 or opera...
    http://www.qt-apps.org/content/show....?content=82221


    Qt Code:
    1. #ifdef OPCAMENABLE
    2.  
    3. #include "cv.h"
    4. #include "highgui.h"
    5. #include <stdio.h>
    6. #include <ctype.h>
    7.  
    8. static QImage IplImageToQImage(const IplImage *iplImage, uchar **data , bool mirroRimage = true )
    9. {
    10. uchar *qImageBuffer = NULL;
    11. int width = iplImage->width;
    12.  
    13. /*
    14.   * Note here that OpenCV image is stored so that each lined is 32-bits aligned thus
    15.   * explaining the necessity to "skip" the few last bytes of each line of OpenCV image buffer.
    16.   */
    17. int widthStep = iplImage->widthStep;
    18. int height = iplImage->height;
    19.  
    20. switch (iplImage->depth)
    21. {
    22. case IPL_DEPTH_8U:
    23. if (iplImage->nChannels == 1)
    24. {
    25. /* OpenCV image is stored with one byte grey pixel. We convert it to an 8 bit depth QImage. */
    26. qImageBuffer = (uchar *)malloc(width * height * sizeof(uchar));
    27. uchar *QImagePtr = qImageBuffer;
    28. const uchar *iplImagePtr = (const uchar *)iplImage->imageData;
    29. for (int y = 0; y < height; ++y)
    30. {
    31. // Copy line by line
    32. memcpy(QImagePtr, iplImagePtr, width);
    33. QImagePtr += width;
    34. iplImagePtr += widthStep;
    35. }
    36. }
    37. else if (iplImage->nChannels == 3)
    38. {
    39. /* OpenCV image is stored with 3 byte color pixels (3 channels). We convert it to a 32 bit depth QImage. */
    40. qImageBuffer = (uchar *)malloc(width * height * 4 * sizeof(uchar));
    41. uchar *QImagePtr = qImageBuffer;
    42. const uchar *iplImagePtr = (const uchar *)iplImage->imageData;
    43.  
    44. for (int y = 0; y < height; ++y)
    45. {
    46. for (int x = 0; x < width; ++x)
    47. {
    48. // We cannot help but copy manually.
    49. QImagePtr[0] = iplImagePtr[0];
    50. QImagePtr[1] = iplImagePtr[1];
    51. QImagePtr[2] = iplImagePtr[2];
    52. QImagePtr[3] = 0;
    53.  
    54. QImagePtr += 4;
    55. iplImagePtr += 3;
    56. }
    57. iplImagePtr += widthStep - 3 * width;
    58. }
    59. }
    60. else
    61. qDebug("IplImageToQImage: image format is not supported : depth=8U and %d channels\n", iplImage->nChannels);
    62.  
    63. break;
    64.  
    65. case IPL_DEPTH_16U:
    66. if (iplImage->nChannels == 1)
    67. {
    68. /* OpenCV image is stored with 2 bytes grey pixel. We convert it to an 8 bit depth QImage. */
    69. qImageBuffer = (uchar *)malloc(width * height * sizeof(uchar));
    70. uchar *QImagePtr = qImageBuffer;
    71. const uint16_t *iplImagePtr = (const uint16_t *)iplImage->imageData;
    72.  
    73. for (int y = 0; y < height; ++y)
    74. {
    75. for (int x = 0; x < width; ++x)
    76. *QImagePtr++ = ((*iplImagePtr++) >> 8); // We take only the highest part of the 16 bit value. It is similar to dividing by 256.
    77. iplImagePtr += widthStep / sizeof(uint16_t) - width;
    78. }
    79. }
    80. else
    81. qDebug("IplImageToQImage: image format is not supported : depth=16U and %d channels\n", iplImage->nChannels);
    82.  
    83. break;
    84.  
    85. case IPL_DEPTH_32F:
    86. if (iplImage->nChannels == 1)
    87. {
    88. /* OpenCV image is stored with float (4 bytes) grey pixel. We convert it to an 8 bit depth QImage. */
    89. qImageBuffer = (uchar *)malloc(width * height * sizeof(uchar));
    90. uchar *QImagePtr = qImageBuffer;
    91. const float *iplImagePtr = (const float *)iplImage->imageData;
    92.  
    93. for (int y = 0; y < height; ++y)
    94. {
    95. for (int x = 0; x < width; ++x)
    96. *QImagePtr++ = (uchar)(255 * ((*iplImagePtr++)));
    97. iplImagePtr += widthStep / sizeof(float) - width;
    98. }
    99. }
    100. else
    101. qDebug("IplImageToQImage: image format is not supported : depth=32F and %d channels\n", iplImage->nChannels);
    102.  
    103. break;
    104.  
    105. case IPL_DEPTH_64F:
    106. if (iplImage->nChannels == 1)
    107. {
    108. /* OpenCV image is stored with double (8 bytes) grey pixel. We convert it to an 8 bit depth QImage. */
    109. qImageBuffer = (uchar *) malloc(width * height * sizeof(uchar));
    110. uchar *QImagePtr = qImageBuffer;
    111. const double *iplImagePtr = (const double *) iplImage->imageData;
    112.  
    113. for (int y = 0; y < height; ++y)
    114. {
    115. for (int x = 0; x < width; ++x)
    116. *QImagePtr++ = (uchar)(255 * ((*iplImagePtr++)));
    117. iplImagePtr += widthStep / sizeof(double) - width;
    118. }
    119. }
    120. else
    121. qDebug("IplImageToQImage: image format is not supported : depth=64F and %d channels\n", iplImage->nChannels);
    122.  
    123. break;
    124.  
    125. default:
    126. qDebug("IplImageToQImage: image format is not supported : depth=%d and %d channels\n", iplImage->depth, iplImage->nChannels);
    127. }
    128.  
    129. QImage *qImage;
    130. if (iplImage->nChannels == 1)
    131. {
    132. QVector<QRgb> colorTable;
    133. for (int i = 0; i < 256; i++)
    134. colorTable.push_back(qRgb(i, i, i));
    135.  
    136. qImage = new QImage(qImageBuffer, width, height, QImage::Format_Indexed8);
    137. qImage->setColorTable(colorTable);
    138. }
    139. else
    140. qImage = new QImage(qImageBuffer, width, height, QImage::Format_RGB32);
    141. QImage gd0 = qImage->mirrored(false,mirroRimage);
    142. *data = qImageBuffer;
    143. QColor textColor = Qt::black;
    144. QColor fillrectcolor = Qt::red;
    145. QColor shapepicture = Qt::white;
    146. QImage gd = gd0.scaledToWidth(350);
    147. QDateTime now = QDateTime::currentDateTime ();
    148. QString selectionText = now.toString("dd.MM.yyyy hh:mm:ss");
    149. QPainter p(&gd);
    150. p.setRenderHint(QPainter::Antialiasing, true);
    151.  
    152. QFontMetrics fm( qApp->font() );
    153. int stringWidth = fm.width(selectionText);
    154. int stringHeight = fm.ascent();
    155. const int sx = gd.width() - stringWidth - 5;
    156. QPen pen;
    157. pen.setStyle( Qt::SolidLine );
    158. pen.setWidth( 2 );
    159. pen.setColor( textColor );
    160. p.setPen( pen);
    161. p.drawText(QPointF(sx - 1 ,gd.height() - 2 - stringHeight - 1),selectionText);
    162. pen.setColor( fillrectcolor );
    163. p.setPen( pen);
    164. p.drawText(QPointF(sx,gd.height() - 2 - stringHeight),selectionText);
    165.  
    166. return gd;
    167. }
    168.  
    169.  
    170.  
    171. #endif
    To copy to clipboard, switch view to plain text mode 

  13. The following 2 users say thank you to patrik08 for this useful post:

    carllooper (18th August 2009), droetker (18th May 2012)

  14. #11
    Join Date
    Mar 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: OpenCV integration

    Hello Forum,

    I'm new to both QT and OpenCV. I've written couple of program in OpenCV and works well and done the same with QT so botht the tools are working well.

    I'm trying to integrate the code posted by "pherthyl" to stream the video data caputured by the webcam in opencv. The application is really well written (for me as I can understand it). When i try and build it says that cannot find "opencv/highgui.h"

    I've installed opencv in /opt/opencv and all the files are viz. highgui.h, cxcore.h, cv.h are located in /opt/opencv/include/opencv.

    I tried and compile the project by changing the path of highgui.h in capturethread.h from opencv/highgui.h to opt/opencv/include/opencv/highgui.h but still it gives the same error that it couldn't locate the files.

    Is there any specific changes that I need to make in the MAKEFILE which will specify the location of these files and link it.

    Thanks in advance.

    Regards,
    Mitesh

  15. #12
    Join Date
    Jul 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: OpenCV integration

    Quote Originally Posted by pherthyl View Post
    Hi Stephan,

    I'm currently putting together a small project for a computer vision grad class I'm taking. Eventually it will be a head tracker, but right now it's just the general capturing framework that I will use. I did some benchmarking on different approaches to copying opencv data to a QImage, and ended up with the code posted here: http://www.qtcentre.org/forum/p-qima...ostcount7.html

    I've also put together a simple framework for capturing and frame processing that you might find useful. I've attached the code for it. Just run qmake and make. Should work for most supported cameras.

    It's multithreaded, so the capture thread spins getting frames as fast as possible and putting them into a buffer. Then the processing thread grabs frames out of that buffer and does whatever processing you want to do on the IplImage. Then the result gets loaded into a structure and passed through a chain of filters, ending with the widget that will contain the Image in the Qt GUI. Right now I do no processing and have no filters written yet, but the framework should work well for most computer vision tasks. I used a similar architecture for our eye tracking system and it works very well.

    The display of the image uses a custom widget that paints it on the paintevent. I couldn't use OGL because my laptop video drivers are crap and it won't run. It should be about as fast as it can go without OGL though. Using Qt::WA_OpaquePaintEvent and Qt::WA_PaintOnScreen gives a nice speedup over the defaults.

    Thanks for code!
    I'm running example and capture frame size isn't changing, it seems to me that cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640); does nothing. Or have I missed something?

    if(size == Size640) {
    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);
    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);
    qDebug() << "Setting 640x480:CV_CAP_PROP_FRAME_WIDTH:" << cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
    qDebug() << "Setting 640x480CV_CAP_PROP_FRAME_HEIGHT:" << cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);

    }

    returns:
    Setting 640x480:CV_CAP_PROP_FRAME_WIDTH: 320
    Setting 640x480CV_CAP_PROP_FRAME_HEIGHT: 240

    Any ideas how could I change frame width/height?
    Best regards,
    Milan

  16. #13
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: OpenCV integration

    Quote Originally Posted by kosirm View Post
    Thanks for code!
    I'm running example and capture frame size isn't changing, it seems to me that cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640); does nothing. Or have I missed something?

    if(size == Size640) {
    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);
    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);
    qDebug() << "Setting 640x480:CV_CAP_PROP_FRAME_WIDTH:" << cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
    qDebug() << "Setting 640x480CV_CAP_PROP_FRAME_HEIGHT:" << cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);

    }

    returns:
    Setting 640x480:CV_CAP_PROP_FRAME_WIDTH: 320
    Setting 640x480CV_CAP_PROP_FRAME_HEIGHT: 240

    Any ideas how could I change frame width/height?
    Best regards,
    Milan
    No. This is what I was talking about when I said the highgui functions suck

    On some cameras those functions will work, but on most they won't. If you want to control camera properties like capture size and others you'll have to use another image acquisition library or try cvcam as someone else suggested. I never had much luck with it. It'll do basic capture, but that's it.

  17. #14
    Join Date
    Jul 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: OpenCV integration

    thanks...

    best regards, Milan
    Last edited by kosirm; 11th July 2009 at 14:42.

  18. #15
    Join Date
    Jul 2009
    Posts
    6
    Thanks
    2
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: OpenCV integration

    Sorry to re-awaken an old topic but i am having some difficulties converting an opencv Monochrome image into a Qimage. The image is a result of calling the opencv function
    void cvInRangeS( const CvArr* src, CvScalar lower, CvScalar upper, CvArr* dst );

    When i pass this image to the function IplImageToQImage it does convert the image into qimage however the image is 8 times smaller and duplicated. The results can be seen below

    Opencv Image


    Convertion to Qimage results



    Does anybody know why this has happened? And any ideas how to correct the error?

  19. The following 2 users say thank you to switch for this useful post:

    droetker (18th May 2012)

  20. #16
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: OpenCV integration

    Not sure why you're getting that. Have you tried looking at the dst image before you convert it to a QImage (using the highgui showimg function)? Make sure the dst image is the correct bit depth (8u or 8s).

  21. #17
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    1

    Red face Re: OpenCV integration

    Hello pherthyl,


    Thanks for the framework, it's very good, but I found a problem running in my hardware. I tested the framework in a Hp notebook, with the webcam and with a external camera and worked fine. When a tried the framework in another notebook (a LG note) with the integrate webcam, a get an deadlock every time I stop and try a play again.

    The console output: (this problem in this notebook occurs every time, it's not a random problem...)


    Listing capture properties...
    CV_CAP_PROP_FRAME_WIDTH
    CV_CAP_PROP_FRAME_HEIGHT
    CV_CAP_PROP__FPS 0
    CV_CAP_PROP_FOURCC 0
    CV_CAP_PROP_BRIGHTNESS 0
    CV_CAP_PROP_CONTRAST 0
    CV_CAP_PROP_SATURATION 0
    CV_CAP_PROP_HUE 0
    Done
    Setting 640x480 1
    Attempting to set frame rate...
    Error: 0
    Starting to track
    About to start the capture thread
    Started the capture thread
    Stop capture requested.
    Waiting on capture start...
    Listing capture properties...
    CV_CAP_PROP_FRAME_WIDTH
    CV_CAP_PROP_FRAME_HEIGHT
    CV_CAP_PROP__FPS 0
    CV_CAP_PROP_FOURCC 0
    CV_CAP_PROP_BRIGHTNESS 0
    CV_CAP_PROP_CONTRAST 0
    CV_CAP_PROP_SATURATION 0
    CV_CAP_PROP_HUE 0
    Done
    Setting 640x480 1
    Attempting to set frame rate...
    Error: 0
    Starting to track
    About to start the capture thread
    Started the capture thread
    QMutex::lock Deadlock detected in thread 3916



    Well, another test that I did, it's to start a HeadTracker object when a button is pressed in the main window. Well, it works fine until I request a re-size. After a re-size the program crashes and close.


    It's just a report, but any help it's very welcome, I will have a better lock in the code to see if I can improve anything, because I think is a very good framework and really fast as well

    cheers!

  22. #18

    Default Re: OpenCV integration

    I know this thread is quite old, but still it is a very good wrapper to get images from webcam or whatnot.

    If for some reason you dont need some fancy 32 bit format you could change the updatePixmap function to only use one memcpy like this:

    Qt Code:
    1. t.start();
    2. //qDebug() << "Copying data";
    3. bool start = false;
    4. // check if the frame dimensions have changed
    5. if(frame->width != imageWidth || frame->height != imageHeight) {
    6. if(imageData) {
    7. delete[] imageData;
    8. }
    9. start = true;
    10. imageWidth = frame->width;
    11. imageHeight = frame->height;
    12. emit(frameSizeChanged(imageWidth, imageHeight));
    13. imageData = new unsigned char[3*imageWidth*imageHeight];
    14. }
    15.  
    16. int pixels = imageWidth * imageHeight;
    17. uchar* src = (uchar*)(frame->imageData);
    18.  
    19. memcpy(imageData, src, pixels*3);
    20. if(!start) {
    21. ++frames;
    22. time += t.elapsed();
    23. }
    To copy to clipboard, switch view to plain text mode 

    Then you have to change the paintEvent method to create the tImg with RGB888 format like this:
    Qt Code:
    1. QImage tImg(imageData, imageWidth, imageHeight, QImage::Format_RGB888);
    To copy to clipboard, switch view to plain text mode 

    You might run into problem of RGB <--> BGR conversion, just modify the painter.drawImage call to
    Qt Code:
    1. painter.drawImage(QPoint(0,0), tImg.rgbSwapped());
    To copy to clipboard, switch view to plain text mode 
    Last edited by mounte; 15th December 2009 at 11:40.

  23. #19
    Join Date
    Apr 2010
    Posts
    7
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: OpenCV integration

    Seems the archive is corrupted.Could you please send me this ? my email is

    umanga dot pdn at gmail dot com

    thanks

  24. #20
    Join Date
    Aug 2009
    Posts
    1
    Thanked 3 Times in 1 Post

    Exclamation Re: OpenCV integration

    I thought the archive was corrupted too - but its actually double-gzipped, then tarred. So to open the archive, I had to gunzip qtopencv.tar.gz, then "cat qtopencv.tar | gunzip > qtopencv2.tar", then I could do "tar xvf qtopencv.tar" to extract the files. To save everyone that work, I posted a zipped version of the archive at: http://www.jdbryanphotography.com/do...s/qtopencv.zip. Cheers!

  25. The following 3 users say thank you to josiahbryan for this useful post:

    gmiller39 (13th July 2010), karatchov (30th July 2010), pavanbarot (13th April 2011)

Similar Threads

  1. Replies: 8
    Last Post: 18th March 2011, 12:27
  2. Replies: 7
    Last Post: 22nd December 2010, 09:13
  3. Qt4 integration with VS2008 Express how-to interest?
    By thomaspu in forum Qt Programming
    Replies: 11
    Last Post: 21st May 2008, 13:53
  4. How to open two cameras with opencv?
    By alphaboy in forum General Programming
    Replies: 2
    Last Post: 21st December 2007, 11:58
  5. VS Integration plugins not visible
    By kemp in forum Qt Tools
    Replies: 1
    Last Post: 11th August 2006, 23:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.