Ask Your Question

Error when converting OpenCV Mat to 2D array

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

Nbb gravatar image

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

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 =; //error here
unsigned char* dataMat =; //works here

EDIT: It seems like the following code works.

int* dataMat = (int*);

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

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

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
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 278 times

Last updated: Apr 06 '17