1. 程式人生 > >OpenCV學習筆記_影象轉換cvCvtColor、通道分割cvSplit以及通道合併cvMerge

OpenCV學習筆記_影象轉換cvCvtColor、通道分割cvSplit以及通道合併cvMerge

#include<cv.h>
#include<highgui.h>

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;
}