aarch交叉编译opencv、ncnn

aarch64-linux-gnu-gcc/g++ 交叉编译工具链

# 查看可以安装的版本
apt-cache search aarch64
# 选择可以安装的版本进行安装
# 此处选择gcc-5-aarch64-linux-gnu以及g++-5-aarch64-linux-gnu进行安装
sudo apt-get install gcc-5-aarch64-linux-gnu 
sudo apt-get install gcc-5-aarch64-linux-gnu
# 安装依赖
sudo apt --fix-broken install
# 安装一个没有版本号的gcc和g++
sudo apt-get install gcc-aarch64-linux-gnu
sudo apt-get install gcc-aarch64-linux-gnu
# 查看版本
aarch64-linux-gnu-g++ -v
aarch64-linux-gnu-gcc -v

交叉编译opencv
修改platform/linux/aarch64-gnu.toolchain.cmake

set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(GCC_COMPILER_VERSION "" CACHE STRING "GCC Compiler version")
set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++)
set(GNU_MACHINE "aarch64-linux-gnu" CACHE STRING "GNU compiler triple")
include("${CMAKE_CURRENT_LIST_DIR}/arm.toolchain.cmake")

在opencv3.2.0下新建文件夹 aarch_64_install和build,进入build,执行
sudo cmake -DCMAKE_MAKE_PROGRAM:PATH=/usr/bin/make -DCMAKE_INSTALL_PREFIX=../aarch_64_install -DWITH_CUDA=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake -DCUDA_GENERATION=Kepler ..
-DCMAKE_INSTALL_PREFIX 指定编译文件make install后保存路径

make -j64

make install

#include <opencv2/opencv.hpp>
 
using namespace cv; 
 
int main( int argc, char** argv )  
{  
	Mat image;  
 
	image = imread( "7.bmp", 1 );  
	if( !image.data )  
	{  
		printf( "No image data \n" );  
		return -1;  
	}   
 
	cv::Point lu = cv::Point(180, 60); 
	cv::Point rd = cv::Point(400, 260);   
 
	cv::rectangle(image, lu, rd, cv::Scalar( 255, 20, 0 ), 1, CV_AA );                 	
 
	imwrite("8.bmp", image);        
 
	return 0;  
}

在终端执行:
/usr/bin/aarch64-linux-gnu-g++ -o draw_image test.cpp -I ../aarch_64_install/include/ ../aarch_64_install/lib/libopencv_core.so ../aarch_64_install/lib/libopencv_imgcodecs.so ../aarch_64_install/lib/libopencv_imgproc.so

交叉编译ncnn


cd <ncnn-root-dir>
mkdir -p build-aarch64-linux-gnu
cd build-aarch64-linux-gnu
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu.toolchain.cmake ..
make -j$(nproc)
按照opencv设置进行make install

你可能感兴趣的:(opencv,linux,人工智能,cnn)