opencv c++ (5):通道分离与合并

通道分离与合并

很简单,就split和merge api,例子在下面

#include 
#include
#include

using namespace std;
using namespace cv;

int main()
{

	Mat src = imread("src.jpg");
	if (src.empty())
	{
		cout << "could not open file!";
		cout << endl;
		return -1;
	}
	imshow("src", src);
	//1. 分离
	vector<Mat>mv;
	split(src, mv);
	int size = mv.size();
	cout << "channels numbers :" << size << endl;
	imshow("mv blue", mv[0]);
	imshow("mv Green", mv[1]);
	imshow("mv Red", mv[2]);

	//2. 合并
	Mat dst;
	mv[0] = Scalar(0);
	merge(mv, dst);
	imshow("dst", dst);
	waitKey(0);
	destroyAllWindows();
	return 0;
}

你可能感兴趣的:(opencv,c++,计算机视觉)