Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install OpenCV 4.1.2 for Raspberry Pi 3 or 4 (Raspbian Buster)

Install OpenCV 4.1.2 on Raspbian Buster

$ chmod +x *.sh
$ ./download-opencv.sh
$ ./install-deps.sh
$ ./build-opencv.sh
$ cd ~/opencv/opencv-4.1.2/build
$ sudo make install

Check you can run test.py using both python 2 and 3 to verify that OpenCV python bindings were successfully installed

$ wget "https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png" -O lenna.jpg
$ python2 test.py lenna.jpg
$ python3 test.py lenna.jpg

WARNING: Users of boards with 1GB of memory

Compiling is very memory intensive, you will likely need to increase your swap size. Assuming you have a reasonably large SD card (>16GB to be safe), follow the procedure below to increase your swap size from the default 100MB to 2GB

$ sudo dphys-swapfile swapoff
$ sudo sed -i 's:CONF_SWAPSIZE=.*:CONF_SWAPSIZE=2048:g' /etc/dphys-swapfile
$ sudo reboot
#!/usr/bin/env bash
set -ex
OPENCV_VERSION=4.1.2
pushd ~/opencv/opencv-$OPENCV_VERSION
mkdir -p build
pushd build
MEM="$(free -m | awk /Mem:/'{print $2}')" # Total memory in MB
# RPI 4 with 4GB RAM is actually 3906MB RAM after factoring in GPU RAM split.
# We're probably good to go with `-j $(nproc)` with 3GB or more RAM.
if [[ $MEM -ge 3000 ]]; then
NUM_JOBS=$(nproc)
else
NUM_JOBS=1 # Earlier versions of the Pi don't have sufficient RAM to support compiling with multiple jobs.
fi
# -D ENABLE_PRECOMPILED_HEADERS=OFF
# is a fix for https://github.com/opencv/opencv/issues/14868
# -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic
# is a fix for https://github.com/opencv/opencv/issues/15192
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-$OPENCV_VERSION/modules \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_DOCS=ON \
-D BUILD_EXAMPLES=ON \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D WITH_TBB=ON \
-D WITH_OPENMP=ON \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D PYTHON_EXECUTABLE=$(which python2) \
..
make -j "$NUM_JOBS"
popd; popd
#!/usr/bin/env bash
set -ex
OPENCV_VERSION=4.1.2
cd ~
mkdir -p opencv && pushd opencv
wget -O "opencv-${OPENCV_VERSION}.tar.gz" "https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.tar.gz"
wget -O "opencv_contrib-${OPENCV_VERSION}.tar.gz" "https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.tar.gz"
tar -xvf "opencv-${OPENCV_VERSION}.tar.gz"
tar -xvf "opencv_contrib-${OPENCV_VERSION}.tar.gz"
popd
#!/usr/bin/env bash
set -ex
sudo apt-get purge -y libreoffice*
sudo apt-get clean
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt-get autoremove -y
# For some reason I couldn't install libgtk2.0-dev or libgtk-3-dev without running the
# following line
# See https://www.raspberrypi.org/forums/viewtopic.php?p=1254646#p1254665 for issue and resolution
sudo apt-get install -y devscripts debhelper cmake libldap2-dev libgtkmm-3.0-dev libarchive-dev \
libcurl4-openssl-dev intltool
sudo apt-get install -y build-essential cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
libxvidcore-dev libx264-dev libgtk2.0-dev libgtk-3-dev \
libatlas-base-dev libblas-dev libeigen{2,3}-dev liblapack-dev \
gfortran \
python2.7-dev python3-dev python-pip python3-pip python python3
sudo pip2 install -U pip
sudo pip3 install -U pip
sudo pip2 install numpy
sudo pip3 install numpy
import numpy as np
import cv2
import sys
if len(sys.argv) < 2:
print("USAGE: {} img-file".format(sys.argv[0]))
sys.exit(1)
# Load an color image in grayscale
img = cv2.imread(sys.argv[1],0)
cv2.imshow('image',img)
cv2.waitKey(5000)
cv2.destroyAllWindows()
@rememberlenny

This comment has been minimized.

Copy link

rememberlenny commented Jul 18, 2019

Thank you @willprice!

@Mapellnor

This comment has been minimized.

Copy link

Mapellnor commented Aug 1, 2019

Fookin legend, thanks!

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

Hi, If I give you this error when running ./build-opencv.sh is there help you can give me? Installing opencv so far has proven to be a pure one week nightmare

[ 29%] Linking CXX shared library ../../lib/libopencv_core.so
[ 29%] Built target opencv_core
make: *** [Makefile:163: all] Error 2

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

Hi @willmendil, You'll have to give me much more information than just that snippet to be able to help. I suggest you follow these instructions and copy and paste your entire session logs onto https://pastebin.com/ and share the link. OpenCV builds can sometimes fail due to using too many threads, try running make instead of make -j $(nproc)

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

the log was too long for pastebin: here's another link https://www.codepile.net/pile/yJnjmVJm
I'll try using thus make

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

Yeah, this looks like g++ might be getting killed by OOM

c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.

How much RAM does your pi have? Run dmesg | egrep -i 'killed process' to see whether there are any kernel logs OOM kills.

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

0.85gb

runing your command i get

[11959.017754] Killed process 29841 (cc1plus) total-vm:437356kB, anon-rss:375340kB, file-rss:0kB, shmem-rss:0kB

i don't know what it means

edit: it's a raspberry pi 3 but running buster, hence why i thought your script would work, am I wrong?

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

It means you've run out of memory during compilation, so the kernel killed the g++ process compiling your code, hence why your build fails. I've not tested this on RPi 3, just on the 4. But given the OS version is the same it should work. You need to decrease the number of threads building code as this will reduce memory usage. See how make works instead of make -j $(nproc).

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

ooohhh, right that could explain it. The cpu and ram are indeed running near 100%, I'm running the make, (maybe i should do j2 as it has 4 cores) I'll keep you updates, in, oh i don't know, a week when the compilation has finished ^^

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

Even though you've got enough cores to run make with 2, or even 4 jobs, memory is your bottleneck. I'd play it safe and start with compiling with a single thread, then experimenting to see whether you can compile with more threads before running out of memory.

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

