I am trying to build opencv 3.3.0 on raspberry pi 3 but facing an error at 93% saying invalid conversion. Details are provided below any help will be greatly appreciated. please help.
This error message is showing up.
/home/pi/opencv-3.3.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.3.0/modules/python/src2/cv2.cpp:854:34: error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive] char* str = PyString_AsString(obj);In file included from /home/pi/opencv-3.3.0/modules/python/src2/cv2.c
I Tried these commands
cd ~/opencv-3.3.0/
$ mkdir build $ cd build $ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \ -D BUILD_EXAMPLES=ON ..
#cv2.cpp code at error location.
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;
}
I'd use sudo apt-get install python3-opencv
; but if you need the CMake compiled version, like for ROS, then it appears to be a bug in OpenCV; after I did the following change at opencv3/modules/python/src2/cv2.cpp lin 885, it compiled for me. Change...
char* str = PyString_AsString(obj);
to
const char* str = PyString_AsString(obj);
I had encountered same phenomenon. It was hard since compile takes much time and I spent more than half day to resolve this.
TLDR:
1) Building opencv is not recommended any more. Give up building from source.
2) Raspberry pie provides opencv wheel. Try this.
sudo pip3 install opencv-contrib-python
3) If it doesn't work, simply use apt-get
sudo apt-get install python-opencv
4) For python3,
sudo apt-get install python3-opencv
Please let me know if it works. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With