質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Raspbian

Raspbianは、DebianベースのRaspberry Pi用ディストリビューション。ハードウェア浮動小数点演算を有効にすることが可能で、Webブラウズなどの速度を向上できます。

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

1793閲覧

ラズベリーパイにOpenCVをインストールしたいのですが、、、

nobita

総合スコア66

Raspbian

Raspbianは、DebianベースのRaspberry Pi用ディストリビューション。ハードウェア浮動小数点演算を有効にすることが可能で、Webブラウズなどの速度を向上できます。

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/09/27 11:11

ラズベリーパイ初心者です。
ラズベリーパイで OpenCVを使って画像認識を実施したいのですが、

コンソールで、下記のように install しても usr/local/python/cv2/python-2.7 の中に .so ファイルができるだけであって。
本来は python3 で実施したいのですが、 python2系でしか出来上がりません。
ラズベリーパイの中には、 Python2 と python3 が入っています。 python3.6 です。

なにがいけないのでしょうか?

$ sudo raspi-config $ df -h $ sudo apt-get update $ sudo apt-get upgrade $ sudo rpi-update $ sudo reboot now $ sudo nano /etc/dphys-swapfile $ sudo /etc/init.d/dphys-swapfile stop $ sudo /etc/init.d/dphys-swapfile start $ free -m $ sudo apt-get install build-essential cmake pkg-config $ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev $ sudo apt-get install libavcodec-dev libavformat-dev libswscaledev libv4l-dev $ sudo apt-get install libxvidcore-dev libx264-dev $ sudo apt-get install libgtk2.0-dev libgtk-3-dev $ sudo apt-get install libatlas-base-dev gfortran $ sudo apt-get install python2.7-dev python3-dev $ cd $ mkdir workspace $ cd workspace $ wget -O opencv.zip https://github.com/opencv/opencv/archive/3.4.4.zip $ unzip opencv.zip $ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.4.zip $ unzip opencv_contrib.zip $ cd opencv-3.4.4/ $ mkdir build $ cd build $ cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/workspace/opencv_contrib-3.4.4/modules \ -D BUILD_EXAMPLES=ON \ -D ENABLE_NEON=ON .. $ sudo make -j4 $ sudo make install $ sudo ldconfig

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mt08

2019/09/28 04:56

cmake 実行時のログに、イントールされる場所とか、出てると思います。貼り付けてもらえますか? あと、使用環境によっても変わってくるので、どのOSイメージベースで、どのような変更を加えた環境なのかも書かれたほうが、アドバイスがもらいやすいと思います。 # Raspbianの標準環境で使えるdebパッケージなら作ってるんですけど...( https://qiita.com/mt08/items/e8e8e728cf106ac83218 )
nobita

2019/09/28 07:04

回答ありがとうございます。 仕事が終わって家に帰ったらサイド実行して貼り付けます! また、OSは Rasbian です!
nobita

2019/09/28 12:55

``` General configuration for OpenCV 3.4.4 ===================================== -- Version control: unknown -- -- Extra modules: -- Location (extra): /home/pi/workspace/opencv_contrib-3.4.4/modules -- Version control (extra): unknown -- -- Platform: -- Timestamp: 2019-09-27T02:25:29Z -- Host: Linux 4.19.71-v7+ armv7l -- CMake: 3.13.4 -- CMake generator: Unix Makefiles -- CMake build tool: /usr/bin/make -- Configuration: RELEASE -- -- CPU/HW features: -- Baseline: NEON -- requested: DETECT -- required: NEON -- disabled: VFPV3 -- -- C/C++: -- Built as dynamic libs?: YES -- C++11: YES -- C++ Compiler: /usr/bin/c++ (ver 8.3.0) -- C++ flags (Release): -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 -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG -- C++ flags (Debug): -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 -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG -- C Compiler: /usr/bin/cc -- C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -mfp16-format=ieee -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG -- C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -mfp16-format=ieee -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG -- Linker flags (Release): -- Linker flags (Debug): -- ccache: NO -- Precompiled headers: YES -- Extra dependencies: dl m pthread rt -- 3rdparty dependencies: -- -- OpenCV modules: -- To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy hdf hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto -- Disabled: world -- Disabled by dependency: - -- Unavailable: cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv java js matlab ovis python3 sfm viz -- Applications: tests perf_tests examples apps -- Documentation: NO -- Non-free algorithms: NO -- -- GUI: -- GTK+: YES (ver 3.24.5) -- GThread : YES (ver 2.58.3) -- GtkGlExt: NO -- VTK support: NO -- -- Media I/O: -- ZLib: /usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.11) -- JPEG: /usr/lib/arm-linux-gnueabihf/libjpeg.so (ver 62) -- WEBP: build (ver encoder: 0x020e) -- PNG: /usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.6.36) -- TIFF: /usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 / 4.0.10) -- JPEG 2000: /usr/lib/arm-linux-gnueabihf/libjasper.so (ver 1.900.1) -- OpenEXR: build (ver 1.7.1) -- HDR: YES -- SUNRASTER: YES -- PXM: YES -- -- Video I/O: -- DC1394: NO -- FFMPEG: YES -- avcodec: YES (ver 58.35.100) -- avformat: YES (ver 58.20.100) -- avutil: YES (ver 56.22.100) -- swscale: YES (ver 5.3.100) -- avresample: NO -- GStreamer: NO -- libv4l/libv4l2: NO -- v4l/v4l2: linux/videodev2.h -- -- Parallel framework: pthreads -- -- Trace: YES (built-in) -- -- Other third-party libraries: -- Lapack: NO -- Eigen: NO -- Custom HAL: YES (carotene (ver 0.0.1)) -- Protobuf: build (3.5.1) -- -- OpenCL: YES (no extra features) -- Include path: /home/pi/workspace/opencv-3.4.4/3rdparty/include/opencl/1.2 -- Link libraries: Dynamic load -- -- Python 2: -- Interpreter: /usr/bin/python2.7 (ver 2.7.16) -- Libraries: /usr/lib/arm-linux-gnueabihf/libpython2.7.so (ver 2.7.16) -- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.16.2) -- packages path: lib/python2.7/dist-packages -- -- Python 3: -- Interpreter: /usr/local/bin/python3 (ver 3.6.6) -- Libraries: NO -- numpy: NO (Python3 wrappers can not be generated) -- packages path: lib/python3.6/site-packages -- -- Python (for build): /usr/bin/python2.7 -- -- Java: -- ant: /usr/bin/ant (ver 1.10.5) -- JNI: NO -- Java wrappers: NO -- Java tests: NO -- -- Install to: /usr/local -- ----------------------------------------------------------------- -- -- Configuring done ```
nobita

