|
Firefly-RK3399 上编译安装 OpenCV 3
发表于 2017-5-17 14:11:39
浏览:43874
|
回复:11
打印
只看该作者
[复制链接]
楼主
本帖最后由 eevee 于 2017-5-17 14:22 编辑
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
复制代码
参考:Build OpenCV on Firefly-RK3399
|
|