Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将cv::Mat浇铸到ipcMatrix<;ipcRGB>;_C++_Opencv_Image Processing_Casting - Fatal编程技术网

C++ 将cv::Mat浇铸到ipcMatrix<;ipcRGB>;

C++ 将cv::Mat浇铸到ipcMatrix<;ipcRGB>;,c++,opencv,image-processing,casting,C++,Opencv,Image Processing,Casting,怀疑: 有没有一种简单的方法可以将cv::Mat转换为另一种数据类型?将cv::Mat转换为另一种数据类型的秘诀在于了解数据(像素)的存储和排序方式: OpenCV以cv::Mat的形式将数据存储为无符号字符数组,像素以BGR的顺序存储 ipcMatrix的工作原理基本相同,只是像素存储为RGB 也就是说,要将cv::Mat转换为ipcMatrix,您只需执行以下操作: // Load input image cv::Mat mat_input = cv::imread("input.jpg

怀疑:


有没有一种简单的方法可以将
cv::Mat
转换为另一种数据类型?

cv::Mat
转换为另一种数据类型的秘诀在于了解数据(像素)的存储和排序方式:

  • OpenCV以
    cv::Mat
    的形式将数据存储为
    无符号字符数组
    ,像素以BGR的顺序存储
  • ipcMatrix
    的工作原理基本相同,只是像素存储为RGB
也就是说,要将
cv::Mat
转换为
ipcMatrix
,您只需执行以下操作:

// Load input image
cv::Mat mat_input = cv::imread("input.jpg");

// Convert a BGR Mat into RGB:
cv::Mat mat_rgb;
cv::cvtColor(mat_input, mat_rgb, cv::COLOR_BGR2RGB);

// Copy the pixels from the Mat to another memory location:
int data_sz = mat_rgb.rows * mat_rgb.cols * mat_rgb.channels();
unsigned char* pixels = new unsigned char[data_sz];    
memcpy(pixels, mat_rgb.data, data_sz);

// And finally, use the constructor of ipcMatrix<> to declare the new object correctly:
ipcMatrix<ipcRGB> input = ipcMatrix<ipcRGB>(mat_rgb.cols, mat_rgb.rows, (ipcRGB*)pixels);
//加载输入图像
cv::Mat Mat_input=cv::imread(“input.jpg”);
//将BGR Mat转换为RGB:
cv::Mat Mat_rgb;
cv::CVT颜色(材质输入、材质rgb、cv::颜色BGR2RGB);
//将像素从Mat复制到另一个内存位置:
int data_sz=mat_rgb.rows*mat_rgb.cols*mat_rgb.channels();
无符号字符*像素=新的无符号字符[data_sz];
memcpy(像素、mat_rgb.data、data_sz);
//最后,使用ipcMatrix的构造函数正确声明新对象:
ipcMatrix输入=ipcMatrix(mat_rgb.cols,mat_rgb.rows,(ipcRGB*)像素);
< /代码>请将C++标记添加到问题中。