Convert RGB array to Mat (OpenCv)

吃可爱长大的小学妹 提交于 2021-02-19 02:09:00

问题


I've been trying to convert an array [R,G,B,..] in Mat object with opencv. But is returning wrong data, someone knows why?

double data[12] = {0,0,255,0,0,255,0,0,255,0,0,255};
Mat src =  Mat(2,2, CV_16UC3, data);

and returns:

M = 
 [0, 0, 0, 0, 0, 0;
  0, 0, 0, 0, 57344, 16495]

EDIT:

Solved! use uchar instead double, and CV_8UC3


回答1:


i think, you wanted:

uchar data[12] = {0,0,255,0,0,255,0,0,255,0,0,255};
Mat src =  Mat(2,2, CV_8UC3, data);

(all red, 2x2 rbg image)



来源:https://stackoverflow.com/questions/20179171/convert-rgb-array-to-mat-opencv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!