2019/09/28 12:56

cmake 実行時のログ はこんな感じです。。
guest

回答2

0

ベストアンサー

nobitaさん、

ログ見ると、

... -- Python 3: -- Interpreter: /usr/local/bin/python3 (ver 3.6.6) -- Libraries: NO -- numpy: NO (Python3 wrappers can not be generated) -- packages path: lib/python3.6/site-packages ...

"Libraries: NO" と "numpy: NO"となってるので、
libpython3.6m.so(?)が見つからない、あと、python3.6へのnumpyのインストールがされてないので、その対応が必要っぽいです。

ところで、Python 3.6は、自前でビルドしたものでしょうか。
そういった環境では、確認したことないので、参考になるかわかりませんが、わたしが、Raspbian Stretchの標準付属のPython2.7/3.5.3、numpyなどもaptでインストールした環境でにビルドしたときの手順やログは、こんな感じでした。
https://github.com/mt08xx/files/commit/8061a260427b3d7b92db2ea8f791525d30a1376e

投稿2019/09/29 02:02

mt08

総合スコア1825

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

cmakeの時に-D BUILD_opencv_python3=ONオプションを追加してみてはどうでしょう?

あるいは、sudo pip3 install opencv-pythonを使うのが一つの手です。

投稿2019/09/27 12:09

fukatani

総合スコア626

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nobita

2019/09/27 12:13

回答ありがとうございます。 sudo pip3 install opencv-python を実行したら。。。
nobita

2019/09/27 12:14

``` pi@raspberrypi:~ $ sudo pip3 install opencv-python Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting opencv-python ERROR: Could not find a version that satisfies the requirement opencv-python (from versions: none) ERROR: No matching distribution found for opencv-python pi@raspberrypi:~ $ ```
nobita

2019/09/27 12:14

となりました。、、 バージョンが合ってないんでしょうか?
nobita

2019/09/27 12:47

参考にして brew がまず使えないので、Homebrew をインストールしようと実行しているのですが、 エラーがでますね。。。。。
nobita

2019/09/27 12:49

Warning: /home/linuxbrew/.linuxbrew/bin is not in your PATH.
fukatani

2019/09/27 12:52

思ったより大変ですね、すいません。初心に帰って`-D BUILD_opencv_python3=ON`オプションつけてビルドをやり直したほうがいいかもです。 pyenvでPython3.5に入れるのが相対的には楽でしょうが、ハマりやすいです。 Python3.5を使っているつもりが3.6になってたり。 一応やり方はあります↓ https://qiita.com/ysdyt/items/f232e6481b44f92276cf rasberry y
nobita

2019/09/27 13:04

ありがとうございます ビルド を時間をみてやってみます! いままで、install していたcv2などは そのままでいいのでしょうか? アンインストール等した方がいいのですか? 削除
nobita

2019/09/27 13:44

cmake -D CMAKE_BUILD_TYPE=RELEASE \ > -D BUILD_opencv_python3=ON\ > -D CMAKE_INSTALL_PREFIX=/usr/local \ > -D INSTALL_C_EXAMPLES=OFF \ > -D INSTALL_PYTHON_EXAMPLES=ON \ > -D OPENCV_EXTRA_MODULES_PATH=~/workspace/opencv_contrib-3.4.4/modules \ > -D BUILD_EXAMPLES=ON \ > -D ENABLE_NEON=ON ..
nobita

2019/09/27 13:44

とすれべいいんでしょうか?
fukatani

2019/09/27 13:53

sudo make installした場所で、sudo make uninstallすればアンインストールできますが、まずはそのままやってみてください。 オプションはそれで合っていると思います。 Python2にcv2が入っていてもそれ自体は問題ありません。
nobita

2019/09/27 21:29

夜中に インストールして 朝 確認してみたのですが、 python2.7 しかなかったです。。。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問