Opencv is the royal road when trying to recognize faces with Raspberry Pi. However, when I looked it up, it wasn't straightforward and there seemed to be a trap. Let's clarify the procedure by leaving the version etc. exactly. There will be cases where we want to create the same environment again in the future.
As a result, this page was made almost as it is. Installing OpenCV 3 on Raspberry Pi + Python 3 as easily as possible
rasbian version check
pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.13 (stretch)
Release: 9.13
Codename: stretch
Pre-install the libraries that OpenCV depends on (exactly the same as the reference)
$ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-100
$ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install libjasper-dev
install opencv As of 2021/1/10 The latest is 4.4.0.42. Install by specifying the version for reference. However, there is no 3.4.4, so if you specify 3.4.4, an error will occur and it will tell you which version exists.
$ sudo pip3 install opencv-python==3.4.4
Could not find a version that satisfies the requirement opencv-python==3.4.4(from versions: 3.2.0.6, 3.2.0.7, 3.2.0.8, 3.3.0.9, 3.3.0.10, 3.3.1.11, 3.4.0.12, 3.4.0.13, 3.4.0.14, 3.4.1.15, 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19, 3.4.6.27, 3.4.7.28, 3.4.10.37, 3.4.11.39, 3.4.11.41, 4.0.1.24, 4.1.0.25, 4.1.1.26, 4.3.0.38, 4.4.0.40, 4.4.0.42)
Specify 3.4.4.19 again and install.
$ sudo pip3 install opencv-python==3.4.4.19
I was able to confirm that 3.4.4 was installed. (Although I think you should display 3.4.4.19 here as well)
pi@raspberrypi:~/face $ python3
Python 3.5.3 (default, Nov 18 2020, 21:09:16)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.4'
Operation check (exactly the same as the reference) Now that canny.jpg is generated, it seems that you can use opencv from at least python3.
pi@raspberrypi:~/face $ python3
Python 3.5.3 (default, Nov 18 2020, 21:09:16)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> bgr = cv2.imread('./test.jpg', cv2.IMREAD_COLOR)
>>> gray = cv2.cvtColor(bgr, cv2.COLOR_BGR2GRAY)
>>> canny = cv2.Canny(gray, 200, 50)
>>> cv2.imwrite('./canny.jpg', canny)
True
test.jpg is lena, which is often used in opencv examples. You can see that the conversion to GrayScale was completed.
I haven't tried to see if it works with the latest opencv 4.4.0.42.
Recommended Posts