Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error when converting OpenCV Mat to 2D array

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

Error when converting OpenCV Mat to 2D array

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 ?