Convert IplImage to QImage

asked 2013-01-10 16:47:45 -0500

rizor gravatar image

Hi everybody,

I wrote some code which tries to convert IplImages (out of a video-stream) to a QImage. The problem is, that the code generates a SIGSEGV at cvGet2D.

This is the current version of the code:

QImage image(cvImage->width, cvImage->height, QImage::Format_RGB32);

pBits = image.bits();
bytesPerLine = image.bytesPerLine();
for (int y = 0; y < cvImage->height; y++) {
    for (int x = 0; x < cvImage->width; x++) {
        s = cvGet2D(cvImage, y, x);
        rgb = qRgb((unsigned char)s.val[2], (unsigned char)s.val[1],
                   (unsigned char)s.val[0]);
        scanLine = pBits + y * bytesPerLine;
        ((unsigned int*)scanLine)[x] = rgb;
    }
}

Here some values in the SIGSEGV-situation:

cvImage->height = 504
cvImage->width = 768
y = 168
x = 677

I have no idea what I can change. Do you have an idea how to fix the problem?

Greetings, rizor

edit retag flag offensive close merge delete