0

I have this code:

cv::Mat myImage = imread("Image.png");
char * dataPointer = const_cast<char*>(myImage.data);

but I am getting error:

'const_cast' : cannot convert from 'uchar *const ' to 'char *'  

Why I am getting this error?

Codor
  • 17,235
  • 9
  • 32
  • 52
mans
  • 15,766
  • 39
  • 153
  • 296

1 Answers1

1

Technically, the issue is that a const_cast can only change the CV-qualifiers, and a cast from uchar *const to char * does a bit more than that: it will also convert unsigned char (aliased by OpenCV to uchar) to char, pointer-wise.

I would advise you not to remove the const qualifier. But if you cannot avoid it, converting the pointer to uchar* instead should work for you.

cv::Mat myImage = imread("Image.png");
uchar * dataPointer = const_cast<uchar*>(myImage.data);

If you really want a char*, that can be done too.

char* dp = reinterpret_cast<char*>(dataPointer);
E_net4 - Krabbe mit Hüten
  • 24,143
  • 12
  • 85
  • 121