IplImage* src; src = cvLoadImage("C:\Users\xht\Desktop\open\ba.jpg"); IplImage* imgRed = cvCreateImage(cvGetSize(src),8,1); IplImage* imgGreen = cvCreateImage(cvGetSize(src),8,1); IplImage* imgBlue = cvCreateImage(cvGetSize(src),8,1); cvSplit(src,imgBlue,imgGreen,imgRed,NULL);
IplImage* img; img = cvLoadImage("C:\\Users\\xht\\Desktop\\open\\ba.jpg"); cvNamedWindow("img"); cvShowImage("img",img); IplImage* imgRed = cvCreateImage(cvGetSize(img),8,1); IplImage* imgGreen = cvCreateImage(cvGetSize(img),8,1); IplImage* imgBlue = cvCreateImage(cvGetSize(img),8,1); for (int y = 0 ;y < img->height;y++) { unsigned char* prow = (unsigned char*)(img->imageData + y * img->widthStep); //img->imageData是图像的起始地址,img->widthStep是图像行数据长度,*y后跳到第y行的开头 unsigned char* brow = (unsigned char*)(imgBlue->imageData + y * imgBlue->widthStep); unsigned char* grow = (unsigned char*)(imgGreen->imageData + y * imgGreen->widthStep); unsigned char* rrow = (unsigned char*)(imgRed->imageData + y * imgRed->widthStep); for (int x=0;x < img->width;x++) { brow[x] = prow[3 * x + 0] ; grow[x] = prow[3 * x + 1] ; rrow[x] = prow[3 * x + 2] ; } }