在嵌入式系统中实现qt和opencv的处理,最基础的就是QImage和IplImage之间的转换。这样两者就可以进行一起使用图像数据,从而达到利用qt显示和利用opencv处理的功能。
下面我将贴出代码:
QImage ----->> IplImage
- QImage *IplImageToQImage(const IplImage *img)
- {
- QImage *image;
- cvCvtColor(img,img,CV_BGR2RGB);
- uchar *imgData=(uchar *)img->imageData;
- image=new QImage(imgData,img->width,img->height,QImage::Format_RGB888);
- return image;
- }
IplImage ------->>QImage
- IplImage *QImageToIplImage(const QImage * qImage)
- {
- int width = qImage->width();
- int height = qImage->height();
- CvSize Size;
- Size.height = height;
- Size.width = width;
- IplImage *IplImageBuffer = cvCreateImage(Size, IPL_DEPTH_8U, 3);
- for (int y = 0; y < height; ++y)
- {
- for (int x = 0; x < width; ++x)
- {
- QRgb rgb = qImage->pixel(x, y);
- cvSet2D(IplImageBuffer, y, x, CV_RGB(qRed(rgb), qGreen(rgb), qBlue(rgb)));
- }
- }
- return IplImageBuffer;
- }