Invalid conversion error in cv2 file while installing opencv 3.3.0 on Raspberry Pi Stretch

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
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \

#cv2.cpp code at error location.

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


I had encountered same phenomenon. It was hard since compile takes much time and I spent more than half day to resolve this.


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. :)

Raspbian Stretch: Install OpenCV 3 + Python on your Raspberry Pi , Installing OpenCV 3 on a Raspberry Pi 3 running Raspbian Stretch After rebooting, your file system should have been expanded to include all available space on wget -O It sounds like the path is incorrect and cv2.imread is returning None. Once OpenCV has been installed, you can remove both the opencv-3.3.0 and opencv_contrib-3.3.0 directories to free up a bunch of space on your disk: $ rm -rf opencv-3.3.0 opencv_contrib-3.3.0 However, be cautious with this command! Make sure OpenCV has been properly installed on your system before blowing away these directories.

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);


const char* str = PyString_AsString(obj);

[SOLVED]Stretch OpenCV 3.3.0., Invalid conversion error in cv2 file while installing opencv 3.3.0 on Raspberry Pi Stretch. I am trying to build opencv 3.3.0 on raspberry pi 3 but facing an error at  So let’s put your fresh install of OpenCV on your Raspberry Pi to good use — just click here to learn more about the real-world projects you can solve using your Raspberry Pi + Practical Python and OpenCV . Summary. In this blog post, I have detailed how to install OpenCV 3.0 with Python 2.7+ and Python 3+ bindings on your Raspberry Pi 2.

After 3 days of frustration, I found out that,opencv is actually full of bugs and its not always your fault. I ran Opencv version 4(previously i was trying Opencv 3.3.0) on Raspberry pi stretch and it compiled smoothly without a single error. One more thing is to make sure you have increased your swap space to 2048 before compilation.


make it 2048 from 100.

Happy coding..!!

Install OpenCV 4.1.2 for Raspberry Pi 3 or 4 (Raspbian Buster , Once done space can be recovered by deleting zip and working folder. I've got an error with a #include_next <math.h> in cmath at around 23%. I've bodge-fixed Raspbian Stretch (probably Lite) install on a Pi2, 16GB card. Strangely I don't have a file in my OpenCV build. Install OpenCV 4 on Raspberry Pi 4 and Raspbian Buster In this tutorial, we will install and test OpenCV 4 on Raspbian Buster in five simple, easy-to-follow steps. If you’ve ever compiled OpenCV from scratch before, you know that the process is especially time-consuming and even painstakingly frustrating if you miss a key step or if you are

make error: While installing OpenCV 3.3.0 on Raspberry pi 3 · Issue , $ cd ~/opencv/opencv-4.1.2/build $ sudo make install. Check you can RPI 4 with 4GB RAM is actually 3906MB RAM after factoring in GPU RAM split. # We're probably cv2.imshow('image',img). cv2. error: template argument 2 is invalid In file included from Is it compatible with Raspberry pi stretch? Stats. Asked: 2014-01-16 19:48:47 -0500 Seen: 249 times Last updated: Jan 17 '14

Install OpenCV on Raspberry Pi, make error: While installing OpenCV 3.3.0 on Raspberry pi 3 #1567 OpenCV =​> 3.3.0; Operating System / Platform => Raspbian Stretch on Raspberry Pi 3; Compiler => I run make VERBOSE=1 and included the result in the attached file  From there, all you need to do is install OpenCV 3 on your Raspberry Pi 3: $ sudo make install $ sudo ldconfig Timing: 52s. Step #6: Finish installing OpenCV on your Pi. We’re almost done — just a few more steps to go and you’ll be ready to use your Raspberry Pi 3 with OpenCV 3. For Python 2.7:

[PDF] Motorcycle Dashcam - NORMA@NCI Library, In this post, we will provide a bash script for installing OpenCV (C++, 2.7 and Python 3.5) on Raspbian Operating System on Raspberry Pi. 1, echo "OpenCV installation by" heavy Python modules like Numpy, it's time to reset the swap file. error: invalid command 'bdist_wheel'. In this blog post I detailed how to install OpenCV and Python on your Raspberry Pi 2 or Raspberry Pi B+. Timings for each installation step were also provided so you could plan out the install accordingly. As the Raspberry Pi (along with Raspbian/NOOBS) evolves the installation instructions will likely change.

  • Appreciate your efforts. It's true that building opencv on the raspberry pi is not a smart way and there is website which provides precompiled packages.