Results 1 to 3 of 3

Thread: qimage to iplimage

  1. #1
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default qimage to iplimage

    hi i am quite new to Qt, and i am stuck in a problem regarding converting a Qimage to Iplimage in my program,
    can anyone help me with this

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qimage to iplimage

    Never used OpenCV / IplImage before but google revealed this:

    http://www.c-plusplus.de/forum/viewt...art-is-10.html

    Qt Code:
    1. IplImage *img= ...
    2.  
    3. QImage *image= new QImage(img->width, img->height, QImage::Format_RGB32);
    4.  
    5. for (int y=0;y<img->height;y++)
    6. {
    7. unsigned int *dst= (unsigned int*)image->scanLine(y);
    8. unsigned char *src= (unsigned char*)img->imageData + y*img->width*3;
    9. for (int x=0;x<img->width;x++,src+=3)
    10. {
    11. *dst++= src[0] | (src[1]<<8) | (src[2]<<16) | (0xff<<24);
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    You just have to turn it around and make sure the destination format is right.. And you may need to adapt the pixel stride (src+=3 ) to whatever your source is.. look for uses of scanLine.

    Johannes

  3. #3
    Join Date
    Mar 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qimage to iplimage

    hi here is a code snippet of function i am usin to convert QImage to IplImage, but it gives the error : Invalid parameter passed to C runtime function.
    IplImage* ImageViewer::convertToIplImage(QImage *qImage)
    {
    cvNamedWindow("win1",CV_WINDOW_AUTOSIZE);
    IplImage* cvImage;
    cvImage = cvCreateImageHeader(cvSize(qImage->width(), qImage->height()), IPL_DEPTH_8U, 4);
    cvImage->imageData = (char*)qImage->bits();
    IplImage* colorImage = cvCreateImage( cvGetSize(cvImage), 8, 3 );
    cvConvertImage( cvImage, colorImage, 0 );
    cvShowImage("win1",colorImage);
    cvWaitKey(0);

    // if(!cvSaveImage("cvImage.bmp", cvImage)) printf("Could not save: cvImage.bmp in qtToCv");

    return colorImage;
    //return x;

    }

    can anyone tell me whats going wrong

Similar Threads

  1. QImage
    By hazardpeter in forum Newbie
    Replies: 2
    Last Post: 31st July 2009, 15:19
  2. QImage
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 17th October 2007, 20:35
  3. What's faster: QPixmap-to-QImage or QImage-to-QPixmap
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2006, 17:11
  4. QImage
    By mickey in forum Qt Programming
    Replies: 7
    Last Post: 14th July 2006, 21:54
  5. Replies: 3
    Last Post: 15th March 2006, 11:44

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
  •  
Qt is a trademark of The Qt Company.