Detailed process of opencv arm cross compilation and simulation verification

【Key content】

1. Compile opencv into a library that can run on arm, and directly obtain the compiled results. See:

armv7:https://download.csdn.net/download/u012824853/87867650

armv8:https://download.csdn.net/download/u012824853/87867658

2. In the absence of a board, simulate and verify the opencv library

1. Compile opencv into a library that can run on arm

1. Select a version from the link below

Releases - OpenCV https://opencv.org/releases/ Click "Sources" to start downloading, get opencv-3.4.1.zip:

2. Unzip and get opencv-3.4.1 to /home/ubuntu/opencv/opencv-3.4.1/

unzip opencv-3.4.1.zip

3. Open cmake-gui:

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

4.

where is the source code: the path of opencv-3.4.1 just downloaded and decompressed

where to build the binaries: just download the build in the path of opencv-3.4.1 after decompression

Then click Configure

5. Operation System must be Linux, Processor must be arm

The C of Compilers is the location of the C cross-compilation toolchain in your own PC/server

Compilers' C++ is the location of the C++ cross-compilation toolchain in your PC/server

Target Root is the location of your own PC/server public header files

Include Mode为Search only in Target Root

Click Finish

6. Wait until Configuration is done

Tick ​​BUILD_JPEG and BUILD_PNG

In addition, CMAKE_INSTALL_PREFIX is also reselected:

7. Click Configure again, wait for Configuring done, click Generate, wait for Generating done, you can close cmake-gui

8. Run make -j32 in /home/ubuntu/opencv/opencv-3.4.1/build, wait for 100%, then execute sudo make install, complete opencv arm cross-compilation without error, all programming results are just now In the set CMAKE_INSTALL_PREFIX

2. Simulation verification

1. In the absence of an arm board, do simulation verification on a PC/server:

sudo apt-get install qemu

Write 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. Write 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. compile

make

4. Copy all files in /home/ubuntu/output/lib/ to /usr/lib/, then execute

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

Execution completes without error

Guess you like

Origin blog.csdn.net/u012824853/article/details/128746720