前段时间移植opencv到nanopi成功了,当时没有记录一下,几个月之后项目需要发现已经忘的差不多了,果然好记性不如烂笔头:(,写的有点乱 记录一下吧
准备工作
主机环境搭建
略
需要的软件包
移植Python3
移植python前先安装同样的版本到主机(很重要)
移植opencv 3.4.0
环境变量设置
export WX_HOST=arm-cortexa9-linux-gnueabihf
export WX_CROSS_PREFIX=arm-cortexa9-linux-gnueabihf-
export NANOPI_LOCAL=/home/lipingsheng/nanopi/local
export CC=arm-cortexa9-linux-gnueabihf-gcc
export ARCH=arm
jpeg-8d
先解压 然后进入jpeg-8d解压后的文件夹内部
tar -zxvf jpegsrc.v8d.tar.gz
cd jpeg-8d
./configure --prefix=$NANOPI_LOCAL --host=$WX_HOST --enable-shared
make && make install
libpng
同样是先解压软件包
tar -zxvf libpng-1.2.59.tar.gz
cd libpng-1.2.59
./configure --prefix=$NANOPI_LOCAL --host=$WX_HOST LDFLAGS=-L$NANOPI_LOCAL/lib CFLAGS=-I$NANOPI_LOCAL/include
make && make install
x264
tar -jxvf x264-snapshot-20171215-2245.tar.bz2
cd x264
./configure --host=$WX_HOST --cross-prefix=$WX_CROSS_PREFIX --enable-shared --prefix=$NANOPI_LOCAL
make && make install
xvidcore 1.3.2
解压什么的往下就略过了
cd xvidcore 1.3.2
./configure --prefix=$NANOPI_LOCAL --host=$WX_HOST --disable-assembly
make && make install
tiff
./configure --prefix=$NANOPI_LOCAL --host=$WX_HOST --enable-shared LDFLAGS=-L$NANOPI_LOCAL/lib CFLAGS=-I$NANOPI_LOCAL/include
make && make install
ffmpeg-3.4.1
./configure --prefix=$NANOPI_LOCAL \
--enable-shared \
--disable-static \
--enable-gpl \
--enable-cross-compile \
--arch=arm \
--disable-stripping \
--target-os=linux \
--enable-libx264 \
--enable-libxvid \
--cc=$CC \
--enable-swscale \
--extra-cflags=-I$NANOPI_LOCAL/include \
--extra-ldflags=-L$NANOPI_LOCAL/lib \
--disable-asm \
--pkgconfigdir=$NANOPI_LOCAL/lib/pkgconfig
make && make install
opencv 3.4
在opencv根目录创建toolchain.make
vim toolchain.make
在文件中添加以下内容
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER arm-cortexa9-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-cortexa9-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH "/home/lipingsheng/nanopi/local")
set(CMAKE_C_FLAGS "-Wl,-rpath-link=/home/lipingsheng/nanopi/local/lib")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
在opencv根目录创建build文件夹 用来存放cmake的过程以及结果文件
mkdir build
进到build目录 并且配置cmake 选择自己需要的opencv模块
cd build
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D OPENCV_EXTRA_MODULES_PATH=/home/lipingsheng/nanopi/opencv/opencv_contrib-3.4.0/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF \
-D CMAKE_TOOLCHAIN_FILE=../toolchain.make \
-D CMAKE_INSTALL_PREFIX=/home/lipingsheng/nanopi/local \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_opencv_python2=OFF \
\
-D BUILD_opencv_python3=ON \
-D PYTHON3_EXECUTABLE=/usr/local/bin/python3 \
-D PYTHON3_INCLUDE_DIR=/home/lipingsheng/nanopi/local/include/python3.6m \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/home/lipingsheng/nanopi/local/lib/python3.6/site-packages/numpy/core/include \
-D PYTHON3_PACKAGES_PATH=/home/lipingsheng/nanopi/local/lib/python3.6/site-packages \
-D PYTHON3_LIBRARIES=/home/lipingsheng/nanopi/local/lib/libpython3.6m.so \
-D PYTHON3_INCLUDE_PATH=/home/lipingsheng/nanopi/local/include/python3.6m \
\
-D BUILD_opencv_highgui=OFF \
-D BUILD_opencv_gpu=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_opencv_apps=OFF \
-D BUILD_opencv_calib3d=OFF \
-D BUILD_opencv_contrib=OFF \
-D BUILD_opencv_features2d=OFF \
-D BUILD_opencv_flann=OFF \
-D BUILD_opencv_ml=OFF \
-D BUILD_opencv_nonfree=OFF \
-D BUILD_opencv_objdetect=OFF \
-D BUILD_opencv_photo=OFF \
-D BUILD_opencv_stitching=OFF \
-D BUILD_opencv_superres=OFF \
-D BUILD_opencv_ts=OFF \
-D BUILD_opencv_video=OFF \
-D BUILD_opencv_videostab=OFF \
..
然后就可以make了
make -j4
make install
特别提醒
- 还没写完 缺少的以后再补充
- 方法总比困难多
- 如果有疑问 欢迎和我交流