Search code examples
c++qtopencvqimageqpixmap

Convert IplImage to Qpixmap


How do we convert IplImage to a QPixmap or QImage?

If the only answer is save the Iplimage then load it to the QPixmap, then how do we do that?


Solution

  • IplImage * ImageToIplImage(QPixmap * qPix){
    
        int width = (qPix->toImage()).width();
        int height =(qPix->toImage()).height();
    
        // Creates a iplImage with 3 channels
    
        IplImage *img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
    
        for(int y=0;y<height;y++)
        {
            for(int x=0;x<width;x++ )
            {
                QRgb color = qPix->toImage().pixel(x,y);
                cvSet2D(img,y,x,cvScalar(qBlue(color),qGreen(color),qRed(color),1));
            }
        }
        return img; }
    

    it worked !! thanks to Fateh benmerzoug