#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
cv::Mat rgba( 10, 10, CV_8UC4, cv::Scalar(1,2,3,4) );
cv::Mat bgr( rgba.rows, rgba.cols, CV_8UC3 );
cv::Mat alpha( rgba.rows, rgba.cols, CV_8UC1 );
//对数据头进行复制
cv::Mat out[] = { bgr, alpha };
// 通道转换rgba[0] -> bgr[2], rgba[1]-> bgr[1],
// rgba[2] -> bgr[0], rgba[3] -> alpha[0]
int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
mixChannels( &rgba, 1, out, 2, from_to, 4 );
std::cout << out[0] << std::endl;
std::cout << out[1] << std::endl;
return 0;
}
转载:http://blog.youkuaiyun.com/zhuwei1988
本文提供了一个使用OpenCV进行图像通道转换的具体示例代码。该示例展示了如何从RGBA颜色空间转换到BGR和Alpha通道,并通过mixChannels函数完成这一过程。代码详细解释了通道映射的过程。
771

被折叠的 条评论
为什么被折叠?



