- 作業環境
- "python" は python3.7 を指す。
- パッケージの更新
$ sudo apt update
$ sudo apt upgrade -y
$ sudo reboot
- opencv が必要とするライブラリの install:
libhdf5-dev
libatlas-base-dev
libjasper-dev
libqtgui4
libqt4-test
libwebp-dev
libilmbase-dev
libopenexr-dev
libavcodec-dev
libavformat-dev
libswscale-dev
libharfbuzz-dev
$ sudo apt install -y libhdf5-dev libatlas-base-dev libjasper-dev libqtgui4 \
libqt4-test libwebp-dev libilmbase-dev libopenexr-dev \
libavcodec-dev libavformat-dev libswscale-dev libharfbuzz-dev
以上のファイルは,import cv2 でのつぎのエラーを無くすることになるもの:
$ python
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.local/lib/python3.5/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: liblapack.so.3: cannot open shared object file: No such file or directory
- pip のチェック:
$ ls -la /usr/bin/pip*
-rwxr-xr-x 1 root root 302 Apr 11 2019 /usr/bin/pip
-rwxr-xr-x 1 root root 302 Apr 11 2019 /usr/bin/pip2
-rwxr-xr-x 1 root root 303 Apr 11 2019 /usr/bin/pip3
-rwxr-xr-x 1 root root 42976 Mar 19 22:01 /usr/bin/pipanel
- pip, setuptools の更新
$ sudo pip install -U pip setuptools
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pip
Downloading https://files.pythonhosted.org/packages/fe/ef/
60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/
pip-21.0.1-py3-none-any.whl (1.5MB)
100% |████████████████████████████████| 1.5MB 153kB/s
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/9e/d4/
b99a960314121a003e9f39c61dfde01a1010bb47661e193a7722f7f32d52/
setuptools-54.2.0-py3-none-any.whl (785kB)
100% |████████████████████████████████| 788kB 223kB/s
Installing collected packages: pip, setuptools
Successfully installed pip-21.0.1 setuptools-54.2.0
$ ls -la /usr/local/lib/python3.7/dist-packages
drwxr-sr-x 3 root staff 4096 Apr 7 08:15 _distutils_hack
-rw-r--r-- 1 root staff 152 Apr 7 08:15 distutils-precedence.pth
drwxr-sr-x 6 root staff 4096 Apr 7 08:15 pkg_resources
drwxr-sr-x 7 root staff 4096 Apr 7 08:15 setuptools
drwxr-sr-x 2 root staff 4096 Apr 7 08:15 setuptools-54.2.0.dist-info
‥‥
- opencv-python のインストール
$ sudo pip install opencv-python
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting opencv-python
Downloading https://www.piwheels.org/simple/opencv-python/
opencv_python-4.5.1.48-cp37-cp37m-linux_armv7l.whl (10.5MB)
100% |████████████████████████████████| 10.5MB 24kB/s
Requirement already satisfied: numpy>=1.14.5 in
/usr/lib/python3/dist-packages (from opencv-python) (1.16.2)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.5.1.48
$ ls -la /usr/local/lib/python3.7/dist-packages
drwxr-sr-x 4 root staff 4096 Apr 6 22:38 cv2
drwxr-sr-x 2 root staff 4096 Apr 6 22:38 opencv_python-4.5.1.48.dist-info
‥‥
import cv2 を試す:
$ python
>>> import cv2
(エラー無し)
>>> print(cv2)
(cv2 の所在)
- opencv-contrib-python のインストール (失敗)
$ sudo pip install opencv-contrib-python
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting opencv-contrib-python
Downloading https://files.pythonhosted.org/packages/42/02/
7b2fb0b81266aa3243dd8f392d48db1a206cc9a1856a14228e75c515616e/
opencv-contrib-python-4.5.1.48.tar.gz (148.8MB)
100% |████████████████████████████████| 148.8MB 1.6kB/s
Installing build dependencies ... done
Requirement already satisfied: numpy>=1.14.5 in
/usr/lib/python3/dist-packages (from opencv-contrib-python) (1.16.2)
Building wheels for collected packages: opencv-contrib-python
Running setup.py bdist_wheel for opencv-contrib-python ... |
Download 後の build からは,異常に時間がかかる。
そして,3時間経過したくらいで,フリーズ状態に至る。
Raspberry Pi のスペックの貧弱が理由と考えられる。
|