Ask Your Question
0

Error when converting OpenCV Mat to 2D array

asked 2017-04-05 23:26:10 -0600

Nbb gravatar image

updated 2017-04-05 23:28:16 -0600

I am having an issue trying to convert my cv::Mat to a 2D array. A value of type uchar* cannot be used to initialize an entity of type int*. I converted my Mat to CV_32SC1 which I believe is of type int and definitely not uchar.

label = cv::imread(test_set_boundary[i], CV_LOAD_IMAGE_ANYDEPTH); 
label.convertTo(label, CV_32SC1); 
int* dataMat = label.data; //error here
unsigned char* dataMat = label.data; //works here

EDIT: It seems like the following code works.

int* dataMat = (int*)label.data;

Would anyone let me know why I still need to typecast ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-04-06 01:35:28 -0600

berak gravatar image

the official way to do it would be:

int *p = mat.ptr<int>(); // pointer to 1st element
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-05 23:26:10 -0600

Seen: 437 times

Last updated: Apr 06 '17