搭建hi3516的docker开发环境
1. 运行一个ubuntu 18.04的docker容器
docker run -itd --name hi3516 -v host_path:/root/work --privileged=true --shm-size 4G ubuntu:18.04 /bin/bash
docker exec -it hi3516 /bin/bash
2. 在docker容器中更新仓库源,安装开发环境
cp /etc/apt/sources.list /etc/apt/sources.list.bak
sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
apt update
apt-get install vim lib32z1 lib32ncurses5
3. 从海思开发包中拷贝交叉编译工具链,并安装
tar zxvf arm-himix410-linux.tgz
cd arm-himix410-linux
source ./arm-himix410-linux.install
source /etc/profile
vim ~/.bashrc
export PATH="/opt/hisi-linux/x86-arm/arm-himix410-linux/bin:$PATH"
4. 测试交叉编译工具链
vim hello.c
#include <stdio.h>
int main(int argc, char **argv)
{
printf("hello world!\n");
return 0;
}
arm-himix410-linux-gcc -o hello.out hello.c
参考地址:
https://blog.csdn.net/u013470224/article/details/50696827
https://blog.csdn.net/u010164190/article/details/89322488
5. 编译OpenCV 4.6.0
5.1 到https://opencv.org/releases/下载,并解压opencv 4.6.0
unzip opencv-4.6.0.zip
cd opencv-4.6.0
5.2 安装基础依赖包
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
5.3 编写编译脚本
vim build.sh
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
BuildDir=.../opencv-4.6.0/build
ToolChain=/opt/hisi-linux/x86-arm/arm-himix410-linux
if [ ! -d "$BuildDir" ]; then
# Take action if $BuildDir doesn‘t exists.
echo "create ${BuildDir}..."
mkdir -p ${BuildDir}
fi
cd ${BuildDir}
echo "building OpenCV4"
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_SHARED_LIBS=OFF \
-D CMAKE_FIND_ROOT_PATH=${ToolChain}/ \
-D CMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake \
-D CMAKE_C_COMPILER=${ToolChain}/bin/arm-himix410-linux-gcc \
-D CMAKE_CXX_COMPILER=${ToolChain}/bin/arm-himix410-linux-g++ \
-D CMAKE_C_FLAGS="-mfloat-abi=softfp -mfpu=neon" \
-D CMAKE_CXX_FLAGS="-mfloat-abi=softfp -mfpu=neon" \
-D CMAKE_INSTALL_PREFIX=${BuildDir}/install \
-D WITH_TBB=ON \
-D WITH_EIGEN=ON \
-D BUILD_ZLIB=ON \
-D BUILD_TIFF=ON \
-D BUILD_JASPER=ON \
-D BUILD_JPEG=ON \
-D BUILD_PNG=ON \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D WITH_LIBV4L=ON \
-D BUILD_opencv_python=OFF \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_DOCS=OFF \
-D WITH_OPENCL=OFF \
-D WITH_1394=OFF \
..
make -j$(nproc)
5.4 编译安装OpenCV
sh build.sh
make install
cd opencv-4.6.0/build/install
5.5 编写测试程序
vim hello.cpp
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv)
{
if ( argc != 2 ) {
printf("usage: test.out <image_Path>\n");
return -1;
}
Mat image = imread(argv[1]);
if (image.empty()) {
printf("Reading image fails.\n");
return -1;
}
Mat gray;
cvtColor(image, gray, COLOR_BGR2GRAY);
imwrite("gray.jpg", gray);
printf("Writing gray image success.\n");
return 0;
}
5.6编写cmake文件
vim CMakeLists.txt
# 设置目标工程名称
project(HELLO)
# 设置生成文件名称
set(TARGET hello)
# 设置编译最小版本
cmake_minimum_required(VERSION 3.10)
# 设置目标平台系统
set(CMAKE_SYSTEM_NAME Linux)
# 设置交叉编译路径
set(CMAKE_FIND_ROOT_PATH /opt/hisi-linux/x86-arm/arm-himix410-linux/bin)
# 设置交叉编译工具
set(CMAKE_C_COMPILER arm-himix410-linux-gcc)
set(CMAKE_CXX_COMPILER arm-himix410-linux-g++)
# 设置库的目录路径
set(OpenCV_DIR .../opencv-4.6.0/build)
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# 添加编译文件目录
aux_source_directory(${PROJECT_SOURCE_DIR} USRSRC)
# 添加生成执行文件
add_executable(${TARGET} ${USRSRC})
# 执行生成文件链接
TARGET_LINK_LIBRARIES(${TARGET} ${OpenCV_LIBS})
5.7编译测试文件
rm -rf build && mkdir build && cd build && cmake .. && make
5.8拷贝生成文件到开发版
相关参考:
https://blog.csdn.net/weixin_40918067/article/details/117866635
https://blog.csdn.net/qq_24994587/article/details/125186273
http://cn.voidcc.com/question/p-wxfryuxv-ve.html
https://www.jianshu.com/p/e3f9d5330f6a
https://blog.csdn.net/sinat_31608641/article/details/121713191
https://blog.csdn.net/weixin_42398658/article/details/121701995
https://www.cnblogs.com/BlueBlueSea/p/16632851.html
https://blog.csdn.net/qq_38410730/article/details/102837401
https://www.jianshu.com/p/89fb01752d6f