Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert RGB array to Mat (OpenCv)

Tags:

c

opencv

rgb

mat

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

like image 702
raphaelluchini Avatar asked Nov 24 '13 18:11

raphaelluchini


1 Answers

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)

like image 145
berak Avatar answered Oct 16 '22 18:10

berak