LoginSignup
4
3

More than 3 years have passed since last update.

Raspberry Piに構築したOpenCVのエラー解消法

Last updated at Posted at 2020-02-12

初めに

こちらを参考にRaspberry PiにOpenCVをインストールしたところ、Python3でエラーが出てOpenCVがインポートできませんでした。いろいろ調べて解決したので、その方法を記載します。

環境

Raspberry Pi 3 B+
Python 3
OpenCV 4.1.1

エラー内容と解決法 

その1

最初に出たエラーメッセージはこちらです。

>>import cv2
ImportError: libhdf5_serial.so.103: cannot open shared object file: No such file or directory

libhdf5_serial.soがないみたいなので、必要なパッケージをインストールします。

$ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-100

その2

次に出たエラーメッセージがこちらです。

>>import cv2
ImportError: /usr/lib/arm-linux-gnueabihf/neon/vfp/libavcodec.so.58: undefined symbol: bcm_host_is_fkms_active

bcm_host_is_fkms_active がfirmwareに追加されったっぽいので、kernelとfirmwareを最新にします。

sudo apt update && sudo apt upgrade

その3

最後に出たエラーがこちらです。

>>> import cv2
ImportError: /home/pi/cv2/cv2.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: __atomic_

こちらのサイトを参考に次のコマンドを実行しました。

$ LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1

vimで.bashrcファイルを編集します。

$ vim.tiny .bashrc

export LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1 #文末にこの一文を追加

動作確認

$ python3
>>> import cv2
>>> 
>>> cv2.__version__
>>> '4.1.1'

何も表示されなくなったので無事OpenCVが読み込まれました\^^/
念のためバージョンを確認しています。
これでRaspberry piでPythonとOpenCVを使えるようになれたら嬉しいです。

参考サイト

https://github.com/raspberrypi/firmware/issues/1319
https://qiita.com/XM03/items/48463fd910470b226f22

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3