Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 48

Thread: OpenCV integration

  1. #21
    Join Date
    Aug 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenCV integration

    Can we do like this? Mine is very simple. It works ( I think ) can you guys help check this?

    Qt Code:
    1. IplImage * img = cvLoadImage( "C:\\Users\\Pictures\\dodo19.jpg");
    2. cvCvtColor(img,img,CV_BGR2RGB);
    3. m_i = QImage((unsigned char *)img->imageDataOrigin,img->width,img->height,QImage::Format_RGB888);
    4. imageLabel->setPixmap(QPixmap::fromImage(m_i,0));
    To copy to clipboard, switch view to plain text mode 

    The picture looks good in the Qt Dialog. Please check if doing like this does really work fine.

  2. #22
    Join Date
    Sep 2010
    Posts
    17
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: OpenCV integration

    If it can help here is a code-snippet for a custom Qt plug-in using OpenCV. I use "neutral" unsigned char* between Qt and OpenCV. On return unsigned char* converted to QImage is displayed in a custom Widget. This PlugIn is used reall-time on video stream ( on PC.. sorry).

    Qt Code:
    1. // code
    2. #include <QtGui>
    3. #include <math.h>
    4. #include <stdlib.h>
    5. #include "OpenCVwarpFilter.h"
    6. //
    7. #include "cv.h"
    8. #include "cxcore.h"
    9.  
    10. #pragma message("automatic link to OpenCV libs")
    11. #pragma comment(lib,"cv210.lib")
    12. #pragma comment(lib,"cxcore210.lib")
    13.  
    14. struct OpenCVStruct
    15. {
    16. int iWidth;
    17. int iHeight;
    18. IplImage *m_pImg; // OpenCV Images
    19. IplImage *m_pOutputImg;
    20. CvMat *m_pMapMatrix; // OpenCV Matrix
    21. CvPoint2D32f src_quad[4];
    22. CvPoint2D32f dst_quad[4];
    23. };
    24.  
    25. QString OpenCVwarpFilterPlugin::filterName() const
    26. {
    27. return "piWarp_OpenCV";
    28. }
    29.  
    30.  
    31. unsigned long OpenCVwarpFilterPlugin::filterParamsSize() const
    32. {
    33. return sizeof(OpenCVStruct);
    34. }
    35.  
    36. void OpenCVwarpFilterPlugin::filterInit(void* piParams)
    37. {
    38. OpenCVStruct* pOpenCV = (OpenCVStruct*)piParams;
    39. pOpenCV->m_pImg = NULL;
    40. pOpenCV->m_pOutputImg = NULL;
    41. pOpenCV->m_pMapMatrix = NULL;
    42. pOpenCV->iWidth = 0;
    43. pOpenCV->iHeight = 0;
    44. }
    45.  
    46. void OpenCVwarpFilterPlugin::filterClose(void* piParams)
    47. {
    48. OpenCVStruct* pOpenCV = (OpenCVStruct*)piParams;
    49. if (pOpenCV->m_pImg != NULL)
    50. {
    51. cvReleaseImage(&pOpenCV->m_pImg);
    52. cvReleaseImage(&pOpenCV->m_pOutputImg);
    53. cvReleaseMat(&pOpenCV->m_pMapMatrix);
    54. }
    55. }
    56.  
    57. void OpenCVwarpFilterPlugin::setOperation(unsigned char *destintation,unsigned char *source,
    58. long width,long height,long dest_pitch,long src_pitch,long Bpp,void* piParams)
    59. {
    60. OpenCVStruct* pOpenCV = (OpenCVStruct*)piParams;
    61. if (! pOpenCV)
    62. return;
    63.  
    64.  
    65.  
    66. if ((pOpenCV->m_pImg == NULL) || (pOpenCV->iWidth != width) || (pOpenCV->iHeight != height))
    67. {
    68. if (pOpenCV->m_pImg != NULL)
    69. {
    70. cvReleaseImage(&pOpenCV->m_pImg);
    71. cvReleaseImage(&pOpenCV->m_pOutputImg);
    72. cvReleaseMat(&pOpenCV->m_pMapMatrix);
    73. }
    74. pOpenCV->m_pImg = cvCreateImage(cvSize(width,height), IPL_DEPTH_8U, 3);
    75. pOpenCV->m_pOutputImg = cvCreateImage(cvGetSize(pOpenCV->m_pImg), 8, 3 );
    76.  
    77. pOpenCV->src_quad[0].x = 150; pOpenCV->src_quad[0].y = 150;
    78. pOpenCV->src_quad[1].x = 0; pOpenCV->src_quad[1].y = (float)height;
    79. pOpenCV->src_quad[2].x = (float)width; pOpenCV->src_quad[2].y = 0;
    80. pOpenCV->src_quad[3].x = (float)width; pOpenCV->src_quad[3].y = (float)height;
    81.  
    82. pOpenCV->dst_quad[0].x = 0; pOpenCV->dst_quad[0].y = 0;
    83. pOpenCV->dst_quad[1].x = 0; pOpenCV->dst_quad[1].y = (float)height;
    84. pOpenCV->dst_quad[2].x = (float)width; pOpenCV->dst_quad[2].y = 0;
    85. pOpenCV->dst_quad[3].x = (float)width; pOpenCV->dst_quad[3].y = (float)height;
    86.  
    87. pOpenCV->m_pMapMatrix = cvCreateMat(3,3,CV_32FC1);
    88. }
    89. pOpenCV->iWidth = width;
    90. pOpenCV->iHeight = height;
    91.  
    92. cvWarpPerspectiveQMatrix(pOpenCV->src_quad, pOpenCV->dst_quad, pOpenCV->m_pMapMatrix);
    93.  
    94. memcpy(pOpenCV->m_pImg->imageData,source,pOpenCV->m_pImg->imageSize);
    95. cvWarpPerspective(pOpenCV->m_pImg, pOpenCV->m_pOutputImg, pOpenCV->m_pMapMatrix, CV_WARP_FILL_OUTLIERS, cvScalarAll(1));
    96. memcpy(destintation,pOpenCV->m_pOutputImg->imageData,pOpenCV->m_pOutputImg->imageSize);
    97. }
    98.  
    99. Q_EXPORT_PLUGIN2(FilterInterface, OpenCVwarpFilterPlugin)
    100.  
    101. // Header
    102. #ifndef EXTRAFILTERSPLUGIN_H
    103. #define EXTRAFILTERSPLUGIN_H
    104.  
    105. #include <QObject>
    106. #include <QString>
    107. #include "interfaceImageFilter.h"
    108.  
    109. class OpenCVwarpFilterPlugin : public QObject, public FilterInterface
    110. {
    111. Q_OBJECT
    112. Q_INTERFACES(FilterInterface)
    113.  
    114. public:
    115. QString filterName() const;
    116. unsigned long filterParamsSize() const;
    117. void filterInit(void* piParams);
    118. void filterClose(void* piParams);
    119. void setOperation(unsigned char *dest,unsigned char *src,
    120. long width,long height,long dest_pitch,long src_pitch,long Bpp,void* piParams);
    121.  
    122. };
    123.  
    124. #endif
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 22nd September 2010 at 10:47. Reason: missing [code] tags

  3. #23
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: Try to run but getting linker error

    Hallo,
    I have downloaded the zip file and tried to run. First i downloaded the OpenCV2.0.1 and copied the opencv folder in the Project folder (i.e qtopencv/opencv) then i made the vcproj out of it as I am using Visual Studio 2005.
    when I run the project, i get am linker error : cannot open input file cv.lib

    I didn't find any cv.lib in the entire OpenCv2.0.1 that I downloaded.
    I shalle be grateful if u tell me how can I run ur program.

    Can u please tell me whether I can record the video stream that I shall be getting from the Camera. I went through the code and i find the slot startRecording in the headtracker.cpp empty.
    Thanks.
    Roy


    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.

  4. #24
    Join Date
    Jan 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: OpenCV integration

    Maybe this isn't the right forum for asking but I'm interesting in s-video capture with openCV and can't find anything, could you tell me how to do that or where to look for?

  5. #25
    Join Date
    Nov 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: OpenCV integration

    Hi,
    I didn't understand what do u mean by s-video? If u mean caprute video using a wecam with openCV, there r nice examples in the net. Just search with Capturing video with Wecam in OpenCv. U will find good threads.
    Cheers,
    Roy

  6. #26
    Join Date
    Jul 2010
    Location
    Ahmedabad,Gujarat,India
    Posts
    25
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: OpenCV integration

    Hi josiahbryan,

    Thanks For Sharing an Awesome Example. i have little problem with this application can u please help me.
    i got following output:

    640 is false
    320 is true

    Listing capture properties...

    CV_CAP_PROP_FRAME_WIDTH 0
    CV_CAP_PROP_FRAME_HEIGHT 0

    CV_CAP_PROP_FPS 0
    CV_CAP_PROP_FOURCC 4.29497e+09

    CV_CAP_PROP_BRIGHTNESS 0
    CV_CAP_PROP_CONTRAST 0

    CV_CAP_PROP_SATURATION 0
    CV_CAP_PROP_HUE 0

    Done

    Settings 320x240: 0
    Attempting to set frame rate...

    Error: 0
    Starting to track

    About to start the capture thread

    Started the capture thread

    E: Imagebuffer received a null image

    E: Imagebuffer received a null image

    E: Imagebuffer received a null image

    Hi josiahbryan,

    Thanks For Sharing an Awesome Example. i have little problem with this application can u please help me.
    i got following output:

    640 is false
    320 is true

    Listing capture properties...

    CV_CAP_PROP_FRAME_WIDTH 0
    CV_CAP_PROP_FRAME_HEIGHT 0

    CV_CAP_PROP_FPS 0
    CV_CAP_PROP_FOURCC 4.29497e+09

    CV_CAP_PROP_BRIGHTNESS 0
    CV_CAP_PROP_CONTRAST 0

    CV_CAP_PROP_SATURATION 0
    CV_CAP_PROP_HUE 0

    Done

    Settings 320x240: 0
    Attempting to set frame rate...

    Error: 0
    Starting to track

    About to start the capture thread

    Started the capture thread

    E: Imagebuffer received a null image

    E: Imagebuffer received a null image

    E: Imagebuffer received a null image

  7. #27
    Join Date
    Jul 2008
    Posts
    4

    Default Re: OpenCV integration

    Hi:

    I know this thread is a bit old, but I would like to point out a library for computer vision we are developing, which integrates Qt with OpenCV, as well as other third-party libraries such as IPP:

    QVision

  8. #28
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: OpenCV integration

    I'm trying to compile program and Qt Creator after succsesful compile show error after running:
    QtOpenCV: ../QtOpenCV/main.cpp:13: int main(int, char**): Assertion `camera' failed.
    The program has unexpectedly finished.

  9. #29
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: OpenCV integration

    Can anyone help? pls

  10. #30
    Join Date
    Jul 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: OpenCV integration

    And what ,,camera'' is ?

    Please show some code.

    G.
    Last edited by grzesiek; 29th July 2011 at 14:52.

  11. #31
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

  12. #32
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: OpenCV integration

    Do you have working camera ?

  13. #33
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: OpenCV integration

    I have integrated camera in notebook and also try usb A4 webcamera, Both work fine in skype and cheese. Maybe i need write some settings about cameras in some config files?

  14. #34
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: OpenCV integration

    No, if you have 2 working cameras, then opencv should popup a simple selection widget.
    Try with cvCreateCameraCapture(0); or cvCaptureFromCAM(-1 or 0)

  15. #35
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: OpenCV integration

    At peresent moment i have only integrated webcam. I was trying to check program with another webcam(i set cvCreateCameraCapture(1) according to the number of connected webcam - dev/video1), but every time i had the same error:
    Cpp Code:
    1. QtOpenCV: main.cpp:13: int main(int, char**): Assertion `camera' failed.
    To copy to clipboard, switch view to plain text mode 

  16. #36
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: OpenCV integration

    Not 1, cameras are indexed from 0, first camera in the system has index 0.
    ---
    OpenCV comes with examples, try to see if they work for you.

  17. #37
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: OpenCV integration

    I try run program with both variants: with index 0 and with index 1 (integrated camera - 0, usb-camera - 1) - but with both - same error

  18. #38
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: OpenCV integration

    Have you tried the second method (cvCaptureFromCAM) ? What about OpenCV samples ?

  19. #39
    Join Date
    Oct 2010
    Posts
    19
    Qt products
    Qt4

    Default Re: OpenCV integration

    OpenCv samples without assert() method works fine. I tried both methods with different params. I think opencv can't find any camera in system. So maybe i need to edit some config files?

  20. #40
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: OpenCV integration

    I've never need to edit any config files to get OpenCV working, and I don't think there are any. It should work ok if you can use those cameras in other programs (like VirtualDub, Skype etc). Maybe try updating the drivers for those devices.

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.