Ask Your Question
0

Initialize Mat with type CV_8UC1 from array

asked 2018-02-25 21:04:37 -0600

Kenny Karnama gravatar image

updated 2018-02-25 21:22:39 -0600

Hi guys, i tried to initialize my Mat variable which size is 4 x 9. Here is my code :

int dummy_query_data[36] = { 
        255, 0, 255, 255,255,255,0,255,255,
        255,0,0,255,255,255,255,255,255,
        255,0,0,255,255,255,0,255,255,
        255,0,0,255,255,255,255,255,255
     };


Mat C = Mat(4,9,CV_8UC1,dummy_query_data);

But when i print it to the console using

cout << "C = "<< endl << " "<< C << endl;

It gives incorrect result

C = 
 [255,   0,   0,   0,   0,   0,   0,   0, 255;
   0,   0,   0, 255,   0,   0,   0, 255,   0;
   0,   0, 255,   0,   0,   0,   0,   0,   0;
   0, 255,   0,   0,   0, 255,   0,   0,   0]

Any solution regarding this ? thanks.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-02-25 21:07:02 -0600

berak gravatar image

updated 2018-02-25 21:12:45 -0600

it's a type mismatch, it should be uchar instead of int as in:

 uchar dummy_query_data[4*9] = ...
edit flag offensive delete link more

Comments

also, 4x6 or 4x9 ? be concise !

(4x9 == 36, how on earth did you come up with 38 ?)

berak gravatar imageberak ( 2018-02-25 21:11:07 -0600 )edit

thanks, it works @berak

Kenny Karnama gravatar imageKenny Karnama ( 2018-02-25 21:15:29 -0600 )edit

@berak, hi man. i have already fixed it. sorry for mistakes. and thanks it really works. thank you so much

Kenny Karnama gravatar imageKenny Karnama ( 2018-02-25 21:23:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-25 21:04:37 -0600

Seen: 1,749 times

Last updated: Feb 25 '18