Convert RGB Array to Mat (OpenCv)

I am trying to convert an array [R,G,B,..]to a Mat object with opencv. But it returns incorrect data, does someone know 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 of double instead, and CV_8UC3

+4
source share
1 answer

I think you would like:

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)

+6
source

All Articles