opencv IplImage*的格式 3通道转4通道
unsigned char *dataBackGround = NULL; //
dataBackGround = (unsigned char *)malloc( sizeof( unsigned char) * 4 * sizex * sizey );
cvNamedWindow("imagetest1", CV_WINDOW_AUTOSIZE);
IplImage* cvimg=0;
cvimg=cvLoadImage("C:\Users\Administrator\Desktop\background\background3.jpg", CV_LOAD_IMAGE_COLOR);
cvShowImage("imagetest1",cvimg);
for(y=0; y < cvimg->height; y++){
for(x=0; x < cvimg->width; x++) {
rgbTmp[0] = cvimg->imageData[cvimg->widthStep * y + x*3]; // B
rgbTmp[1] = cvimg->imageData[cvimg->widthStep * y + x*3 + 1]; // G
rgbTmp[2] = cvimg->imageData[cvimg->widthStep * y + x*3 + 2]; // R
//rgbTmp[0] = gray->imageData[cvimg->widthStep * y/3 + 640-x]; // B
//rgbTmp[1] = gray->imageData[cvimg->widthStep * y/3 + 640-x]; // G
//rgbTmp[2] = gray->imageData[cvimg->widthStep * y/3 + 640-x]; // R
opencvImage->imageData[opencvImage->widthStep * y + x*4] = rgbTmp[0];
opencvImage->imageData[opencvImage->widthStep * y + x*4 + 1] = rgbTmp[1];
opencvImage->imageData[opencvImage->widthStep * y + x*4 + 2] = rgbTmp[2];
opencvImage->imageData[opencvImage->widthStep * y + x*4 + 3] = 255;
}
}
memcpy(dataBackGround,opencvImage->imageData, opencvImage->imageSize);unsigned ch