2

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);
Community
  • 1
  • 1
rotating_image
  • 3,046
  • 4
  • 28
  • 46
  • Isn't a +1 missing somewhere ? A row `i` is always left-shifted by `i` columns, which is just a propagation of the the previous row missing 1 column. – mmgp Jan 24 '13 at 17:36
  • this is not always occurring...for some combination only I am getting such weird results... – rotating_image Jan 24 '13 at 18:01
  • Explicitly indicate some of those combinations then. – mmgp Jan 24 '13 at 18:03
  • I've talked about this [here](http://stackoverflow.com/a/11371701/176769). – karlphillip Jan 24 '13 at 20:04
  • 2
    @karlphillip this question is clearly not a duplicate of that one. It is dealing with an entirely different problem than the one described here. – mmgp Jan 24 '13 at 21:06

1 Answers1

4

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.

sashoalm
  • 75,001
  • 122
  • 434
  • 781