OpenCV学习笔记_图像转换cvCvtColor、通道分割cvSplit以及通道合并cvMerge

#include
#include

using namespace std;

int main(void){
	IplImage* cur;
	cur = cvLoadImage("D:\\testPic\\1.jpeg");
	IplImage* gray = cvCreateImage(cvGetSize(cur), cur->depth, 1);
	IplImage* dst1 = cvCreateImage(cvGetSize(cur), cur->depth, 1);
	IplImage* dst2 = cvCreateImage(cvGetSize(cur), cur->depth, 1);
	IplImage* dst3 = cvCreateImage(cvGetSize(cur), cur->depth, 1);
        IplImage* returnSrc = cvCreateImage(cvGetSize(cur), cur->depth, 3);

       //将RGB图像转换成灰度图像
	cvCvtColor(cur, gray, CV_RGB2GRAY);
	//将图片分成多个单通道
	cvSplit(cur, dst1, dst2, dst3, NULL);
        //cvMerge为cvSplit的逆操作,合并通道
        cvMerge(dst1, dst2, dst3, NULL, returnSrc);
       cvShowImage("cur", cur);
	cvShowImage("gray", gray);
	cvShowImage("dst1", dst1);
	cvShowImage("dst2", dst2);
	cvShowImage("dst3", dst3);
        cvShowImage("returnSrc", returnSrc);
       cvWaitKey(0);
	return 0;
}

你可能感兴趣的:(OpenCV学习)