原文转自:http://dev.t-firefly.com/thread-12143-1-1.html
OS:官方固件 Xubuntu 16.04
1) Install
1.1) Required Packages
# compiler ✓ $ sudo apt-get install build-essential # required ✓ $ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev # optional ✓ $ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
1.2) Getting OpenCV Source Code
$ git clone https://github.com/opencv/opencv.git $ cd opencv/ $ git checkout 3.2.0
If use extra modules:
$ git clone https://github.com/opencv/opencv_contrib.git $ cd opencv_contrib/ $ git checkout 3.2.0
1.3) Building OpenCV from Source
$ cd opencv/ $ mkdir build $ cd build/ $ export PY_NAME=$(python -c 'from sys import version_info as v; print("python%d.%d" % v[:2])') $ export PY_NUMPY_DIR=$(python -c 'import os.path, numpy.core; print(os.path.dirname(numpy.core.__file__))') $ cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DPYTHON2_EXECUTABLE=$(which python) -DPYTHON_INCLUDE_DIR=/usr/include/$PY_NAME -DPYTHON_INCLUDE_DIR2=/usr/include/aarch64-linux-gnu/$PY_NAME -DPYTHON_LIBRARY=/usr/lib/aarch64-linux-gnu/lib$PY_NAME.so -DPYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/$PY_NAME/dist-packages/numpy/core/include/ -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules .. $ make -j$(nproc --all) $ sudo make install
2) Examples
2.1) Canny Edge Detection
`canny.py`:
#!/usr/bin/env python import cv2 import numpy as np def main(): img = cv2.imread('../data/messi5.jpg', 0) edges = cv2.Canny(img, 100, 200) cv2.imshow('Original & Edge', np.vstack((img, edges))) cv2.waitKey() cv2.destroyAllWindows() if __name__ == '__main__': main()
3) Appendix
3.1) Install pip
$ python --version Python 2.7.12 $ curl -O https://bootstrap.pypa.io/get-pip.py $ python get-pip.py $ vi ~/.pip/pip.conf [global] format=columns index-url=http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com