:( got an error:
Do you need more log?

[ 21%] Linking CXX shared library ../../lib/libopencv_highgui.so
[ 21%] Built target opencv_highgui
Scanning dependencies of target example_hdf_create_groups
[ 21%] Building CXX object modules/hdf/CMakeFiles/example_hdf_create_groups.dir/samples/create_groups.cpp.o
[ 21%] Linking CXX executable ../../bin/example_hdf_create_groups
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.0: undefined reference to `tbb::interface7::internal::task_arena_base::internal_max_concurrency(tbb::interface7::task_arena const*)'
collect2: error: ld returned 1 exit status
make[2]: *** [modules/hdf/CMakeFiles/example_hdf_create_groups.dir/build.make:90: bin/example_hdf_create_groups] Error 1
make[1]: *** [CMakeFiles/Makefile2:2866: modules/hdf/CMakeFiles/example_hdf_create_groups.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

Hmmm, looks like it's erroring due to Intel Threaded Building Blocks (TBB) support.
Perhaps try changing
-D WITH_TBB=ON to -D WITH_TBB=OFF

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

ok, am trying that. Won't that make opencv slower though? ( i guess it's better slow than none working but just wondered)

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

Maybe try building with OpenMP support instead: -D WITH_OPENMP=ON. Whether it's slower or not depends on what functions you're using in OpenCV and whether they've been parallelised using TBB or OpenMP.

@OldMan74

This comment has been minimized.

Copy link

OldMan74 commented Aug 1, 2019

Hi Will, I spent most of last week trying to get OpenCV to install on Raspbian Buster and was not successful! In fact, I finally gave up. I just came across your post and am inspired to try again using your scripts. But I have a couple of questions first:

  1. I notice that in build-opencv.sh there are two identical lines: -D CMAKE_BUILD_TYPE=RELEASE \ are they both necessary?
  2. I am a C++ guy. Do I really need both -D PYTHON3_EXECUTABLE=$(which python3) \ and -D PYTHON_EXECUTABLE=$(which python2) \
    I would prefer to just forget about python2. Also, at this point, I don't know if I will ever use python3. I don't even know which version of python comes with Buster. Is it safe to omit both lines in the build? If I decide to keep python3 which version should I specify?
@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

Hi @OldMan74

  1. You're quite right, that shouldn't be there. I've removed it. Thanks
  2. You should be able to drop both of those if you don't have python installed (although it's likely it is already installed on your machine). If you just want python 3, then you should be able to just keep -D PYTHON3_EXECUTABLE=$(which python3)
@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

regarding point 1, is that a problem ? should I restart my build. I'm up 35% since my last message :s

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

@willmendil no not at all, it's just redundant. Leave your build going :)

@OldMan74

This comment has been minimized.

Copy link

OldMan74 commented Aug 1, 2019

Thanks Will. Here I go... one more time... We will see what happens this time. Thanks for the quick response! 🙂

@alkaiaeq2

This comment has been minimized.

Copy link

alkaiaeq2 commented Aug 1, 2019

Have been trying these scripts all morning....i get to roughly the same build point each iteration and then the pi freezes. I am doing this on a fresh buster build on a 3 b+....i get no error messages or anything it just freezes...i tried removing -j and seem to lock up even sooner during the build....locks up when building modules/python2/CMakeFiles/opencv_python2,dir/__/src2/cv2.cpp.o

This is at 80% in to the build

Trying now with your suggestion to willmendil of setting WITH_TBB=OFF and currently building...

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

[ 77%] Built target example_stereo_dense_disparity
Scanning dependencies of target gen_opencv_python_source
[ 77%] Generate files for Python bindings and documentation
Note: Class Feature2D has more than 1 base class (not supported by Python C exte  nsions)
      Bases:  cv::Algorithm, cv::class, cv::Feature2D, cv::Algorithm
      Only the first base class will be used
Note: Class detail_GraphCutSeamFinder has more than 1 base class (not supported   by Python C extensions)
      Bases:  cv::detail::GraphCutSeamFinderBase, cv::detail::SeamFinder
      Only the first base class will be used
[ 77%] Built target gen_opencv_python_source
Scanning dependencies of target opencv_python2
[ 77%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2  /cv2.cpp.o
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [modules/python2/CMakeFiles/opencv_python2.dir/build.make:63: modul  es/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:19045: modules/python2/CMakeFiles/opencv_pyth  on2.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

oh my god.... it seems to be the same error as before. Any clues on how to solve that?

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

No, this one seems to be a different issue, perhaps related to opencv/opencv#12972
I've updated the version to 4.1.1, maybe you might have more luck with that release?
I'll test on my RPi 4 now. If I have time tonight I might also bring up a RPi 3 to test on too.

@alkaiaeq2

This comment has been minimized.

Copy link

alkaiaeq2 commented Aug 1, 2019

Stalled at the same point even after setting WITH_TBB=OFF

Going to try with 4.1.1 in your recent update....like i said the pi merely locks up with no error codes or anything.

@willmendil2

This comment has been minimized.

Copy link

willmendil2 commented Aug 1, 2019

Would you be able to compil it on your side and post a script that would install your compilation on my pi?

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

you forgot to edit cd ~/opencv/opencv-4.1.0/build

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 1, 2019

@willmendil2, that's what I'm trying at the moment.

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 1, 2019

set WITH_TBB=OFF with your new .sh will see tomorrow if it has worked.

@oneshell

This comment has been minimized.

Copy link

oneshell commented Aug 1, 2019

@willprice I was able to compile and it seems I've installed opencv just fine, but when I enter python3 and import cv2 it says "no module named cv2". Any advice?

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 2, 2019

@oneshell do you virtualenv or any other python environment management tool?

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 2, 2019

 Scanning dependencies of target example_hdf_create_groups
[ 22%] Building CXX object modules/hdf/CMakeFiles/example_hdf_create_groups.dir/                                                                                           samples/create_groups.cpp.o
[ 22%] Linking CXX executable ../../bin/example_hdf_create_groups
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic                                                                                           _fetch_add_8'
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic                                                                                           _fetch_sub_8'
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic                                                                                           _store_8'
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic                                                                                           _load_8'
/usr/bin/ld: ../../lib/libopencv_core.so.4.1.1: undefined reference to `__atomic                                                                                           _compare_exchange_8'
collect2: error: ld returned 1 exit status
make[2]: *** [modules/hdf/CMakeFiles/example_hdf_create_groups.dir/build.make:90                                                                                           : bin/example_hdf_create_groups] Error 1
make[1]: *** [CMakeFiles/Makefile2:2689: modules/hdf/CMakeFiles/example_hdf_crea                                                                                           te_groups.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 2, 2019

(I think you could move this project to a proper github repo, so the changes in the scripts could be followed, and maybe contributed upon)

@oneshell

This comment has been minimized.

Copy link

oneshell commented Aug 2, 2019

@willprice Thanks for your response. I often use virtual environments, although on this particular application I am not.

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 2, 2019

@willmendil The latest update " -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic" should fix this. It's a known bug in opencv 4.1.1
I will consider making a repo.

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 2, 2019

ok am trying this now

@alkaiaeq2

This comment has been minimized.

Copy link

alkaiaeq2 commented Aug 2, 2019

Have you successfully deployed this on RPi3 of any kind? I get to the same place every time and the Pi freezes...Right after the opencv_stereo build.....sometimes different objects after that but always the next set of objects being built that does it.

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 2, 2019

Have you successfully deployed this on RPi3 of any kind? I get to the same place every time and the Pi freezes...Right after the opencv_stereo build.....sometimes different objects after that but always the next set of objects being built that does it.

No I have not, as stated in the description of this gist:

Install OpenCV 4.1.1 for Raspberry Pi 4 (Raspbian Buster)

I am currently experimenting to see whether I can get it to build. The current scripts work on RPi 4, not on 3. Currently the compiler segfaults during compilation

/home/pi/opencv/opencv_contrib-4.1.1/modules/xphoto/src/annf.hpp: In constructor ‘KDTree<Tp, cn>::KDTree(const cv::Mat&, int, int) [with Tp = float; int cn = 24]’:
/home/pi/opencv/opencv_contrib-4.1.1/modules/xphoto/src/annf.hpp:178:1: internal compiler error: Segmentation fault
 }
 ^

I will have a bash at seeing whether I can figure out the magic incantation to get it to build, but until then I'd suggest you wait.

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 2, 2019

I'm at 44% for the moment, will see if it works. If not, I'll flash raspbian stretch and just install it with pip which apparently works . piwheels/packages#28 (comment), I don't think I'll be getting a Rpi4 right now.

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 2, 2019

@oneshell OpenCV should install packages to /usr/local/lib/python3.7/dist-packages/cv2/ for python 3.7, and /usr/local/lib/python2.7/dist-packages/cv2/ for python 2.7. Can you provide me with the output of the following commands:

$ tree ~/opencv/opencv-4.1.*/build/python_loader
$ ls /usr/local/lib/python*/dist-packages/
$ ls /usr/local/lib/python*/dist-packages/cv2/
@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 2, 2019

Scanning dependencies of target gen_opencv_python_source
[ 77%] Generate files for Python bindings and documentation
Note: Class Feature2D has more than 1 base class (not supported by Python C exte                                                                                           nsions)
      Bases:  cv::Algorithm, cv::class, cv::Feature2D, cv::Algorithm
      Only the first base class will be used
Note: Class detail_GraphCutSeamFinder has more than 1 base class (not supported                                                                                            by Python C extensions)
      Bases:  cv::detail::GraphCutSeamFinderBase, cv::detail::SeamFinder
      Only the first base class will be used
[ 77%] Built target gen_opencv_python_source
Scanning dependencies of target opencv_python2
[ 77%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2                                                                                           /cv2.cpp.o
c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [modules/python2/CMakeFiles/opencv_python2.dir/build.make:63: modul                                                                                           es/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:15642: modules/python2/CMakeFiles/opencv_pyth                                                                                           on2.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

again at 77% even with -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic, guess i'll be downgrading to stretch. If you get it working, let me know

@tigdra

This comment has been minimized.

Copy link

tigdra commented Aug 3, 2019

Awesome!!! Worked out great. Thanks!

@OldMan74

This comment has been minimized.

Copy link

OldMan74 commented Aug 3, 2019

Hi Will. FINALLY! I got it to compile. At first, I continued to run into the dreaded "make: *** [Makefile:163: all] Error 2" error. Then, due to something I read somewhere on this site, I begin to think I was running out of memory or perhaps some kind of a timing problem using multiple cores. So I switched to using only one core and it roared right pass the error locations!! Then it died from some "undefined reference to atomic_ ..." But I remember seeing some comments on your site about a bug in 4.1.1 and -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic so I changed cmake to include that and it ground away all the way to the end! So thanks so much for the help! 🙂

You were right - both Python2 and Python3 come with Raspbian Buster so I decided it was okay to make the Python libraries. However, when I verified that the Python library build was successful, I got the following error:
image
Perhaps that "atomic" bug didn't get fully fixed? Any ideas on how I might fix it? As I said before, I am a C++ guy so probably won't be doing much with Python so can live without for a while. Thanks again for all your hard work.

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 3, 2019

@OldMan74, the version I compiled overnight has the same issue too. I'm trying to build 4.1.0 now to see whether that resolves the problem. 4.1.1 seems to be rather challenging to build to say the least. I think the primary issue with building on RPi 3 is the lack of memory, hence the updated instructions now state users with boards with 1GB of RAM or less should create a decent sized swap file.

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 3, 2019

@OldMan74, @willmendil. I have successfully compiled OpenCV 4.1.0 on RPi 3 using 2019-07-10-raspbian-buster.img and run the test.py files. Make sure to increase your swap file size!

@rememberlenny

This comment has been minimized.

Copy link

rememberlenny commented Aug 3, 2019

@willmendil

This comment has been minimized.

Copy link

willmendil commented Aug 3, 2019

@willprice I had increased to 1024MB as many tutorials instructed but it had never worked. I've fanally given up and downgrade to raspbian stretch as I needed to get work done. Using the pip install from piwheel works fine

@OldMan74

This comment has been minimized.

Copy link

OldMan74 commented Aug 3, 2019

@rememberlenny, I agree with you TOTALLY! - why isn't there a standard Linux installer like there is for Windows?! Why does every person have to struggle with all the compile problems and all the terminal commands that must be input? I just want to learn to use the OpenCV library - not learn about all the quirks that must be overcome to get it to install! I have wasted nearly two weeks trying to get OpenCV to install when I could have been using that time to write code to learn using OpenCV.

@simeon9696

This comment has been minimized.

Copy link

simeon9696 commented Aug 4, 2019

@willprice You're amazing man, downloaded today and it worked right away. Literally spent the last week re-flashing my SD card and following a million tutorials. Thank you so much! - RPi 3 Model B Raspbian Buster July 2019 💃

@arielgaga

This comment has been minimized.

Copy link

arielgaga commented Aug 5, 2019

Hello, Thanks for posting this!
I've followed a few guides and got stuck trying to run any version of OpenCV on raspberry pi 3 b+ .
Do you guys have any step by step guide to follow along this setup? how should i start with this?
Also im installing buster from NOOBS can it create problems?

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 5, 2019

Hi @arielgaga,
Just follow the steps in the README. I have not tested on the RPi 3 B+, but i have on the RPi 3 B which is very similar. Be sure to increase your swap size (instructions in the README). I have not tested on noobs either, but providing it provides the same environment as the normal raspbian distro does you should be OK.

@arielgaga

This comment has been minimized.

Copy link

arielgaga commented Aug 5, 2019

Thanks @willprice your help is very appreciated! I am getting through your guide and
ive got to the last part and when i need to do the --- python2 test.py lenna.jpg .
When i run it im getting the error -

Traceback (most recent call last):
File "test.py", line 11, in
cv2.imshow('image',img)
cv2.error: OpenCV(4.1.0) /home/pi/opencv/opencv-4.1.0/modules/highgui/src/window.cpp:627: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

any idea what causing this?

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 6, 2019

Hi @arielgaga,
That's surprising as the error message lists some packages to install but both should be installed by the install-deps.sh script. Did that run without error?

Can you paste the output of the following command

$ dpkg -l libgtk2.0-dev pkg-config
@arielgaga

This comment has been minimized.

Copy link

arielgaga commented Aug 6, 2019

Thanks @willprice
I've repeated install-deps. sh script then bulilded again and now it is working!!!
its probably because i etited the swap size and didnt rebooted. LOL it took some time...
thanks for everything

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 6, 2019

Glad it worked :)

@ekouwe

This comment has been minimized.

Copy link

ekouwe commented Aug 7, 2019

Thanks alot for your work! Unfortunatly I have the same problem as oneshell had 6 days ago: I was able to compile and install opencv on a 3B+ with Buster. When running the testfile, Python had no problem with import numpy as np but it gave an error on import cv2: "no module named cv2". I found the solution to be:
Try again from scratch:
Format a 16 GB SD card on your PC with an SD Card Formatter;
Download Raspbian Buster to your PC;
Use an Etcher to copy the image to the SD card;
Start your RPi with the SD card inserted & follow the instructions (skip: Update Software; do: Restart);
Open this page in the RPi browser & select Download ZIP;
Extract All files, no boxes checked, to /home/pi/;
Open the README.md file and open a terminal;
Copy the three lines regarding the swapfile one by one to the terminal and execute them;
After the Reboot again open the README.md file and a terminal;
Now you can start copying all the lines from the README.md file to the terminal, starting with
pi@raspberrypy:~$ chmod +x *.sh
Don't forget to restore the original swapfile by changing 2048 back to 100.

Thanks again Will!!

@Pougnator

This comment has been minimized.

Copy link

Pougnator commented Aug 11, 2019

Wooohooo! Worked for me, RPi 3 B with Buster. I had to do the memory trick, and include the -D OPENCV_EXTRA_EXE_LINKER_FLAGS=-latomic to tackle the Error2. Thanks a lot @willprice! Your post put an end to a week of miserable build failure

@divahno

This comment has been minimized.

Copy link

divahno commented Aug 13, 2019

Installation went okay but test.py fails:

# python3 test.py lenna.jpg
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import cv2
ModuleNotFoundError: No module named 'cv2

Run commands you mentioned above:

$ tree ~/opencv/opencv-4.1.*/build/python_loader
$ ls /usr/local/lib/python*/dist-packages/
$ ls /usr/local/lib/python*/dist-packages/cv2/

result was:

/root/opencv/opencv-4.1.0/build/python_loader
├── build
│   ├── bdist.linux-armv7l
│   └── lib
│       └── cv2
│           ├── config.py
│           ├── __init__.py
│           ├── load_config_py2.py
│           └── load_config_py3.py
├── cv2
│   ├── config.py
│   ├── __init__.py
│   ├── load_config_py2.py
│   └── load_config_py3.py
├── dist
│   └── opencv-4.1.0-py3.7.egg
├── opencv.egg-info
│   ├── dependency_links.txt
│   ├── PKG-INFO
│   ├── requires.txt
│   ├── SOURCES.txt
│   └── top_level.txt
└── setup.py

7 directories, 15 files
/usr/local/lib/python2.7/dist-packages/:

/usr/local/lib/python3.7/dist-packages/:
easy-install.pth  numpy  numpy-1.17.0.dist-info
ls: cannot access '/usr/local/lib/python*/dist-packages/cv2/': No such file or directory

Few notes:

  • using Buster Lite from 07-10-19
  • build was without issues
  • had to install pip3 to install numpy

Any thoughts are appreciated

@DigitalMakerCIC

This comment has been minimized.

Copy link

DigitalMakerCIC commented Aug 13, 2019

Added following optimisations to make file, taken from pyimagesearch -D ENABLE_NEON=ON
-D ENABLE_VFPV3=ON \

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 13, 2019

@DigitalMakerCIC, thanks, added to the cmake invocation.

@divahno

This comment has been minimized.

Copy link

divahno commented Aug 13, 2019

My problem was somewhat solved by using "virtualenv" (again help from pyimagesearch).

Problem was related that CMAKE configuration was not showing python3. After I have installed virtualenv and run cmake, it properly showed:

from pyimagesearch

from pyimagesearch

and after the installation, I had to do "Link OpenCV 4 into your Python 3 virtual environment"

$ cd ~/.virtualenvs/cv/lib/python3.7/site-packages/
$ ln -s /usr/local/bin/python/cv2/python-3.7/site-packages/cv2.cpython-35m-arm-linux-gnueabihf.so cv2.so
$ cd ~

Now, I will flash Raspian Buster Lite again and try it without virtualenv. :)

@ekouwe

This comment has been minimized.

Copy link

ekouwe commented Aug 13, 2019

@divahno: I had the same problem too. I think I forgot (the next morning) to type in the last two commands
cd ~/opencv/opencv-4.1.0/build
sudo make install
Hopefully this is the solution!

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 13, 2019

Hi @divahno. Good to know you managed to get at least one configuration working. I've tested this on freshly installed Raspbian Buster (not lite, although I'd have hoped that install-deps.sh would still install everything, I'll have a bash at some point with lite to double check)

You shouldn't have needed to install numpy yourself as install-deps.sh should do this.

From your command output it looks as if sudo make install hasn't been run from the build directory once the build has been completed.

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 14, 2019

@divahno
I tried building on Raspbian Buster Lite today and found that pip2/3 are missing. I've updated the install-deps.sh script to ensure these are installed. Once I'd done this I was able to successfully build OpenCV 4.1.0 on the RPi 4 using this setup.

@arielgaga

This comment has been minimized.

Copy link

arielgaga commented Aug 14, 2019

Hello guys, @divahno,@willprice
I have a question regarding virtualenv module.
I am currently working on an OpenCV project that tracks objects in video streams in realtime.
I'm getting a 1~5 FPS video because of heavy filtering methods.
I've installed OpenCV directly from PIP2 and PIP3 for Python 2 and 3 and not on virtualenv.
i am looking for better results and PFS speed. Do you recommend installing again from start rasberian with virtualenv?
i am running currently - raspbian buster desktop from NOOBS.
And i will be happy to get some tips and advice about making this faster
Thank you in advance
Ariel

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 14, 2019

@arielgaga

Virtualenv isn't going to make any difference in speed.

Perhaps try recompiling with the flags DigitalMakerCIC provided above (these have now been integrated into the build script in this gist--so you can simply follow the instructions again to get a build with NEON and VFPV3 acceleration

@OldMan74

This comment has been minimized.

Copy link

OldMan74 commented Aug 14, 2019

Hi @arielgaga,@willprice.
When I saw the last couple of comments, I can't resist adding my two cents. I agree with Will, virtualenv isn't going to make any speed difference. I am running OpenCV version 4.1.0 (thanks to Will and a couple of other websites) on a Raspberry Pi 3B that is controlling a PiCar-V (with USB camera) from Sunfounder. I don't know how many FPS I am getting, but the target symbol placed on a yellow tennis ball in the video follows the ball without a problem as I move the ball around with my hand. I would guess I am getting at least 10 FPS. One difference, I am writing the code in C++ (that may improve the speed - but only slightly I would imagine). I am following Kyle Hounslow's excellent YouTube video on object tracking. The video is first converted into an HSV image, then filtered and turned into a black/white image with some OpenCV morphing to improve the image. Then the OpenCV findContours function is called followed by OpenCV moments to locate the target and find its position in the frame and finally a cross-hairs target is painted on the video image. I am only tracking a single object and have yet to add the vehicle control to follow the object, but, so far, it seems that the processing speed is sufficient. I would be interested in learning more about your project.

@arielgaga

This comment has been minimized.

Copy link

arielgaga commented Aug 15, 2019

Hi @OldMan74 and Will
Thank you guys for the advice, my project is about people tracking and counting direction they are walking (it's useful for shopping malls, airports, etc...). It's for a school project. I agree C++ is the best option, but I'm writing it in python in order to practice the language.
I am currently trying to recompile OpenCV with the flags mentioned above, updates about the performance increase will come...
I am getting the error on CLI: "configuration incomplete, errors occurred! "

cMakeError.log ----> https://pastebin.com/32RBkEhu
cMakeOutput.log --> https://pastebin.com/WLuPTpNa

Should i clean install everything? I'm looking for a low time consuming option

@shahid377

This comment has been minimized.

Copy link

shahid377 commented Aug 15, 2019

@ willprice, is it possible with 16 GB memory card with RPI 3B to install OpenCV or I should buy 64 GB?

@shahid377

This comment has been minimized.

Copy link

shahid377 commented Aug 15, 2019

As you mentioned that RP3 B memory is not efficient and we need to use the sd card as RAM. if we increase swap rate to 2gb then left memory size is enough for OpenCV 4.1?

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 15, 2019

@shahid377, I'd give it a go with 2GB swap and see what happens. I've not measured the high water mark of memory usage. If you use fewer jobs -j then you'll keep the memory usage lower.

@shahid377

This comment has been minimized.

Copy link

shahid377 commented Aug 16, 2019

[ 8%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfRgbaYca.cpp.o
[ 8%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfRleCompressor.cpp.o
[ 8%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfScanLineInputFile.cpp.o
In file included from /usr/include/c++/8/vector:69,
from /home/pi/opencv/opencv-4.1.0/3rdparty/openexr/IlmImf/ImfMisc.h:47,
from /home/pi/opencv/opencv-4.1.0/3rdparty/openexr/IlmImf/ImfScanLineInputFile.cpp:44:
/usr/include/c++/8/bits/vector.tcc: In member function ‘void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {Imf::{anonymous}::InSliceInfo}; _Tp = Imf::{anonymous}::InSliceInfo; _Alloc = std::allocatorImf::{anonymous}::InSliceInfo]’:
/usr/include/c++/8/bits/vector.tcc:413:7: note: parameter passing for argument of type ‘std::vectorImf::{anonymous}::InSliceInfo::iterator’ {aka ‘__gnu_cxx::__normal_iterator<Imf::{anonymous}::InSliceInfo*, std::vectorImf::{anonymous}::InSliceInfo >’} changed in GCC 7.1
vector<_Tp, _Alloc>::
^~~~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/vector.tcc: In member function ‘void Imf::ScanLineInputFile::setFrameBuffer(const Imf::FrameBuffer&)’:
/usr/include/c++/8/bits/vector.tcc:109:4: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<Imf::{anonymous}::InSliceInfo*, std::vectorImf::{anonymous}::InSliceInfo >’ changed in GCC 7.1
_M_realloc_insert(end(), std::forward<_Args>(__args)...);
^~~~~~~~~~~~~~~~~
/usr/include/c++/8/bits/vector.tcc:109:4: note: parameter passing for argument of type ‘__gnu_cxx::__normal_iterator<Imf::{anonymous}::InSliceInfo*, std::vectorImf::{anonymous}::InSliceInfo >’ changed in GCC 7.1
_M_realloc_insert(end(), std::forward<_Args>(__args)...);
^~~~~~~~~~~~~~~~~
[ 8%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfStandardAttributes.cpp.o
[ 8%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfStdIO.cpp.o

@shahid377

This comment has been minimized.

Copy link

shahid377 commented Aug 16, 2019

@willprice, could you please check the above log info?, during build I get so many exception

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Aug 16, 2019

Please don't paste bits of commands across multiple comments, use pastebin or similar. These are just information notifications, not exceptions.

@shahid377

This comment has been minimized.

Copy link

shahid377 commented Aug 16, 2019

Ok thank you so much for you kind response. if I will have any problem to install openCV I will let you know

@shahid377

This comment has been minimized.

Copy link

shahid377 commented Aug 17, 2019

@ Willprice Thank you so much for sharing instructions about opencv. After follow you, finally I installed opencv on my raspberry pi 3B

pi@raspberrypi:~/opencv/opencv-4.1.0/build $ python
Python 2.7.16 (default, Apr 6 2019, 01:42:57)
[GCC 8.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import cv2
quit();
pi@raspberrypi:~/opencv/opencv-4.1.0/build $ python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import cv2

@martinptm

This comment has been minimized.

Copy link

martinptm commented Aug 19, 2019

Thanks. I have the pi4b with 2GB ram and use an 32GB SD-Card. First $ ./build-opencv.sh stoppet at 81%. Not sure if it really was the problem, but when i increased the swap size as recommended and retried it continued and worked perfectly

@mattsj91

This comment has been minimized.

Copy link

mattsj91 commented Aug 28, 2019

Many thanks, Will!
I have tried about 8 other methods to get OpenCV on the Rpi, and yours was the only one that has worked.

@shineofleo

This comment has been minimized.

Copy link

shineofleo commented Aug 30, 2019

Hi thanks for all the details.

I just got my brand new rpi 4 with Raspbian Buster. I simply got stuck at libgtk-3-dev installation. As you mentioned,

For some reason I couldn't install libgtk2.0-dev or libgtk-3-dev without running the

following line

See https://www.raspberrypi.org/forums/viewtopic.php?p=1254646#p1254665 for issue and resolution

sudo apt-get install -y devscripts debhelper cmake libldap2-dev libgtkmm-3.0-dev libarchive-dev
libcurl4-openssl-dev intltool

But the libgtkmm-3.0-dev also depends on libgtk-3-dev such as:

The following packages have unmet dependencies:
libgtkmm-3.0-dev : Depends: libgtk-3-dev (>= 3.22.0) but it is not going to be installed
Depends: libcairomm-1.0-dev (>= 1.12.0) but it is not going to be installed
Depends: libpangomm-1.4-dev (>= 2.38.2) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Any idea how to get around? I checked the link but not much help... rpi4 and Buster are quite new so not much info around the internet.

thanks!

@sahilastangocharlie

This comment has been minimized.

Copy link

sahilastangocharlie commented Aug 30, 2019

@willprice Thanks for the tutorial. I have RPI4B 1GB with full buster installed.
I am stuck at 99% from more than 2 hours after "./build-opencv.sh" command and the output is as follows.

[ 99%] built target example_tutorial_imgproc_drawContours
[ 99%] built target example_tutorial_imgproc_HoughLinesPointSet

what should i do???
thanks:(

@sahilastangocharlie

This comment has been minimized.

Copy link

sahilastangocharlie commented Aug 30, 2019

@willprice again thanks for the tutorial.
Whole 6 hours of build. Interrupted at 99% by closing the terminal directly and again from build directory manually done "make".

@sumitkm

This comment has been minimized.

Copy link

sumitkm commented Aug 31, 2019

@willprice I was able to build on Raspberry Pi 4 + Buster but struggling on Pi 3B+. However I think I may have corrupted the build. Is there a way to clean the build so the compile process starts at zero instead of where it left off?

Update* I figured I should have deleted the ~/opencv/opencv[version/build folder, but I deleted the entire ~/opencv folder :D :D :D Never mind, downloaded again and restarted compile... will know tomorrow morning, shall report back.

Update 2 Clean rebuild worked the second time... The build had failed/got corrupted first time because I think it stopped midway when my ssh session died (noobie error)

Swap file has been increased

Build crashing at 77% but with following error

[ 77%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp: In function ‘PyObject* pycvSetMouseCallback(PyObject*, PyObject*, PyObject*)’:
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1580:14: error: ‘setMouseCallback’ was not declared in this scope
     ERRWRAP2(setMouseCallback(name, OnMouse, py_callback_info));
              ^~~~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1580:14: note: suggested alternative: ‘pycvSetMouseCallback’
     ERRWRAP2(setMouseCallback(name, OnMouse, py_callback_info));
              ^~~~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp: In function ‘PyObject* pycvCreateTrackbar(PyObject*, PyObject*)’:
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1629:14: error: ‘createTrackbar’ was not declared in this scope
     ERRWRAP2(createTrackbar(trackbar_name, window_name, value, count, OnChange, py_callback_info));
              ^~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1629:14: note: suggested alternative: ‘pycvCreateTrackbar’
     ERRWRAP2(createTrackbar(trackbar_name, window_name, value, count, OnChange, py_callback_info));
              ^~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp: In function ‘PyObject* pycvCreateButton(PyObject*, PyObject*, PyObject*)’:
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1691:14: error: ‘createButton’ was not declared in this scope
     ERRWRAP2(createButton(button_name, OnButtonChange, py_callback_info, button_type, initial_button_state != 0));
              ^~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1691:14: note: suggested alternative: ‘pycvCreateButton’
     ERRWRAP2(createButton(button_name, OnButtonChange, py_callback_info, button_type, initial_button_state != 0));
              ^~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:3,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/core/misc/python/pyopencv_umat.hpp: In function ‘void* cv_UMat_queue()’:
/home/pi/opencv/opencv-4.1.0/modules/core/misc/python/pyopencv_umat.hpp:20:16: error: ‘cv::ocl’ has not been declared
     return cv::ocl::Queue::getDefault().ptr();
                ^~~
/home/pi/opencv/opencv-4.1.0/modules/core/misc/python/pyopencv_umat.hpp: In function ‘void* cv_UMat_context()’:
/home/pi/opencv/opencv-4.1.0/modules/core/misc/python/pyopencv_umat.hpp:25:16: error: ‘cv::ocl’ has not been declared
     return cv::ocl::Context::getDefault().ptr();
                ^~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:4,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp: At global scope:
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:2:9: error: ‘cvflann’ does not name a type
 typedef cvflann::flann_distance_t cvflann_flann_distance_t;
         ^~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:3:9: error: ‘cvflann’ does not name a type
 typedef cvflann::flann_algorithm_t cvflann_flann_algorithm_t;
         ^~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:6:31: error: ‘cvflann_flann_algorithm_t’ does not name a type
 PyObject* pyopencv_from(const cvflann_flann_algorithm_t& value)
                               ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:6:11: error: redefinition of ‘PyObject* pyopencv_from(const T&) [with T = int; PyObject = _object]’
 PyObject* pyopencv_from(const cvflann_flann_algorithm_t& value)
           ^~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:658:11: note: ‘PyObject* pyopencv_from(const T&) [with T = int; PyObject = _object]’ previously declared here
 PyObject* pyopencv_from(const int& value)
           ^~~~~~~~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:4,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:12:31: error: ‘cvflann_flann_distance_t’ does not name a type
 PyObject* pyopencv_from(const cvflann_flann_distance_t& value)
                               ^~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:12:11: error: redefinition of ‘PyObject* pyopencv_from(const T&) [with T = int; PyObject = _object]’
 PyObject* pyopencv_from(const cvflann_flann_distance_t& value)
           ^~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:658:11: note: ‘PyObject* pyopencv_from(const T&) [with T = int; PyObject = _object]’ previously declared here
 PyObject* pyopencv_from(const int& value)
           ^~~~~~~~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:4,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:18:35: error: ‘cv::flann’ has not been declared
 bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name)
                                   ^~~~~
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:18:53: error: expected ‘,’ or ‘...’ before ‘&’ token
 bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name)
                                                     ^
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:18:6: error: template-id ‘pyopencv_to<>for ‘bool pyopencv_to(PyObject*, int)’ does not match any template declaration
 bool pyopencv_to(PyObject *o, cv::flann::IndexParams& p, const char *name)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1277:6: note: candidates are: ‘template<class _Tp> bool pyopencv_to(PyObject*, std::vector<_Tp>&, ArgInfo)’
 bool pyopencv_to(PyObject* obj, std::vector<_Tp>& value, const ArgInfo info)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1086:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1073:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1060:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1047:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1034:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1021:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1008:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:995:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:982:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:576:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Scalar&, ArgInfo)’
 static bool pyopencv_to(PyObject *o, Scalar& s, const ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:512:6: note:                 ‘template<class _Tp, int m, int n> bool pyopencv_to(PyObject*, cv::Matx<_Tp, m, n>&, const char*)’
 bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const char* name)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:500:6: note:                 ‘template<class _Tp, int m, int n> bool pyopencv_to(PyObject*, cv::Matx<_Tp, m, n>&, ArgInfo)’
 bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const ArgInfo info)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:314:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Mat&, ArgInfo)’
 static bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:24:6: note:                 ‘template<class T> bool pyopencv_to(PyObject*, T&, const char*)’
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
      ^~~~~~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:4,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:69:37: error: ‘cv::flann’ has not been declared
 bool pyopencv_to(PyObject* obj, cv::flann::SearchParams & value, const char * name)
                                     ^~~~~
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:69:57: error: expected ‘,’ or ‘...’ before ‘&’ token
 bool pyopencv_to(PyObject* obj, cv::flann::SearchParams & value, const char * name)
                                                         ^
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:69:6: error: template-id ‘pyopencv_to<>for ‘bool pyopencv_to(PyObject*, int)’ does not match any template declaration
 bool pyopencv_to(PyObject* obj, cv::flann::SearchParams & value, const char * name)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1277:6: note: candidates are: ‘template<class _Tp> bool pyopencv_to(PyObject*, std::vector<_Tp>&, ArgInfo)’
 bool pyopencv_to(PyObject* obj, std::vector<_Tp>& value, const ArgInfo info)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1086:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1073:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1060:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1047:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1034:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1021:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1008:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:995:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:982:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:576:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Scalar&, ArgInfo)’
 static bool pyopencv_to(PyObject *o, Scalar& s, const ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:512:6: note:                 ‘template<class _Tp, int m, int n> bool pyopencv_to(PyObject*, cv::Matx<_Tp, m, n>&, const char*)’
 bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const char* name)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:500:6: note:                 ‘template<class _Tp, int m, int n> bool pyopencv_to(PyObject*, cv::Matx<_Tp, m, n>&, ArgInfo)’
 bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const ArgInfo info)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:314:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Mat&, ArgInfo)’
 static bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:24:6: note:                 ‘template<class T> bool pyopencv_to(PyObject*, T&, const char*)’
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
      ^~~~~~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:4,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:75:31: error: ‘cvflann’ has not been declared
 bool pyopencv_to(PyObject *o, cvflann::flann_distance_t& dist, const char *name)
                               ^~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:75:56: error: expected ‘,’ or ‘...’ before ‘&’ token
 bool pyopencv_to(PyObject *o, cvflann::flann_distance_t& dist, const char *name)
                                                        ^
/home/pi/opencv/opencv-4.1.0/modules/flann/misc/python/pyopencv_flann.hpp:75:6: error: template-id ‘pyopencv_to<>for ‘bool pyopencv_to(PyObject*, int)’ does not match any template declaration
 bool pyopencv_to(PyObject *o, cvflann::flann_distance_t& dist, const char *name)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1277:6: note: candidates are: ‘template<class _Tp> bool pyopencv_to(PyObject*, std::vector<_Tp>&, ArgInfo)’
 bool pyopencv_to(PyObject* obj, std::vector<_Tp>& value, const ArgInfo info)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1086:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1073:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1060:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1047:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1034:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1021:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1008:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:995:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:982:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:576:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Scalar&, ArgInfo)’
 static bool pyopencv_to(PyObject *o, Scalar& s, const ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:512:6: note:                 ‘template<class _Tp, int m, int n> bool pyopencv_to(PyObject*, cv::Matx<_Tp, m, n>&, const char*)’
 bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const char* name)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:500:6: note:                 ‘template<class _Tp, int m, int n> bool pyopencv_to(PyObject*, cv::Matx<_Tp, m, n>&, ArgInfo)’
 bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const ArgInfo info)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:314:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Mat&, ArgInfo)’
 static bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:24:6: note:                 ‘template<class T> bool pyopencv_to(PyObject*, T&, const char*)’
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
      ^~~~~~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:6,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv_contrib-4.1.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:3:40: error: ‘ppf_match_3d’ was not declared in this scope
 template<> struct pyopencvVecConverter<ppf_match_3d::Pose3DPtr >
                                        ^~~~~~~~~~~~
