hi3559编译opencv4.2.0 并使用
(之后上传编译好的so文件)
下载源码,编译安装
去官方网站下载4.2.0源码
复制,改名
修改最顶层的CMakeLists.txt,在第658行加入一条语句
ocv_include_directories(./3rdparty/zlib)
能解决以下问题:
fix error: pngstruct.h:30:18: fatal error: zlib.h: No such file or directory #include "zlib.h":
修改3rdparty/libpng/CMakeLists.txt,在文件前加入以下4行语句,
IF(HISI3559A)
SET(ARM 1)
SET(ENABLE_NEON 1)
ENDIF()
在/home/haitu/opencv路径(opencv源码路径下)新建hisi_build文件夹,并新建build.sh,chmod 777 ./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 \
..
./build.sh执行,生成Makefile,然后make ,make install
部署
报错:version `CXXABI_1.3.11‘ not found
在ubuntu下找到最高版本的可能能用的libstdc(注意区分,别找你系统的,大概率不能用
sudo find / -name "libstdc++.so.6*"
看他是否有这个版本的包
sudo strings /opt/hisi-linux/x86-arm/aarch64-himix100-linux/aarch64-linux-gnu/lib64/libstdc++.so.6.0.23 |grep CXXABI
板端删除原来连接
rm libstdc++.so.6
建立新的链接
ln libstdc++.so.6 libstdc++.so.6.0.23
测试
测试1
参考https://blog.csdn.net/fengbingchun/article/details/96430706 文章,可以把example_tutorial_porting_anisotropic_image_segmentation_gapi拷贝到板子上,动态链接库文件路径(/home/haitu/opencv/hisi_build/install/lib)拷贝到板端(/lib64)的位置,然后在example_tutorial_porting_anisotropic_image_segmentation_gapi的同级放一个input.jpg,这样就可以输出一个out.jpg
测试2
cv.cpp文件如下:
#include <stdio.h>
#include "opencv2/opencv.hpp"
int main()
{
cv::Mat image = cv::imread("./input.jpg");
//cv::imshow("xxx", image);
//cv::waitKey(40);
printf("image.col=%d image.row=%d \n", image.cols, image.rows);
cv::imwrite("aa.jpg", image);
return 0;
}
makefile 内容如下
CC = aarch64-himix100-linux-g++
DIR = /home/haitu/opencv/hisi_build/install
#TARGETS := opencv_test
LD=-lopencv_highgui -lopencv_features2d -lopencv_flann -lopencv_calib3d -lopencv_objdetect -lopencv_imgcodecs -lopencv_imgproc -lopencv_videoio -lopencv_core -lpthread -lrt -ldl #-lzlib
INCLUDE = -I$(DIR)/include/opencv4 -I/home/haitu/opencv/include/ -I/home/haitu/opencv/3rdparty/zlib/
LIB_PATH = -L$(DIR)/lib
all:cv.cpp
$(CC) $(INCLUDE) $(LIB_PATH) $(LD) cv.cpp -o cv
clean:
rm -f *.o $(TARGETS)
编译成功,运行成功后就正常了
同样需要一个input.jpg在同目录下