ラベル インストール の投稿を表示しています。 すべての投稿を表示
ラベル インストール の投稿を表示しています。 すべての投稿を表示

2019年9月15日日曜日

OpenCV インストール

環境は以下です。

windows10
python2.X


Python+OpenCVでカメラキャプチャ
を参考にカメラの画像を表示したかったが、以下のようになりOpenCvの環境がだめ!


ソース参考
import cv2
def capture_camera(mirror=True, size=None):
    """Capture video from camera"""
    # カメラをキャプチャする
    cap = cv2.VideoCapture(0) # 0はカメラのデバイス番号

    while True:
        # retは画像を取得成功フラグ
        ret, frame = cap.read()

        # 鏡のように映るか否か
        if mirror is True:
            frame = frame[:,::-1]

        # フレームをリサイズ
        # sizeは例えば(800, 600)
        if size is not None and len(size) == 2:
            frame = cv2.resize(frame, size)

        # フレームを表示する
        cv2.imshow('camera capture', frame)

        k = cv2.waitKey(1) # 1msec待つ
        if k == 27: # ESCキーで終了
            break

    # キャプチャを解放する
    cap.release()
    cv2.destroyAllWindows()

$ python
>>> capture_camera()




Microsoft Windows [Version 10.0.17763.379]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\user>python
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>> ^D
  File "<stdin>", line 1

以下のエラになった
C:\Users\user>python
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: 指定されたモジュールが見つかりません。
    


https://opencv.org/releases.htmlよりダウンロードして解凍した。

バージョンは、4.0.1(NGなので)と3.4.5
C:\Users\user\Downloads\opencv\build\python\cv2\python-2.7
のcv2.pydを以下に移動した。

C:\Python27\Lib\site-packages


成功した
Microsoft Windows [Version 10.0.17763.864]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\kobay>python
Python 2.7.16 (v2.7.16:413a49145e, Mar  4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>

2019年3月23日土曜日

python3系にwxpythonをインストール (エラーあり-の, 終わらないし)


python3系にwxpythonをインストール


自分は、ServersMan@VPSなので、GUI環境ではない。

バージョン確認
root@localhost:~# cat /etc/issue
Ubuntu 14.04.5 LTS \n \l

64bitです(32bitはi686と表示らしい)
root@localhost:~# arch
x86_64


なので色々と大変だった。
GUI関係がインストールされていないのである、
以下をインストールしたらエラーがなくなった。
GTK+
OpenGL
GStreamer
webkit


python3.6  -m pip install wxpython
で実行したが、なかなか終わらない?
(ループしているようだったが、調べるとかなり時間がかかるらしい「数時間から日レベル」)

途中でキャンセルした。


python3.6  -m pip install wxpython
Collecting wxpython
  Using cached https://files.pythonhosted.org/packages/17/74/7c3ced03c3c76b9f98e4a0edae1801755a7599ebf481c04d9f77dfff17e3/wxPython-4.0.4.tar.gz
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from wxpython) (1.11.0)
Requirement already satisfied: Pillow in /usr/local/lib/python3.6/dist-packages (from wxpython) (5.4.1)
Building wheels for collected packages: wxpython
  Building wheel for wxpython (setup.py) ... /^canceled
Operation cancelled by user

そこで、ネット上のwheel を利用して再インストールしてみた。
https://extras.wxpython.org/wxPython4/extras/
から、linux->gtk3->ubuntu14.04
と自分の必要とするものを探して利用しますよ。


python3.6  -m pip install https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-14.04/wxPython-4.0.2-cp36-cp36m-linux_x86_64.whl
Collecting wxPython==4.0.2 from https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-14.04/wxPython-4.0.2-cp36-cp36m-linux_x86_64.whl
  Downloading https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-14.04/wxPython-4.0.2-cp36-cp36m-linux_x86_64.whl (142.9MB)
    100% |????????????????????????????????| 143.0MB 28kB/s
Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from wxPython==4.0.2) (1.11.0)
Collecting PyPubSub (from wxPython==4.0.2)
  Downloading https://files.pythonhosted.org/packages/1a/41/a0aceb552d8ec63bb1e8223d130f9dd0f736470036d75d708183b104a2cb/Pypubsub-4.0.3-py3-none-any.whl (61kB)
    100% |????????????????????????????????| 61kB 109kB/s
Installing collected packages: PyPubSub, wxPython
Successfully installed PyPubSub-4.0.3 wxPython-4.0.2



間違えた場合は、こんな感じ(like this)
cp35はヴァージョンpyhton3.5でした、自分はpython3.6なので、cp36
その他OSのバージョンなどを注意深く確認する必要がありますね!

wxPython-4.0.0a3.dev3059+4a5c5d9-cp35-cp35m-linux_x86_64.whl is not a supported wheel on this platform.


参考URL
Ubuntu 16.04 に wxPython (Python3用) をインストール
ubuntu16.04のpython3にwxpythonをインストールする