×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    83

    Use Gstreamer + Opencv

    Hi all,

    Following the thread by Klen about AR application, I would like to ask how to get and show the image from Gstreamer pipeline with Opencv function .

    while in the example app, the image is shown on the screen by this function (am i right?)

    Code:
    if(CameraN900::buffer!=NULL) {
        unsigned char* data=(unsigned char *) GST_BUFFER_DATA (CameraN900::buffer);
        // 2 pixels width, 2 pixels height, 6 bytes per line, RGB888 format
        QImage img(data, GLWidget::buffer_width, GLWidget::buffer_height,3*GLWidget::buffer_width, QImage::Format_RGB888); 			
        painter->drawImage(0, 0, img.scaled(800,480));
    }
    However, if I want to do the image processing, i should get the image as IplImage* first, which seems impossible without saving the QImage to the device and then read it with cvLoadImage().
    Is there any other method to do so?

    Thx
    Last edited by divanov; 2010-06-16 at 10:10. Reason: fixing CODE tag

  2. #2
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    83

    Re: Use Gstreamer + Opencv

    Sorry, but where are the two replies of this post? I just saw them a moment ago and found they are lost!

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    36

    Re: Use Gstreamer + Opencv

    http://discussion.forum.nokia.com/fo...install-libcv4

    Btw: I didn't mean to hijack your thread, just researched an answer for you and found out that gst-opencv was recommended for this purpose. Just for the record: The other way would be to use OpenCV directly AFAIK.

  4. #4
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: Use Gstreamer + Opencv

    My hints is convert data to iplImage then process it with OpenCV and in the end convert the IplImage to QImage:

    eg:
    Code:
           // This code is valid for images with depth = 8 and channels = 3
           qImageBuffer = (uchar *)malloc(width * height * 4 * sizeof(uchar));
            uchar *qImagePtr = qImageBuffer;
            const uchar *iplImagePtr = (const uchar *)iplImage->imageData;
    
            for (int y = 0; y < height; ++y)
            {
              for (int x = 0; x < width; ++x)
              {
                // We cannot help but copy manually.
                qImagePtr[0] = iplImagePtr[0];
                qImagePtr[1] = iplImagePtr[1];
                qImagePtr[2] = iplImagePtr[2];
                qImagePtr[3] = 255;
    
                qImagePtr += 4;
                iplImagePtr += 3;
              }
              iplImagePtr += widthStep - 3 * width;
            }
    qImage = new QImage(qImageBuffer, width, height, QImage::Format_ARGB32);
    Last edited by gnuton; 2010-06-16 at 09:49.

  5. #5
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    83

    Re: Use Gstreamer + Opencv

    Quote Originally Posted by Dorfmeister View Post
    Just for the record: The other way would be to use OpenCV directly AFAIK.
    IC, Thx. While I have done with OpenCV directly for a long while. I have to say that the performance of highgui is a little bit poor, which lead me to think about using gstreamer+opencv might be a good solution.

  6. #6
    Super Contributor
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Use Gstreamer + Opencv

    Quote Originally Posted by gnuton View Post
    My hints is convert data to iplImage then process it with OpenCV and in the end convert the IplImage to QImage:

    eg:
    Code:
           // This code is valid for images with depth = 8 and channels = 3
           qImageBuffer = (uchar *)malloc(width * height * 4 * sizeof(uchar));
            uchar *qImagePtr = qImageBuffer;
            const uchar *iplImagePtr = (const uchar *)iplImage->imageData;
    
            for (int y = 0; y < height; ++y)
            {
              for (int x = 0; x < width; ++x)
              {
                // We cannot help but copy manually.
                qImagePtr[0] = iplImagePtr[0];
                qImagePtr[1] = iplImagePtr[1];
                qImagePtr[2] = iplImagePtr[2];
                qImagePtr[3] = 255;
    
                qImagePtr += 4;
                iplImagePtr += 3;
              }
              iplImagePtr += widthStep - 3 * width;
            }
    qImage = new QImage(qImageBuffer, width, height, QImage::Format_ARGB32);
    Why not to use QImage::Format_RGB888? It will eliminate need for a loop?

  7. #7
    Registered User
    Join Date
    Jun 2010
    Posts
    36

    Re: Use Gstreamer + Opencv

    Will it also eliminate the need for a gst-opencv port? Since I have very little time it would be interesting to know how you estimate the usefulness of this endeavour. Do both approaches perform equally ? Do you anticipate any benefit of preferring one over the other? Thanks in advance.

  8. #8
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    83

    Re: Use Gstreamer + Opencv

    Quote Originally Posted by Dorfmeister View Post
    Will it also eliminate the need for a gst-opencv port? Since I have very little time it would be interesting to know how you estimate the usefulness of this endeavour. Do both approaches perform equally ? Do you anticipate any benefit of preferring one over the other? Thanks in advance.
    I'v not tried the gst-opencv. Maybe that's not right, but I think the gst-opencv limits many functions of OpenCV. And I prefer to use the original libraries and functions of it.

  9. #9
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    83

    Re: Use Gstreamer + Opencv

    Quote Originally Posted by divanov View Post
    Why not to use QImage::Format_RGB888? It will eliminate need for a loop?
    Now I got the QImage to IplImage function. The problem I have met with is when and where to get the QImage from CameraN900:bufffer.

    The glwidget.cpp call the CameraN900:buffer to drawBackground. It is impossible to use the buffer again in other place since the drawBackground funtion will run in a loop. Otherwise, it might cause the segmentation fault. And indeed, I tried to call the CameraN900:buffer again in guiwidget.cpp in order to have a QImage, and I got segmentation fault. So my idea is I need to save the img, which is from

    QImage img(data, GLWidget::buffer_width, GLWidget::buffer_height,3*GLWidget::buffer_width, QImage::Format_RGB888);

    But in the function void GLWidget::drawBackground(QPainter *painter), how could I save it to somewhere and use it again in the main().

    I might think in a wrong way, but this is what I get so far. Any other ideas about this?

  10. #10
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: Use Gstreamer + Opencv

    Hi Guys,
    I've started to write a simple wiki page with few snippets about OpenCV with Qt
    The page can be improved by anyone:
    - adding the conversion to/from iplImages with different depth and/or channels
    - adding further suggestions for the integration of OpenCV in Qt apps.

    http://wiki.forum.nokia.com/index.ph...OpenCV_with_Qt

    Thanks

  11. #11
    Regular Contributor
    Join Date
    Nov 2009
    Posts
    83

    Re: Use Gstreamer + Opencv

    Quote Originally Posted by gnuton View Post
    Hi Guys,
    I've started to write a simple wiki page with few snippets about OpenCV with Qt
    The page can be improved by anyone:
    - adding the conversion to/from iplImages with different depth and/or channels
    - adding further suggestions for the integration of OpenCV in Qt apps.

    http://wiki.forum.nokia.com/index.ph...OpenCV_with_Qt

    Thanks
    excellent work! I will keep following it. Thank you.

Similar Threads

  1. Replies: 18
    Last Post: 2011-08-17, 13:30
  2. Opencv 2 j2me
    By cristiano.olifer in forum Mobile Java General
    Replies: 2
    Last Post: 2011-03-14, 20:05
  3. OpenCV in Qt example
    By Dorfmeister in forum Nokia N9
    Replies: 25
    Last Post: 2010-06-17, 08:57
  4. How to use OpenCV for Maemo5 app?
    By pta0007 in forum Nokia N9
    Replies: 18
    Last Post: 2010-03-10, 21:23
  5. Porting openCV library to Symbian
    By berny_ in forum Symbian
    Replies: 2
    Last Post: 2007-09-18, 14:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×