c++ - OpenCv Mat initialization from array not working -
i initializing mat object array this
int data[4] = {111,2,3,4}; mat = mat(2, 2, cv_8uc1, data);
now when printing value @ (1,1) should 4
cout<<"\n m1 @ 1,1 "<<(int)a.at<uchar>(1,1);
it printing- 0
i using vs2008 in windows xp , opencv 2.3. stuck on since yesterday.
your matrix holds 8 bit elements (that cv_8uc1
means). passing array of ints. assuming 32 bit ints, first one, 111
, should enough fill array. significant 8 bits of 111
go position 1,1
, , these 0
s. element value 0
.
try passing 8 bit unsigned elements:
unsigned char data[4] = {111,2,3,4}; mat = mat(2, 2, cv_8uc1, data);
alternatively, if need store signed 32
bit elements, use cv_32s
.
Comments
Post a Comment