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);
上一篇:788. 逆序对的数量


下一篇:http协议之request