opencv之通道的分离和合并
通道分离
将一个多通道矩阵分离成几个单通道的矩阵.
void split(const Mat& src, Mat* mvbegin);
void split(InputArray m, OutputArrayOfArrays mv);
注: 输出为std::vector
容器
通道合并
将多个单通道矩阵合并成一个多通道的矩阵.
void merge(const Mat* mv, size_t count, OutputArray dst);
void merge(InputArrayOfArrays mv, OutputArray dst);
实例
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
std::string image_name = "/home/liuzhiyang/test/color_image.png";
cv::Mat color_image;
color_image = cv::imread(image_name, cv::IMREAD_COLOR);
std::vector<cv::Mat> v_channel;
cv::Mat blue_channel, green_channel, red_channel;
cv::split(color_image, v_channel);
blue_channel = v_channel.at(0);
green_channel = v_channel.at(1);
blue_channel = v_channel.at(2);
cv::Mat merge_image;
cv::merge(v_channel, merge_image);
chrislzy: 如有疑惑,错误或者建议,请在评论区留下您宝贵的文字; 转载请注明作者和出处,未经允许请勿用于商业用途!