首先要将IplImage格式的图片转化为QImage格式,下边这个程序可以将一个Iplmage格式的图片转化为QImage RGB32格式
void Ipl2QImageRGB32(IplImage *iplImage, QImage *qImage){
unsigned char* ptrQImage=qImage->bits();
switch(iplImage->depth){
case IPL_DEPTH_8U:
if(iplImage->nChannels==1){
for(int row=0;row<iplImage->height;row++){
unsigned char* ptr=(unsigned char*)(iplImage->imageData+row*iplImage->widthStep);
for(int col=0;col<iplImage->width;col++){
*(ptrQImage)=*(ptr+col);
*(ptrQImage+1)=*(ptr+col);
*(ptrQImage+2)=*(ptr+col);
*(ptrQImage+3)=0;
ptrQImage+=4;
}
}
}
else if(iplImage->nChannels==3){
for(int row=0;row<iplImage->height;row++){
unsigned char* ptr=(unsigned