2

When I use cmake to build opencv-3.2.0 on Raspberry Pi, I encountered a weird error at the 99% of installation.

I did not change anything to not mess anything up, however it seems like a simple code error.

Here is the error appeared in my terminal

/home/pi/opencv-3.2.0/modules/python/src2/cv2.cpp: In function 
‘bool pyopencv_to(PyObject*, T&, const char*) [with T = 
cv::String; PyObject = _object]’:
/home/pi/opencv-3.2.0/modules/python/src2/cv2.cpp:730:34: error: 
invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
 char* str = PyString_AsString(obj);
In file included from /home/pi/opencv- 
3.2.0/modules/python/src2/cv2.cpp:1362:

and this is the pyopencv_to function in cv2.cpp

template<>
bool pyopencv_to(PyObject* obj, String& value, const char* name)
{
(void)name;
if(!obj || obj == Py_None)
    return true;
char* str = PyString_AsString(obj);
if(!str)
    return false;
value = String(str);
return true;
}

Should i manually change the code ?

1
  • Isn't OpenCV available via pacman on raspbian? Commented Jul 31, 2019 at 12:01

1 Answer 1

1

It appears to be a bug in OpenCV; after I did the following change at opencv3/modules/python/src2/cv2.cpp, it compiled for me. Change...

char* str = PyString_AsString(obj);

to

const char* str = PyString_AsString(obj);

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, it's seems to only happens in the rpi from what I've found. Weird, maybe compiler version?
I don't know personally. It could be a version mismatch, but if the fix is simple enough, I just change the codebase.
Well it's a little more for me since I included this as an ExternalProject_Add in my CMaktLists.txt that way there are no manual installation for different system. I fixed this by creating a diff file and applying the patch with git apply. I'd still like to know why this is okay with other system though o_0. I'm suspecting just different compiler flags/version
ya probably is compiler flags

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.