先搭建个可以彩图的环境
1、交叉编译OpenCV
到opencv官网下载opencv-3.4.15并解压
工具链使用gcc-arm-9.2-2019.12-x86\_64-aarch64-none-linux-gnu
cd opencv-3.4.15
mkdir build-r329 && cd build-r329
cmake \
-DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake \
-DBUILD_SHARED_LIBS=OFF \
..
make -j
make install
2、测试
搭建cmake工程,结构如下:
mod@archlinux videoCapture $ tree -L 2
.
├── build
├── CMakeLists.txt
├── main.cpp
└── toolchains
└── aarch64-linux-gnu.toolchain.cmake
CMakeLists.txt
cmake_minimum_required(VERSION 3.10.2)
project(videoCap)
set(OpenCV_DIR /home/mod/code/opencv/opencv-3.4.15/build-r329/install/share/OpenCV)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
macro(add_example name)
add_executable(${name} ${name}.cpp)
target_link_libraries(${name} ${OpenCV_LIBS})
endmacro()
add_example(main)
main.cpp
#include "opencv2/opencv.hpp"
#include <iostream>
int main(void){
cv::Mat frame;
cv::VideoCapture cap;
cap.open("/dev/video0");
if (!cap.isOpened())
{
fprintf(stderr, "Failed to open");
return -1;
}
// for(;;){
//
// cap >> frame;
// imshow("scr", frame);
// if(cv::waitKey(30) == 'q'){
// break;
// }
// }
cap >> frame;
cv::imwrite("test.bmp", frame);
return 0;
}
aarch64-linux-gnu.toolchain.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_C_FLAGS "-march=armv8-a")
set(CMAKE_CXX_FLAGS "-march=armv8-a")
# cache flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags")
编译
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/aarch64-linux-gnu.toolchain.cmake ..
make
拷贝到开发板上(如果需要可以配置nfs环境,参考我在D1上的文章):
scp main root@192.168.100.93:/root
要密码的话,直接在开发板上设计就行。
在开发板上运行程序:
cd root
./main
可以看到多了一副图像test.bmp,拷贝到本地:
scp root@192.168.100.93:/root/test.bmp ./
如下:
编译好的opencv如下:
链接: https://pan.baidu.com/s/1A8UK... 密码: vm3s
接下来就可以做一些好玩的了