[英]Why I am getting error when I try to cast an opencv image data pointer to a char*
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? 为什么我收到此错误?
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. 从技术上讲,问题是
const_cast
只能更改CV限定词,而从uchar *const
为char *
作用还不止uchar *const
:它将还将unsigned char
(由OpenCV别名为uchar
)转换为char
,指针-明智的。
I would advise you not to remove the const qualifier. 我建议您不要删除const限定词。 But if you cannot avoid it, converting the pointer to
uchar*
instead should work for you. 但是,如果您无法避免,则将指针转换为
uchar*
应该适合您。
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*
,也可以这样做。
char* dp = reinterpret_cast<char*>(dataPointer);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.