Anyway, I want to install OpenCV safely, so I installed it by the official method. https://docs.opencv.org/master/d2/de6/tutorial_py_setup_in_ubuntu.html
Raspberry Pi 3 B+
OS
$ cat /etc/debian_version
10.7
$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
$ sudo apt-get install python-opencv
Actually, this is all it takes.
>>> import cv2
>>> print(cv2.__version__)
4.5.1-dev
Installation was successful with Python2.
However, with Python3,
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2’
>>>
I can't find it.
I can't find the cv2.so file when I try to pass it, so I will try to build from the source.
Building OpenCV from source
First, install them as needed for the build.
sudo apt-get install cmake
sudo apt-get install gcc g++
I want both Python2 and 3
sudo apt-get install python-dev python-numpy
sudo apt-get install python3-dev python3-numpy
Install GTK related What is GTK? .. .. → It seems to be used when making a GUI application.
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libgtk-3-dev
For the time being, it seems that you can build up to this point. The next one seems to just update the package in reserve.
sudo apt-get install libpng-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libopenexr-dev
sudo apt-get install libtiff-dev
sudo apt-get install libwebp-dev
Download it from Git.
$ sudo apt-get install git
$ git clone https://github.com/opencv/opencv.git
It was long. Create a build directory. The name is build for the time being
$ cd opencv
$ mkdir build
$ cd build
Next is the installation.
cmake ../
It is near the end of the output.
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.16)
-- Libraries: /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.16)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.2)
-- install path: lib/python2.7/dist-packages/cv2/python-2.7
--
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.7.3)
-- Libraries: /usr/lib/arm-linux-gnueabihf/libpython3.7m.so (ver 3.7.3)
-- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.16.2)
-- install path: lib/python3.7/dist-packages/cv2/python-3.7
It's convenient to be able to configure the installation with just this. I will study again what is happening.
Finally, build and install.
$ make
# sudo make install
It took a lot of time. About 5 hours I don't want to do it anymore! !! !! !! !! !! !!
$ python3
>>> import cv2
>>> print(cv2.__version__)
4.5.1-dev
did it!
I've done it properly, so I've updated OpenCV to the latest dev version. It's ** super annoying ** because I have to build again to change the version.
Recommended Posts