/home/pi/opencv/opencv_contrib-4.1.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:3:40: note: suggested alternative: ‘rpmatch’
 template<> struct pyopencvVecConverter<ppf_match_3d::Pose3DPtr >
                                        ^~~~~~~~~~~~
                                        rpmatch
/home/pi/opencv/opencv_contrib-4.1.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:3:64: error: template argument 1 is invalid
 template<> struct pyopencvVecConverter<ppf_match_3d::Pose3DPtr >
                                                                ^
/home/pi/opencv/opencv_contrib-4.1.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:16:21: error: ‘ppf_match_3d’ was not declared in this scope
 typedef std::vector<ppf_match_3d::Pose3DPtr> vector_Pose3DPtr;
                     ^~~~~~~~~~~~
/home/pi/opencv/opencv_contrib-4.1.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:16:21: note: suggested alternative: ‘rpmatch’
 typedef std::vector<ppf_match_3d::Pose3DPtr> vector_Pose3DPtr;
                     ^~~~~~~~~~~~
                     rpmatch
/home/pi/opencv/opencv_contrib-4.1.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:16:44: error: template argument 1 is invalid
 typedef std::vector<ppf_match_3d::Pose3DPtr> vector_Pose3DPtr;
                                            ^
/home/pi/opencv/opencv_contrib-4.1.0/modules/surface_matching/misc/python/pyopencv_ppf_match_3d.hpp:16:44: error: template argument 2 is invalid
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:7,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:2:9: error: ‘dnn’ does not name a type
 typedef dnn::DictValue LayerId;
         ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:3:21: error: ‘dnn’ was not declared in this scope
 typedef std::vector<dnn::MatShape> vector_MatShape;
                     ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:3:34: error: template argument 1 is invalid
 typedef std::vector<dnn::MatShape> vector_MatShape;
                                  ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:3:34: error: template argument 2 is invalid
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:4:33: error: ‘dnn’ was not declared in this scope
 typedef std::vector<std::vector<dnn::MatShape> > vector_vector_MatShape;
                                 ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:4:46: error: template argument 1 is invalid
 typedef std::vector<std::vector<dnn::MatShape> > vector_vector_MatShape;
                                              ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:4:46: error: template argument 2 is invalid
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:4:48: error: template argument 1 is invalid
 typedef std::vector<std::vector<dnn::MatShape> > vector_vector_MatShape;
                                                ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:4:48: error: template argument 2 is invalid
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:8:31: error: ‘dnn’ has not been declared
 bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const char *name)
                               ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:8:46: error: expected ‘,’ or ‘...’ before ‘&’ token
 bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const char *name)
                                              ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:8:6: error: template-id ‘pyopencv_to<>for ‘bool pyopencv_to(PyObject*, int)’ does not match any template declaration
 bool pyopencv_to(PyObject *o, dnn::DictValue &dv, const char *name)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1277:6: note: candidates are: ‘template<class _Tp> bool pyopencv_to(PyObject*, std::vector<_Tp>&, ArgInfo)’
 bool pyopencv_to(PyObject* obj, std::vector<_Tp>& value, const ArgInfo info)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1086:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1073:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1060:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec2d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec2d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1047:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1034:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1021:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec3d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec3d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1008:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4i&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4i& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:995:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4f&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4f& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:982:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Vec4d&, ArgInfo)’
 static bool pyopencv_to(PyObject* obj, Vec4d& v, ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:576:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Scalar&, ArgInfo)’
 static bool pyopencv_to(PyObject *o, Scalar& s, const ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:512:6: note:                 ‘template<class _Tp, int m, int n> bool pyopencv_to(PyObject*, cv::Matx<_Tp, m, n>&, const char*)’
 bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const char* name)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:500:6: note:                 ‘template<class _Tp, int m, int n> bool pyopencv_to(PyObject*, cv::Matx<_Tp, m, n>&, ArgInfo)’
 bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const ArgInfo info)
      ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:314:13: note:                 ‘bool pyopencv_to(PyObject*, cv::Mat&, ArgInfo)’
 static bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo info)
             ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:24:6: note:                 ‘template<class T> bool pyopencv_to(PyObject*, T&, const char*)’
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
      ^~~~~~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:7,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:44:31: error: ‘dnn’ does not name a type
 PyObject* pyopencv_from(const dnn::DictValue &dv)
                               ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:44:46: error: expected unqualified-id before ‘&’ token
 PyObject* pyopencv_from(const dnn::DictValue &dv)
                                              ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:44:45: error: expected ‘)’ before ‘&’ token
 PyObject* pyopencv_from(const dnn::DictValue &dv)
                        ~                    ^~
                                             )
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:44:47: error: expected initializer before ‘dv’
 PyObject* pyopencv_from(const dnn::DictValue &dv)
                                               ^~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:58:31: error: ‘dnn’ does not name a type
 PyObject* pyopencv_from(const dnn::DictValue &dv)
                               ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:58:46: error: expected unqualified-id before ‘&’ token
 PyObject* pyopencv_from(const dnn::DictValue &dv)
                                              ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:58:45: error: expected ‘)’ before ‘&’ token
 PyObject* pyopencv_from(const dnn::DictValue &dv)
                        ~                    ^~
                                             )
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:58:47: error: expected initializer before ‘dv’
 PyObject* pyopencv_from(const dnn::DictValue &dv)
                                               ^~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:68:31: error: ‘dnn’ does not name a type
 PyObject* pyopencv_from(const dnn::LayerParams& lp)
                               ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:68:47: error: expected unqualified-id before ‘&’ token
 PyObject* pyopencv_from(const dnn::LayerParams& lp)
                                               ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:68:47: error: expected ‘)’ before ‘&’ token
 PyObject* pyopencv_from(const dnn::LayerParams& lp)
                        ~                      ^
                                               )
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:68:49: error: expected initializer before ‘lp’
 PyObject* pyopencv_from(const dnn::LayerParams& lp)
                                                 ^~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:78:35: error: ‘dnn’ has not been declared
 class pycvLayer CV_FINAL : public dnn::Layer
                                   ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:78:40: error: expected ‘{’ before ‘Layer’
 class pycvLayer CV_FINAL : public dnn::Layer
                                        ^~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:80:1: error: expected primary-expression before ‘public’
 public:
 ^~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:80:1: error: expected ‘}’ before ‘public’
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:79:1: note: to match this ‘{’
 {
 ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp: In function ‘void registerLayer(const string&, PyObject*)’:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:99:71: error: ‘pyLayers’ was not declared in this scope
         std::map<std::string, std::vector<PyObject*> >::iterator it = pyLayers.find(type);
                                                                       ^~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:99:71: note: suggested alternative: ‘Layer’
         std::map<std::string, std::vector<PyObject*> >::iterator it = pyLayers.find(type);
                                                                       ^~~~~~~~
                                                                       Layer
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp: In function ‘void unregisterLayer(const string&)’:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:108:71: error: ‘pyLayers’ was not declared in this scope
         std::map<std::string, std::vector<PyObject*> >::iterator it = pyLayers.find(type);
                                                                       ^~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:108:71: note: suggested alternative: ‘Layer’
         std::map<std::string, std::vector<PyObject*> >::iterator it = pyLayers.find(type);
                                                                       ^~~~~~~~
                                                                       Layer
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp: At global scope:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:118:16: error: ‘dnn’ was not declared in this scope
     static Ptr<dnn::Layer> create(dnn::LayerParams &params)
                ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:118:26: error: template argument 1 is invalid
     static Ptr<dnn::Layer> create(dnn::LayerParams &params)
                          ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:118:35: error: ‘dnn’ has not been declared
     static Ptr<dnn::Layer> create(dnn::LayerParams &params)
                                   ^~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:118:53: error: ‘params’ was not declared in this scope
     static Ptr<dnn::Layer> create(dnn::LayerParams &params)
                                                     ^~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:118:53: note: suggested alternative: ‘_frame’
     static Ptr<dnn::Layer> create(dnn::LayerParams &params)
                                                     ^~~~~~
                                                     _frame
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:128:5: error: ‘virtual’ outside class declaration
     virtual bool getMemoryShapes(const std::vector<std::vector<int> > &inputs,
     ^~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/types_c.h:82,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:110:
/home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/cvdef.h:673:23: error: virt-specifiers in ‘getMemoryShapes’ not allowed outside a class definition
 #  define CV_OVERRIDE override
                       ^~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:131:74: note: in expansion of macro ‘CV_OVERRIDE’
                                  std::vector<std::vector<int> > &) const CV_OVERRIDE
                                                                          ^~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/cvdef.h:673:23: error: non-member function ‘bool getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&)’ cannot have cv-qualifier
 #  define CV_OVERRIDE override
                       ^~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:131:74: note: in expansion of macro ‘CV_OVERRIDE’
                                  std::vector<std::vector<int> > &) const CV_OVERRIDE
                                                                          ^~~~~~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:7,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:128:18: warning: no previous declaration for ‘bool getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&)’ [-Wmissing-declarations]
     virtual bool getMemoryShapes(const std::vector<std::vector<int> > &inputs,
                  ^~~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp: In function ‘bool getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&)’:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:140:52: error: ‘o’ was not declared in this scope
         PyObject* res = PyObject_CallMethodObjArgs(o, PyString_FromString("getMemoryShapes"), args, NULL);
                                                    ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp: At global scope:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:149:5: error: ‘virtual’ outside class declaration
     virtual void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays) CV_OVERRIDE
     ^~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/types_c.h:82,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:110:
