海思3559A上编译OpenCV4.1.0源码操作步骤

1. 从https://github.com/opencv/opencv/releases 下载opencv源码opencv-4.1.0.zip并解压缩;

2. 修改最顶层的CMakeLists.txt,在第658行加入一条语句如下,fix error: pngstruct.h:30:18: fatal error: zlib.h: No such file or directory #include "zlib.h":

ocv_include_directories(./3rdparty/zlib)

3. 修改3rdparty/libpng/CMakeLists.txt,在文件前加入以下4行语句,fix error: libopencv_imgcodecs.so.4.1.0: undefined reference to png_init_filter_functions_neon等错误:

IF(HISI3559A)
	SET(ARM 1)
	SET(ENABLE_NEON 1)
ENDIF()

4. 脚本build.sh内容如下:

cmake \
	-DCMAKE_BUILD_TYPE=RELEASE \
	-DCMAKE_C_COMPILER=/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-gcc \
	-DCMAKE_CXX_COMPILER=/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-g++ \
	-DBUILD_SHARED_LIBS=ON \
	-DCMAKE_CXX_FLAGS=-fPIC \
	-DCMAKE_C_FLAGS=-fPIC \
	-DCMAKE_EXE_LINKER_FLAGS=-lpthread -lrt -ldl \
	-DENABLE_PIC=ON \
	-DWITH_1394=OFF \
	-DWITH_ARAVIS=OFF \
	-DWITH_ARITH_DEC=ON \
	-DWITH_ARITH_ENC=ON \
	-DWITH_CLP=OFF \
	-DWITH_CUBLAS=OFF \
	-DWITH_CUDA=OFF \
	-DWITH_CUFFT=OFF \
	-DWITH_FFMPEG=ON \
	-DWITH_GSTREAMER=ON \
	-DWITH_GSTREAMER_0_10=OFF \
	-DWITH_HALIDE=OFF \
	-DWITH_HPX=OFF \
	-DWITH_IMGCODEC_HDR=ON \
	-DWITH_IMGCODEC_PXM=ON \
	-DWITH_IMGCODEC_SUNRASTER=ON \
	-DWITH_INF_ENGINE=OFF \
	-DWITH_IPP=OFF \
	-DWITH_ITT=OFF \
	-DWITH_JASPER=ON \
	-DWITH_JPEG=ON \
	-DHISI3559A=1 \
	-DWITH_PNG=ON \
	-DWITH_LAPACK=ON \
	-DWITH_LIBREALSENSE=OFF \
	-DWITH_NVCUVID=OFF \
	-DWITH_OPENCL=OFF \
	-DWITH_OPENCLAMDBLAS=OFF \
	-DWITH_OPENCLAMDFFT=OFF \
	-DWITH_OPENCL_SVM=OFF \
	-DWITH_OPENEXR=OFF \
	-DWITH_OPENGL=OFF \
	-DWITH_OPENMP=OFF \
	-DWITH_OPENNNI=OFF \
	-DWITH_OPENNNI2=OFF \
	-DWITH_OPENVX=OFF \
	-DWITH_PROTOBUF=OFF \
	-DWITH_PTHREADS_PF=ON \
	-DWITH_PVAPI=OFF \
	-DWITH_QT=OFF \
	-DWITH_QUIRC=OFF \
	-DWITH_TBB=OFF \
	-DWITH_TIFF=ON \
	-DWITH_VULKAN=OFF \
	-DWITH_WEBP=ON \
	-DWITH_XIMEA=OFF \
	-DWITH_GTK=OFF \
	-DINSTALL_C_EXAMPLES=ON \
	-DINSTALL_PYTHON_EXAMPLES=OFF \
	-DBUILD_EXAMPLES=ON \
	-DCMAKE_INSTALL_PREFIX=./install \
	..

5. OpenCV根目录下,依次执行如下命令,执行完后会将生成的头文件和动态库存放在build/install目录:

mkdir build
cd build
cp ../build.sh .
./builld.sh
make -j8
make install

6. 将build/bin目录下的example_tutorial_porting_anisotropic_image_segmentation_gapi及动态库拷贝到海思板子上,执行,显示结果一切正常,说明OpenCV编译正常,执行结果如下:

海思3559A上编译OpenCV4.1.0源码操作步骤_第1张图片

注意:

1. 由于海思板子不支持GTK,所以必须添加-DWITH_GTK=OFF项,所以在海思板子上不支持imshow相关函数;

2. 如想减少编译时间,可不编译examples,将-DINSTALL_C_EXAMPLES和-DBUILD_EXAMPLES由ON调整为OFF。

GitHub:http://github.com//fengbingchun/OpenCV_Test

你可能感兴趣的:(OpenCV,HISILICON)