1. 程式人生 > >樹莓派zero對圖片進行邊緣識別變換所需環境

樹莓派zero對圖片進行邊緣識別變換所需環境

所需環境

通過pip3安裝的。
sudo pip3 install opencv-python imutils numpy scipy
通過系統自帶環境apt-get安裝的。
sudo apt-get install libatlas-base-dev  libjasper-dev
sudo apt-get install libgstreamer1.0-0
sudo apt-get install libgstreamer-plugins-base1.0-0
sudo apt-get install libqtgui4 python3-pyqt5 libqt4-test

下面是安裝之後包的路徑位置和安裝過程中遇到bug的解決過程。

>>> import scipy
>>> scipy
<module 'scipy' from '/usr/local/lib/python3.5/dist-packages/scipy/__init__.py'>
>>> import imutils
>>> imutils
<module 'imutils' from '/usr/local/lib/python3.5/dist-packages/imutils/__init__.py'>
>>> import cv2
>>> cv2
<module 'cv2.cv2' from '/usr/local/lib/python3.5/dist-packages/cv2/cv2.cpython-35m-arm-linux-gnueabihf.so'>
>>> import numpy
>>> numpy
<module 'numpy' from '/usr/local/lib/python3.5/dist-packages/numpy/__init__.py'>
>>> import skimage.filters
>>> import PIL
>>> PIL
<module 'PIL' from '/usr/local/lib/python3.5/dist-packages/PIL/__init__.py'>

在樹莓派上使用sudo apt install python3-pip安裝pip的時候,出現cannot import name 'main’報錯,這個時候通過修改/usr/bin/pip3來解決。

from pip import __main__

if __name__ == '__main__':
    sys.exit(__main__._main())

安裝python opencv包的時候,sudo apt install python-opencv會安裝到python2裡面,python3安裝opencv的方式較複雜,需要安裝的包見 上面通過系統自帶環境apt-get安裝。

python imutils 這個包,在resize操作的時候,會觸發Illegal instruction 這裡是這個包的問題,詳情見參考1.解決辦法自己重寫imutils.resize方法。

def resize(image, width=None, height=None):
    dim = None
    (h, w) = image.shape[:2]
    if width is None and height is None:
        return image
    if width is None:
        r = height / float(h)
        dim = (int(w * r), height)
    else:
        r = width / float(w)
        dim = (width, int(h * r))
    resized = cv2.resize(image, dim, cv2.INTER_AREA)
    return resized

參考: