这个刚开始不知道怎么弄,后来问了下网友,原来一个spit函数搞定!
#include <cv.h> #include <highgui.h> //#include <math.h> int main() { IplImage* src = cvLoadImage( "F:\\hehua.jpg", 1 ); IplImage * RedChannel = cvCreateImage( cvGetSize(src), 8, 1); IplImage * GreenChannel = cvCreateImage( cvGetSize(src), 8, 1); IplImage * BlueChannel = cvCreateImage( cvGetSize(src), 8, 1); IplImage * alphaChannel = cvCreateImage( cvGetSize(src), 8, 1); cvSplit(src,BlueChannel,GreenChannel,RedChannel,0); cvNamedWindow( "RedChannel", 1 ); cvNamedWindow( "GreenChannel", 1 ); cvNamedWindow( "BlueChannel", 1 ); cvNamedWindow( "lphaChannel", 1 ); cvShowImage( "RedChannel", RedChannel ); cvShowImage( "GreenChannel", GreenChannel ); cvShowImage( "BlueChannel", BlueChannel ); cvShowImage( "lphaChannel", alphaChannel ); cvWaitKey(0); cvReleaseImage( &RedChannel ); cvReleaseImage( &GreenChannel ); cvReleaseImage( & BlueChannel ); cvReleaseImage( & alphaChannel ); return 0; }
cvSplit(src,BlueChannel,GreenChannel,RedChannel,0);