opencv arm交叉编译与仿真验证详细流程

Posted I_am_Damon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv arm交叉编译与仿真验证详细流程相关的知识,希望对你有一定的参考价值。

【关键内容】

1.将opencv编译为能在arm上运行的库

2.在没有板子的情况下,仿真验证opencv库

1.将opencv编译为能在arm上运行的库

1.在下方链接中选择某个版本

Releases - OpenCVhttps://opencv.org/releases/点击“Sources”即可开始下载,得到opencv-3.4.1.zip:

2.解压,得到opencv-3.4.1到/home/ubuntu/opencv/opencv-3.4.1/

unzip opencv-3.4.1.zip

3.打开cmake-gui:

cd opencv-3.4.1
mkdir build
cd build
cmake-gui&

4.

where is the source code:刚下载解压后的opencv-3.4.1的路径

where to build the binaries:刚下载解压后的opencv-3.4.1的路径中的build

然后点击Configure

5.Operation System必须为Linux,Processor必须为arm

Compilers的C为自己PC/服务器中的C交叉编译工具链所在位置

Compilers的C++为自己PC/服务器中的C++交叉编译工具链所在位置

Target Root为自己PC/服务器公用头文件所在位置

Include Mode为Search only in Target Root

点击Finish

6.等到Configuring done

勾选BUILD_JPEG和BUILD_PNG

另外CMAKE_INSTALL_PREFIX也重新选择一下:

7.再次点击Configure,等待Configuring done,点击Generate,等待Generating done,可以关闭cmake-gui了

8.在/home/ubuntu/opencv/opencv-3.4.1/build中运行make -j32,等待100%,然后执行sudo make install,无报错即完成opencv arm交叉编译,所有的编程成果物都在刚才设置好的CMAKE_INSTALL_PREFIX中

2.仿真验证

1.在没有arm板的情况下,在PC/服务器上做仿真验证:

sudo apt-get install qemu

编写main.cpp

#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;


int main()

	Mat image;
	image = imread("test.jpg");
	return 0;

2.编写Makefile

SRCS += $(wildcard main.cpp)
OBJS = $(SRCS:.cpp = .o)
CXX = arm-linux-gnueabihf-g++
TARGET = exam
INCLUDES = -I/home/ubuntu/output/include/
LIBS = -L.
LIBS += -L/home/ubuntu/output/lib/
CCFLAGS = -Wall -O0

all : $(TARGET)

$(TARGET):$(OBJS)
	$(CXX) $^ -o $@ $(INCLUDES) $(LIBS) -lopencv_stitching -lopencv_videostab -lopencv_objdetect -lopencv_photo -lopencv_dnn -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_ml -lopencv_superres -lopencv_videoio -lopencv_imgcodecs -lopencv_shape -lopencv_video -lopencv_imgproc -lopencv_core -ldl -lm -lpthread -lrt
%.o:%.cpp
	$(CXX) -c $< $(CCFLAGS)
clean:
	rm $(TARGET)

3.编译

make

4.将/home/ubuntu/output/lib/所有文件复制到/usr/lib/下,然后执行

qemu-arm -L /usr/arm-linux-gnueabihf/ ./exam

执行无报错 即完成

以上是关于opencv arm交叉编译与仿真验证详细流程的主要内容,如果未能解决你的问题,请参考以下文章

经验分享华为atlas500系列aarch64交叉编译opencv

经验分享华为海思Hi35xx系列ARM32交叉编译opencv

ubuntu20.04 arm-linux-gnueabihf交叉编译opencv4.7.0 与opencv-contrib-4.7.0

ubuntu20.04 arm-linux-gnueabihf交叉编译opencv4.7.0 与opencv-contrib-4.7.0

DM8168 OpenCV尝试与评估(编译ARM版OpenCV)

如何安装arm-liunx交叉编译环境?