Хотел-бы поделиться функцией преобразования IplImage в QImage:
// Эта функция копирует IplImage 8бит, 3 канала в Qt QImage
// не выделяет новый размер для входного QImage
// Для неё нужно создать входной QImage нужного размера
int IplCopyToQImage(IplImage *img,QImage &qimg)
{
if (!img) return 1;
int minw = std::min(img->width,qimg.width());
int minh = std::min(img->height,qimg.height());
if (minw == 0 || minh == 0) return 2;
for (int y = 0;y < minh;y++)
{
uchar *ptr = (uchar*)(img->imageData + y*img->widthStep);
QRgb *ptrDst = (QRgb*)(qimg.scanLine(y));
for (int x = 0;x<minw ;x++)
{
int b = ptr[3*x];
int g = ptr[3*x+1];
int r = ptr[3*x+2];
*ptrDst=qRgb(r,g,b);// opt:: using scanline here
ptrDst++;
};
};
return 0;
}
// Эта функция сама пересоздаст нужных размеров QImage
int IplToQImage(IplImage *img,QImage &qimg)
{
if (img == 0) return 1;
int w = img->width;
int h = img->height;
qimg = QImage(img->width,img->height,QImage::Format_RGB32);
return 1+IplCopyToQImage(img,qimg);
}

Свежие комментарии