我想在OpenCV 2.4
中初始化三个通道的内核,我查看了文档,其中没有关于如何为多个通道的Mat
执行此操作的示例。
float data_[12] = {111, 112, 113, 121, 122, 123,
211, 212, 213, 221, 222, 223};
cv::Mat kernel(2, 2, CV_32FC3);
// How to initialize kernel with data_?
有没有办法使用kernel
初始化data_
以上?
答案 0 :(得分:1)
///! 2017.10.05 09:40:33 CST
/// convert uint8_t array/pointer to cv::Mat
#include <opencv2/core.hpp>
#include <iostream>
int main(){
uint8_t uarr[] = {1,2,3,4,5,6,7,8,9,10,11,12};
int rows = 2;
int cols = 2;
cv::Size sz(cols,rows);
cv::Mat mat1(sz,CV_8UC3, uarr);
cv::Mat mat2(rows, cols, CV_8UC3, uarr);
std::cout<< "mat1: \n"<<mat1 << "\n\nmat2:\n" << mat2 << std::endl;
return 0;
}
结果如下:
mat1:
[ 1, 2, 3, 4, 5, 6;
7, 8, 9, 10, 11, 12]
mat2:
[ 1, 2, 3, 4, 5, 6;
7, 8, 9, 10, 11, 12]
详细说明我的另一个答案: OpenCV - how to create Mat from uint8_t pointer