/home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/cvdef.h:673:23: error: virt-specifiers in ‘forward’ not allowed outside a class definition
 #  define CV_OVERRIDE override
                       ^~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:149:111: note: in expansion of macro ‘CV_OVERRIDE’
     virtual void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays) CV_OVERRIDE
                                                                                                               ^~~~~~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:7,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:149:18: warning: no previous declaration for ‘void forward(cv::InputArrayOfArrays, cv::OutputArrayOfArrays, cv::OutputArrayOfArrays)’ [-Wmissing-declarations]
     virtual void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays) CV_OVERRIDE
                  ^~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp: In function ‘void forward(cv::InputArrayOfArrays, cv::OutputArrayOfArrays, cv::OutputArrayOfArrays)’:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:159:52: error: ‘o’ was not declared in this scope
         PyObject* res = PyObject_CallMethodObjArgs(o, PyString_FromString("forward"), args, NULL);
                                                    ^
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp: At global scope:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:177:1: error: expected unqualified-id before ‘private’
 private:
 ^~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:181:1: error: expected declaration before ‘}’ token
 };
 ^
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp: In instantiation of ‘bool pyopencv_to(PyObject*, T&, const char*) [with T = cv::KeyPoint; PyObject = _object]’:
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1305:24:   required from ‘bool pyopencv_to_generic_vec(PyObject*, std::vector<_Tp>&, ArgInfo) [with _Tp = cv::KeyPoint; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1393:56:   required from here
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:24:105: error: ‘to’ is not a member of ‘PyOpenCV_Converter<cv::KeyPoint, void>’
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
                                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp: In instantiation of ‘PyObject* pyopencv_from(const T&) [with T = cv::KeyPoint; PyObject = _object]’:
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1318:39:   required from ‘PyObject* pyopencv_from_generic_vec(const std::vector<_Tp>&) [with _Tp = cv::KeyPoint; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1398:47:   required from here
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:27:75: error: ‘from’ is not a member of ‘PyOpenCV_Converter<cv::KeyPoint, void>’
 PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter<T>::from(src); }
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp: In instantiation of ‘bool pyopencv_to(PyObject*, T&, const char*) [with T = cv::DMatch; PyObject = _object]’:
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1305:24:   required from ‘bool pyopencv_to_generic_vec(PyObject*, std::vector<_Tp>&, ArgInfo) [with _Tp = cv::DMatch; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1406:56:   required from here
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:24:105: error: ‘to’ is not a member of ‘PyOpenCV_Converter<cv::DMatch, void>’
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
                                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp: In instantiation of ‘PyObject* pyopencv_from(const T&) [with T = cv::DMatch; PyObject = _object]’:
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1318:39:   required from ‘PyObject* pyopencv_from_generic_vec(const std::vector<_Tp>&) [with _Tp = cv::DMatch; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1411:47:   required from here
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:27:75: error: ‘from’ is not a member of ‘PyOpenCV_Converter<cv::DMatch, void>’
 PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter<T>::from(src); }
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp: In instantiation of ‘bool pyopencv_to(PyObject*, T&, const char*) [with T = cv::cuda::GpuMat::Allocator; PyObject = _object]’:
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:554:27:   required from ‘static bool PyOpenCV_Converter<cv::Ptr<_Tp> >::to(PyObject*, cv::Ptr<_Tp>&, const char*) [with T = cv::cuda::GpuMat::Allocator; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:24:105:   required from ‘bool pyopencv_to(PyObject*, T&, const char*) [with T = cv::Ptr<cv::cuda::GpuMat::Allocator>; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/core/misc/python/pyopencv_cuda.hpp:29:1:   required from here
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:24:105: error: ‘to’ is not a member of ‘PyOpenCV_Converter<cv::cuda::GpuMat::Allocator, void>’
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
                                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp: In instantiation of ‘PyObject* pyopencv_from(const T&) [with T = cv::cuda::GpuMat::Allocator; PyObject = _object]’:
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:547:29:   required from ‘static PyObject* PyOpenCV_Converter<cv::Ptr<_Tp> >::from(const cv::Ptr<_Tp>&) [with T = cv::cuda::GpuMat::Allocator; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:27:75:   required from ‘PyObject* pyopencv_from(const T&) [with T = cv::Ptr<cv::cuda::GpuMat::Allocator>; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/core/misc/python/pyopencv_cuda.hpp:35:1:   required from here
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:27:75: error: ‘from’ is not a member of ‘PyOpenCV_Converter<cv::cuda::GpuMat::Allocator, void>’
 PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter<T>::from(src); }
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/arm-linux-gnueabihf/c++/8/bits/c++allocator.h:33,
                 from /usr/include/c++/8/bits/allocator.h:46,
                 from /usr/include/c++/8/string:41,
                 from /usr/include/c++/8/stdexcept:39,
                 from /usr/include/c++/8/array:39,
                 from /home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/cvdef.h:671,
                 from /home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/types_c.h:82,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:110:
/usr/include/c++/8/ext/new_allocator.h: In instantiation of ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = cv::cuda::GpuMat::Allocator; _Args = {}; _Tp = cv::cuda::GpuMat::Allocator]’:
/usr/include/c++/8/bits/alloc_traits.h:475:4:   required from ‘static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = cv::cuda::GpuMat::Allocator; _Args = {}; _Tp = cv::cuda::GpuMat::Allocator; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<cv::cuda::GpuMat::Allocator>]’
/usr/include/c++/8/bits/shared_ptr_base.h:545:39:   required from ‘std::_Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp>::_Sp_counted_ptr_inplace(_Alloc, _Args&& ...) [with _Args = {}; _Tp = cv::cuda::GpuMat::Allocator; _Alloc = std::allocator<cv::cuda::GpuMat::Allocator>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)1]’
/usr/include/c++/8/bits/shared_ptr_base.h:677:16:   required from ‘std::__shared_count<_Lp>::__shared_count(_Tp*&, std::_Sp_alloc_shared_tag<_Alloc>, _Args&& ...) [with _Tp = cv::cuda::GpuMat::Allocator; _Alloc = std::allocator<cv::cuda::GpuMat::Allocator>; _Args = {}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)1]’
/usr/include/c++/8/bits/shared_ptr_base.h:1342:71:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<cv::cuda::GpuMat::Allocator>; _Args = {}; _Tp = cv::cuda::GpuMat::Allocator; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)1]’
/usr/include/c++/8/bits/shared_ptr.h:359:59:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_alloc_shared_tag<_Tp>, _Args&& ...) [with _Alloc = std::allocator<cv::cuda::GpuMat::Allocator>; _Args = {}; _Tp = cv::cuda::GpuMat::Allocator]’
/usr/include/c++/8/bits/shared_ptr.h:705:14:   required from ‘std::shared_ptr<_Tp> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = cv::cuda::GpuMat::Allocator; _Alloc = std::allocator<cv::cuda::GpuMat::Allocator>; _Args = {}]’
/usr/include/c++/8/bits/shared_ptr.h:721:39:   required from ‘std::shared_ptr<_Tp> std::make_shared(_Args&& ...) [with _Tp = cv::cuda::GpuMat::Allocator; _Args = {}]’
/home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/cvstd_wrapper.hpp:141:43:   required from ‘cv::Ptr<_Tp> cv::makePtr(const A1& ...) [with _Tp = cv::cuda::GpuMat::Allocator; A1 = {}]’
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:553:23:   required from ‘static bool PyOpenCV_Converter<cv::Ptr<_Tp> >::to(PyObject*, cv::Ptr<_Tp>&, const char*) [with T = cv::cuda::GpuMat::Allocator; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:24:105:   required from ‘bool pyopencv_to(PyObject*, T&, const char*) [with T = cv::Ptr<cv::cuda::GpuMat::Allocator>; PyObject = _object]’
/home/pi/opencv/opencv-4.1.0/modules/core/misc/python/pyopencv_cuda.hpp:29:1:   required from here
/usr/include/c++/8/ext/new_allocator.h:136:4: error: invalid new-expression of abstract class type ‘cv::cuda::GpuMat::Allocator’
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/pi/opencv/opencv-4.1.0/modules/core/misc/python/pyopencv_cuda.hpp:3,
                 from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:2,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/cuda.hpp:108:24: note:   because the following virtual functions are pure within ‘cv::cuda::GpuMat::Allocator’:
     class CV_EXPORTS_W Allocator
                        ^~~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/cuda.hpp:114:22: note: 	‘virtual bool cv::cuda::GpuMat::Allocator::allocate(cv::cuda::GpuMat*, int, int, size_t)’
         virtual bool allocate(GpuMat* mat, int rows, int cols, size_t elemSize) = 0;
                      ^~~~~~~~
/home/pi/opencv/opencv-4.1.0/modules/core/include/opencv2/core/cuda.hpp:115:22: note: 	‘virtual void cv::cuda::GpuMat::Allocator::free(cv::cuda::GpuMat*)’
         virtual void free(GpuMat* mat) = 0;
                      ^~~~
In file included from /home/pi/opencv/opencv-4.1.0/build/modules/python_bindings_generator/pyopencv_custom_headers.h:7,
                 from /home/pi/opencv/opencv-4.1.0/modules/python/src2/cv2.cpp:1721:
/home/pi/opencv/opencv-4.1.0/modules/dnn/misc/python/pyopencv_dnn.hpp:118:28: warning: ‘create’ defined but not used [-Wunused-variable]
     static Ptr<dnn::Layer> create(dnn::LayerParams &params)
                            ^~~~~~
make[2]: *** [modules/python2/CMakeFiles/opencv_python2.dir/build.make:63: modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:14733: modules/python2/CMakeFiles/opencv_python2.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

Cheers.

@brodwix

This comment has been minimized.

Copy link

brodwix commented Sep 2, 2019

@willprice Thank you so much for your tutorial. I finally got openCV built and working on my Raspberry Pi 3 B after 3 attempts:

Attempt 1: I installed Buster from NOOBS, installed virtualenv (never used it), and followed the steps and got OpenCV working, but the next day, the board somehow failed starting Raspbian (couldn't see the colors splash at booting and both LEDs on the board turned on). I think it's because i forgot to change the swap size before shutting down Raspbian.

Attempt 2: I Installed Buster from NOOBS, installed virtualenv, and followed the steps inside an env. I got the same problem as @oneshell had.

Attempt 3 and solution: I installed Buster from image using Etcher and this time without installing virtualenv, followed steps from @ekouwe and got OpenCV working. :)

and here's a silly question...
is there any way to share a prebuilt OpenCV 4 for download and just type $ sudo make install?

Thanks again!

@muhamedsuhail

This comment has been minimized.

Copy link

muhamedsuhail commented Sep 9, 2019

test.py worked good for python2
but shows the below error for python 3

Traceback (most recent call last):
File "test.py", line 1, in
import numpy as np

Thanks in advance.

@brodwix

This comment has been minimized.

Copy link

brodwix commented Sep 9, 2019

@muhamedsuhail
I found similar problems while using environments such as miniconda or virtualenv. Try to fresh install Raspbian and follow the steps installing on root instead miniconda

@muhamedsuhail

This comment has been minimized.

Copy link

muhamedsuhail commented Sep 10, 2019

@brodwix
Okay i'll try it today. I am using raspbian buster and i can't import opencv .I made some modifications and i can now import numpy,but i can't import cv2.I am able to import cv2 in python2.7 but not in python3

@mephillips-durham

This comment has been minimized.

Copy link

mephillips-durham commented Sep 13, 2019

Why the "sudo apt-get purge -y libreoffice*" in install-deps.sh ?
Is it necessary for OpenCV to work?

@hieunvce

This comment has been minimized.

Copy link

hieunvce commented Sep 14, 2019

Why the "sudo apt-get purge -y libreoffice*" in install-deps.sh ?
Is it necessary for OpenCV to work?

It is optional. Do this will give you more space on MicroSD Card.

@cyysky

This comment has been minimized.

Copy link

cyysky commented Oct 1, 2019

Hi willprice,

Thank you for your script

I had compiled and made a debian package with TBB NEON VFPV3 with OPENGL QT5 rasbian buster 10

https://github.com/cyysky/Raspbian-Buster-10-Pre-built-OpenCV-4.1.1-TBB-NEON-VFPV3

Installation
wget https://github.com/cyysky/Raspbian-Buster-10-Pre-built-OpenCV-4.1.1-TBB-NEON-VFPV3/blob/master/opencv-4.1.1_4.1.1-1_armhf.deb
sudo dpkg -i opencv-4.1.1_4.1.1-1_armhf.deb
sudo apt-get -f install
sudo dpkg -i opencv-4.1.1_4.1.1-1_armhf.deb

yoeyat@hotmail.com email me or left comment if anything

Chong
Fortune Machine Computer

@texasStronger

This comment has been minimized.

Copy link

texasStronger commented Oct 24, 2019

I read to no longer perform this on new versions of raspbian such as buster:
sudo apt-get dist-upgrade -y

@texasStronger

This comment has been minimized.

Copy link

texasStronger commented Oct 25, 2019

RPI version 4 with 1 or 2 GB of memory may want to reduce threads.

MEM=cat /proc/meminfo | awk '/MemTotal:/{ print $2}'

if [[ $RPI_VERSION -ge 4 ] and [$MEM -gt 200000000]]; then
NUM_JOBS=4
else
NUM_JOBS=1 # Earlier versions of the Pi don't have sufficient RAM to support compiling with multiple jobs.
fi

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Oct 25, 2019

This is a good point @texasStronger. I'll update the script to use free to determine threads based on the available memory

@texasStronger

This comment has been minimized.

Copy link

texasStronger commented Oct 25, 2019

This is a good point @texasStronger. I'll update the script to use free to determine threads based on the available memory

Could also use
MEM=free -m | awk /Mem:/'{print $2}'

I am not sure if the results from free or meminfo are more standard.
BTW, the install worked great on both RPI 3B 1GB and RPI 4 4GB. Thanks for your work.

@willprice

This comment has been minimized.

Copy link
Owner Author

willprice commented Nov 5, 2019

@texasStronger, thanks for the tip. I've updated the scripts now to install 4.1.2 and use the memory of the board to decide how many jobs to use.

@skyroam

This comment has been minimized.

Copy link

skyroam commented Nov 15, 2019

Is it compatible with Raspberry pi stretch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.