Convert RGB array to Mat (OpenCv)
Asked Answered
B

1

5

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

Backstroke answered 24/11, 2013 at 18:27 Comment(1)
I think this question has the wrong title. Shouldn't it be RGB instead of RGBA?Acquaintance
S
8

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)

Sachi answered 24/11, 2013 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.