1.主要参考教程《使用CMake-gui编译OpenCV3源码的详细过程》,实际操作结合多个教程。
2.放从OPENCV RELEASE 下载的解压出来的文件,里面还要放对应版本的contribute 解压文件
/root/opencv-4.5.4
/root/opencv-4.5.4/build6
在这里要找到三个地方进行修改;
1、勾选上BUILD_opencv_world
2、在CMAKE_BUILD_TYPE后填上:RELEASE
3、在OPENCV_EXTRA_MODULES_PATH后填上opencv-contrib/modules的路径
比如我是:/home/wsx/opencv/opencv/opencv_contrib/modules
完成之后再次点击Configure按钮,稍等片刻,之后在点击Generate按钮
(所有红色报错,全部关掉即可)
交叉编译工具链地址:
/root/tina-v853-docker/prebuilt/rootfsbuilt/arm/toolchain-sunxi-musl-gcc-830/toolchain/bin/arm-openwrt-linux-gcc
/root/tina-v853-docker/prebuilt/rootfsbuilt/arm/toolchain-sunxi-musl-gcc-830/toolchain/bin/arm-openwrt-linux-g++
/root/tina-v853-docker/prebuilt/rootfsbuilt/arm/toolchain-sunxi-musl-gcc-830/bin/
注意:
-
取消WITH_GTK
取消WITH_TIFF , PNG ,JPG
所有红色报错的功能,都不要勾选,或者自己搞定。 -
如果点击configure提示处理器未识别
那么执行vi /root/opencv-4.5.4/cmake/OpenCVDetectCXXCompiler.cmake
可以在第47行,写入 set(CMAKE_SYSTEM_PROCESSOR arm)
(一定会提示,一定要这么做。)
4、 如果要修改默认的install文件夹,要在点击Generate之前修改,修改方式如下
vi /root/opencv-4.5.4/build6/CMakeCache.txt
修改CMAKE_INSTALL_PREFIX:PATH=/root/opencv-4.5.4/build6
5、进入目录
/root/opencv-4.5.4/build6/
执行 cmake .
执行 export STAGING_DIR=/root/tina-v853-docker/prebuilt/rootfsbuilt/arm/toolchain-sunxi-musl-gcc-830/toolchain/bin
执行 make -j20
(看自己的线程数,设定)
到此编译成功
6、编译出来的文件
动态库文件 /usr/local/lib/
文件库 /usr/local/include/opencv4/
注意下面步骤中成功编译出来的固件,是不含动态库的,所以还需要编译时所用的动态库,同步复制到板子的/usr/lib/ 里面去。否则报错找不到动态库
7、编译一个opencv example
首先 执行
export STAGING_DIR=/root/tina-v853-docker/prebuilt/rootfsbuilt/arm/toolchain-sunxi-musl-gcc-830/toolchain/bin
任意目录下创建3个文件
1.CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
set (ARM_LINUX_GCC_PATH /root/tina-v853-docker/prebuilt/rootfsbuilt/arm/toolchain-sunxi-musl-gcc-830/toolchain/bin/) # 改成你的路径
set (CMAKE_C_COMPILER ${ARM_LINUX_GCC_PATH}arm-openwrt-linux-gcc)
set (CMAKE_CXX_COMPILER ${ARM_LINUX_GCC_PATH}arm-openwrt-linux-g++)
project(Test_OpenCV_Mobile)
set(CMAKE_CXX_STANDARD 11)
set(OpenCV_DIR "/root/opencv-4.5.4/") # 改成你的路径
find_package(OpenCV REQUIRED)
FIND_PACKAGE(OpenMP REQUIRED)
add_executable(Test_OpenCV_Mobile main.cpp)
target_link_libraries(Test_OpenCV_Mobile pthread)
target_link_libraries(Test_OpenCV_Mobile dl)
target_link_libraries(Test_OpenCV_Mobile -fopenmp)
target_link_libraries(Test_OpenCV_Mobile ${OpenCV_LIBS})
2.makefile
OPENCV_DIR := /root/opencv-4.5.4/
THIRD_PART_INCLUDE := -I$(OPENCV_DIR)include/opencv4 -I$(OPENCV_DIR)include/opencv4/opencv2
THIRD_PART_LIBRARY := $(OPENCV_DIR)lib/libopencv_highgui.a $(OPENCV_DIR)lib/libopencv_features2d.a $(OPENCV_DIR)lib/libopencv_imgproc.a $(OPENCV_DIR)lib/libopencv_photo.a $(OPENCV_DIR)lib/libopencv_video.a $(OPENCV_DIR)lib/libopencv_core.a
TARGET = Test_OpenCV_Mobile
START:
@echo START
rm -rf $(TARGET)
/root/tina-v853-docker/prebuilt/rootfsbuilt/arm/toolchain-sunxi-musl-gcc-830/toolchain/bin/arm-openwrt-linux-g++ -O2 -std=c++11 -lpthread -fopenmp -ldl $(CFLAGS) $(THIRD_PART_INCLUDE) -o $(TARGET) ./main.cpp $(THIRD_PART_LIBRARY)
.PHONY:clean
clean:
rm -rf $(BINDIR)
3.main.cpp
#include
#include
int main()
{
cv::Mat mat = cv::Mat::zeros(256,256, CV_8UC1);
{
cv::rectangle(mat, cv::Rect(40, 45, 51, 65), cv::Scalar(255), -1, cv::LINE_8, 0);//绘制填充矩形
cv::rectangle(mat, cv::Rect(180, 180, 85, 21), cv::Scalar(255), -1, cv::LINE_8, 0);//绘制填充矩形
std::cout "mat.rows = " std::endl;
std::cout "mat.cols = " std::endl;
}
return 0;
}
8.编译 opencv example
在创建的目录里面,执行
cmake .
make
9、将文件推进板子,并添加权限执行
10、推送相应的动态库进入 /usr/lib
比如 world,core….
11、最后终端执行,推送进来的文件。
./Test_OpenCV/example
到此 opencv 4.5.4 编译成功,并运行opencv example成功。
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
http://www.iteye.com/topic/1069749 服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net 机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net