Question

Possible Duplicate:
Fastest method to convert IplImage IPL_DEPTH_32S to QImage Format_RGB32

I am facing a weird problem in displaying image with Qt...I read a video frame using OpenCV and convert it into RGB from BGR.

video >> frameOrg;
cvtColor(frameOrg,frameOrg,CV_BGR2RGB);

then I select a ROI on the image using crop style..

frame = frameOrg(roi);

I send the selected ROI over signal/slot to a widget for display..the paintEvent() of the display uses

image = QImage((const unsigned char*)frame.data,frame.cols,
               frame.rows,QImage::Format_RGB888);

QRectF target(0.0,0.0,image.width(),image.height());
QRectF source(0.0,0.0,image.width(),image.height());
QPainter painter(this);
painter.drawImage(target,image,source);

But whenever I choose some combination of odd valued width and height of the ROI I get a weird display as shown below... ORIGINAL IMAGE

full image when displayed

IMAGE OF THE ROI SELECTED

image of selected roi

Do I need to do some modifications? Is windows 7 having some problem in displaying? The same ROI when displayed with imshow() displays correctly...any one help me..thanx in advance...

ACTUAL CODE WHICH WORKS

image = QImage((const unsigned char*)frame.data,frame.cols,
               frame.rows,frame.step,QImage::Format_RGB888);
Was it helpful?

Solution

This might be a padding issue. You haven't said what the type of your frame variable is, but IPLImage has a widthStep field. Use this constructor for QImage

QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )

and pass widthStep as the bytesPerLine parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top