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
[email protected]:~ $ 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 18.104.22.168. 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: 22.214.171.124, 126.96.36.199, 188.8.131.52, 184.108.40.206, 220.127.116.11, 18.104.22.168, 22.214.171.124, 126.96.36.199, 188.8.131.52, 184.108.40.206, 220.127.116.11, 18.104.22.168, 22.214.171.124, 126.96.36.199, 188.8.131.52, 184.108.40.206, 220.127.116.11, 18.104.22.168, 22.214.171.124, 126.96.36.199, 188.8.131.52, 184.108.40.206, 220.127.116.11, 18.104.22.168, 22.214.171.124)
Specify 126.96.36.199 again and install.
$ sudo pip3 install opencv-python==188.8.131.52
I was able to confirm that 3.4.4 was installed. (Although I think you should display 184.108.40.206 here as well)
[email protected]:~/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.
[email protected]:~/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 220.127.116.11.