ユーザ用ツール

サイト用ツール


raspberry_pi_4のセットアップ_raspberry_pi_os編

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
raspberry_pi_4のセットアップ_raspberry_pi_os編 [2022/05/27 17:16] – [カーネルのビルド] makotoa67raspberry_pi_4のセットアップ_raspberry_pi_os編 [2022/05/29 19:01] (現在) – [OpenCVのインストール] makotoa67
行 69: 行 69:
 ただし、起動時の詳細なログはなぜかまだ取れていない。WindowsのTeraTermは起動時は取りにくいので、Ubuntu PCのminicomでも試す。 ただし、起動時の詳細なログはなぜかまだ取れていない。WindowsのTeraTermは起動時は取りにくいので、Ubuntu PCのminicomでも試す。
  
 +## OpenCVのインストール
 +
 +[【Python】Raspberry Pi OSにOpenCVをインストール](https://invisiblepotato.com/raspberrypi09/)
 +
 +を参考に、OpenCVをインストール。
 +
 +```
 +$ pip3 install opencv-python
 +Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
 +Collecting opencv-python
 +  Downloading opencv_python-4.5.5.64-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (39.2 MB)
 +     |████████████████████████████████| 39.2 MB 71 kB/s 
 +Requirement already satisfied: numpy>=1.19.3 in /usr/lib/python3/dist-packages (from opencv-python) (1.19.5)
 +Installing collected packages: opencv-python
 +Successfully installed opencv-python-4.5.5.64
 +$ pip3 install numpy --upgrade
 +Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
 +Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (1.19.5)
 +Collecting numpy
 +  Downloading numpy-1.22.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (13.4 MB)
 +     |████████████████████████████████| 13.4 MB 3.8 MB/s 
 +Installing collected packages: numpy
 +  WARNING: The scripts f2py, f2py3 and f2py3.9 are installed in '/home/sirius/.local/bin' which is not on PATH.
 +  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
 +Successfully installed numpy-1.22.4
 +$ sudo apt install libatlas3-base
 +パッケージリストを読み込んでいます... 完了
 +依存関係ツリーを作成しています... 完了        
 +状態情報を読み取っています... 完了        
 +以下のパッケージが自動でインストールされましたが、もう必要とされていません:
 +  libfuse2
 +これを削除するには 'sudo apt autoremove' を利用してください。
 +以下のパッケージが新たにインストールされます:
 +  libatlas3-base
 +アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 1 個。
 +2,278 kB のアーカイブを取得する必要があります。
 +この操作後に追加で 9,160 kB のディスク容量が消費されます。
 +取得:1 http://deb.debian.org/debian bullseye/main arm64 libatlas3-base arm64 3.10.3-10 [2,278 kB]
 +2,278 kB を 0秒 で取得しました (4,986 kB/s)
 +以前に未選択のパッケージ libatlas3-base:arm64 を選択しています。
 +(データベースを読み込んでいます ... 現在 103232 個のファイルとディレクトリがインストールされています。)
 +.../libatlas3-base_3.10.3-10_arm64.deb を展開する準備をしています ...
 +libatlas3-base:arm64 (3.10.3-10) を展開しています...
 +libatlas3-base:arm64 (3.10.3-10) を設定しています ...
 +update-alternatives: /usr/lib/aarch64-linux-gnu/libblas.so.3 (libblas.so.3-aarch64-linux-gnu) を提供するために自動モードで /usr/lib/aarch64-linux-gnu/atlas/libblas.so.3 を使います
 +update-alternatives: /usr/lib/aarch64-linux-gnu/liblapack.so.3 (liblapack.so.3-aarch64-linux-gnu) を提供するために自動モードで /usr/lib/aarch64-linux-gnu/atlas/liblapack.so.3 を使います
 +libc-bin (2.31-13+rpt2+rpi1+deb11u2) のトリガを処理しています ...
 +```
 +
 +上記のやり方でインストールされたOpenCVのバージョンを確認してみた。
 +
 +```
 +$ python3 -c 'import cv2; print(cv2.getBuildInformation())'
 +
 +General configuration for OpenCV 4.5.5 =====================================
 +  Version control:               4.5.5-dirty
 +
 +  Platform:
 +    Timestamp:                   2022-03-04T10:02:17Z
 +    Host:                        Linux 4.9.140-tegra aarch64
 +    CMake:                       3.22.2
 +    CMake generator:             Unix Makefiles
 +    CMake build tool:            /bin/gmake
 +    Configuration:               Release
 +
 +  CPU/HW features:
 +    Baseline:                    NEON FP16
 +
 +  C/C++:
 +    Built as dynamic libs?:      NO
 +    C++ standard:                11
 +    C++ Compiler:                /opt/rh/devtoolset-10/root/usr/bin/c++  (ver 10.2.1)
 +    C++ flags (Release):         -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
 +    C++ flags (Debug):           -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
 +    C Compiler:                  /opt/rh/devtoolset-10/root/usr/bin/cc
 +    C flags (Release):           -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
 +    C flags (Debug):             -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
 +    Linker flags (Release):      -L/root/ffmpeg_build/lib  -Wl,--gc-sections -Wl,--as-needed  
 +    Linker flags (Debug):        -L/root/ffmpeg_build/lib  -Wl,--gc-sections -Wl,--as-needed  
 +    ccache:                      YES
 +    Precompiled headers:         NO
 +    Extra dependencies:          /lib64/libopenblas.so Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test Qt5::Concurrent /lib64/libz.so dl m pthread rt
 +    3rdparty dependencies:       libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf quirc tegra_hal
 +
 +  OpenCV modules:
 +    To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
 +    Disabled:                    world
 +    Disabled by dependency:      -
 +    Unavailable:                 java python2 ts
 +    Applications:                -
 +    Documentation:               NO
 +    Non-free algorithms:         NO
 +
 +  GUI:                           QT5
 +    QT:                          YES (ver 5.15.0 )
 +      QT OpenGL support:         NO
 +    GTK+:                        NO
 +    VTK support:                 NO
 +
 +  Media I/O: 
 +    ZLib:                        /lib64/libz.so (ver 1.2.7)
 +    JPEG:                        libjpeg-turbo (ver 2.1.2-62)
 +    WEBP:                        build (ver encoder: 0x020f)
 +    PNG:                         build (ver 1.6.37)
 +    TIFF:                        build (ver 42 - 4.2.0)
 +    JPEG 2000:                   build (ver 2.4.0)
 +    OpenEXR:                     build (ver 2.3.0)
 +    HDR:                         YES
 +    SUNRASTER:                   YES
 +    PXM:                         YES
 +    PFM:                         YES
 +
 +  Video I/O:
 +    DC1394:                      NO
 +    FFMPEG:                      YES
 +      avcodec:                   YES (58.134.100)
 +      avformat:                  YES (58.76.100)
 +      avutil:                    YES (56.70.100)
 +      swscale:                   YES (5.9.100)
 +      avresample:                NO
 +    GStreamer:                   NO
 +    v4l/v4l2:                    YES (linux/videodev2.h)
 +
 +  Parallel framework:            pthreads
 +
 +  Trace:                         YES (with Intel ITT)
 +
 +  Other third-party libraries:
 +    Lapack:                      YES (/lib64/libopenblas.so)
 +    Eigen:                       NO
 +    Custom HAL:                  YES (carotene (ver 0.0.1))
 +    Protobuf:                    build (3.19.1)
 +
 +  OpenCL:                        YES (no extra features)
 +    Include path:                /io/opencv/3rdparty/include/opencl/1.2
 +    Link libraries:              Dynamic load
 +
 +  Python 3:
 +    Interpreter:                 /opt/python/cp36-cp36m/bin/python3.6 (ver 3.6.15)
 +    Libraries:                   libpython3.6m.a (ver 3.6.15)
 +    numpy:                       /opt/python/cp36-cp36m/lib/python3.6/site-packages/numpy/core/include (ver 1.19.3)
 +    install path:                python/cv2/python-3
 +
 +  Python (for build):            /bin/python2.7
 +
 +  Java:                          
 +    ant:                         NO
 +    JNI:                         NO
 +    Java wrappers:               NO
 +    Java tests:                  NO
 +
 +  Install to:                    /io/_skbuild/linux-aarch64-3.6/cmake-install
 +-----------------------------------------------------------------
 +```
 +
 +この後は、
 +
 +[カメラモジュールを使ってOpenCVでキャプチャする](https://zenn.dev/kotaproj/books/raspberrypi-tips/viewer/400_kiso_camera)
 +
 +を参考に。レガシーカメラスタックを有効にすると、こちらの世界は動作するが、libcamera-helloなどは動作しなくなる。
 +
 +```
 +$ libcamera-hello -t 0 --rotation 180
 +ERROR: the system appears to be configured for the legacy camera stack
 +```
 +
 +C++向けのOpenCV環境も作りたいが、パッケージ化されていない?ひとまず、ソースからビルドする案内をしているページを載せておく。
 +
 +[OpenCV + OpenCV Contribをビルド 【Raspberry Pi OS編】](https://swallow-incubate.com/archives/blog/20200709/)
 +
 +opencv-pythonでインストールされたバージョン(4.5.5)に合わせて、基本的に、上記サイトを参考にしてダウンロードして展開。
 +
 +```
 +$ sudo apt update
 +$ sudo apt upgrade
 +$ sudo apt install cmake libgtk2.0-dev libjpeg-dev libpng-dev
 +$ wget https://github.com/opencv/opencv/archive/4.5.5.tar.gz -O opencv.tar.gz
 +$ wget https://github.com/opencv/opencv_contrib/archive/4.5.5.tar.gz -O opencv_contrib.tar.gz
 +$ gzip -d -c opencv.tar.gz |tar xvf -
 +$ gzip -d -c opencv_contrib.tar.gz |tar xvf -
 +```
 +
 +カーネルをビルドしたときに熱で落ちたりしたことがあるので、一応、
 +
 +```
 +#!/bin/sh
 +
 +while true
 +do
 +    echo temparature: `cat /sys/class/thermal/thermal_zone0/temp`
 +    sleep 1
 +done
 +```
 +
 +などというスクリプトで温度をモニタリングしながら、以下でビルド。
 +
 +```
 +$ cd opencv-4.5.5
 +$ mkdir build
 +$ cd build
 +$ cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.5.5/modules ..
 +$ make -j4
 +$ sudo make install
 +$ sudo ldconfig
 +```
raspberry_pi_4のセットアップ_raspberry_pi_os編.1653639416.txt.gz · 最終更新: 2022/05/27 17:16 by makotoa67