The Easiest Way to Save and Share Code Snippets on the web

C++: convert from IplImage to QImage

cpp-qt

posted: Jun, 23rd 2011 | jump to bottom

// Convert from IplImage to QImage
// (http://umanga.wordpress.com/2010/04/19/how-to-covert-qt-qimage-into-opencv-iplimage-and-wise-versa/)
void YarpInterface::fromIPLtoQImage(IplImage *iplImage, QImage *qtImage) {
 
	// Assume IplImage having 3 channels (RGB)
 
	int channels = iplImage->nChannels;
	char *data = iplImage->imageData;
	char r, g, b, a = 0;
 
	for (int y=0; y < qtImage->height(); y++, data += iplImage->widthStep)
 
		for (int x=0; x < qtImage->width(); x++) {
 
			r = data[x * 3];
			b = data[x * 3 + 2];
			g = data[x * 3 + 1];
 
			qtImage->setPixel(x, y, qRgb(r,g,b));
 
		}
}
49 views