简体   繁体   中英

My QPixmap splits into 3 parts after conversion from IplImage* on Macbook pro with retina

I have a Qt project, that uses OpenCV, and try to move it to my macbook with retina-display. Everything works except QPixmap. When I try to display image in QLable, it splits into 3 parts with red, green and blue colors.

On Windows everything is OK.

But on my Macbook...

Here is how I convert IplImage* to QImage:

QImage CamStream::ToQImage(IplImage* image)

{

int height = image->height;
int width = image->width;

const uchar *qImageBuffer =(const uchar*)image->imageData;
QImage img(qImageBuffer, width, height, QImage::Format_RGB888);
return img.rgbSwapped();

}

Here is how I display the image:

void Main_window::ShowImage(QImage qimg)

{

QPixmap pxmap ( QPixmap::fromImage(qimg));
ui->lbl_video->setPixmap(pxmap);
ui_2->lbl_video->setPixmap(pxmap);

}

Try this:

// IplImage* -> QImage
QImage CamStream::ToQImage(IplImage* src)
{
    IplImage* dst = cvCreateImage(cvGetSize(src), src->depth, 3);
    cvCvtColor(src, dst, CV_BGRA2BGR);
    QImage qimg( (unsigned char*)dst->imageData,
                                 dst->width,
                                 dst->height,
                                 QImage::Format_RGB888 );
    cvReleaseImage(&dst);
    return qimg.rgbSwapped();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM