继上次完成NumCpp的移植之后,这些我们来进行OpenCV与OpenCV_contrib的移植。
1. OpenCV、OpenCV_contrib源码下载
GitHub - opencv/opencv: Open Source Computer Vision LibraryOpen Source Computer Vision Library. Contribute to opencv/opencv development by creating an account on GitHub.https://github.com/opencv/opencvhttps://github.com/opencv/opencv_contrib
https://github.com/opencv/opencv_contrib
2. 第三方库的准备
交叉编译OpenCV之前,一般需要libz, libjpeg, libpng, yasm, libx264, libxvid, ffmpeg这些第三方库的编译。
具体的编译过程,我就不多说了,基本上就是检查编译器是否为交叉编译器,然后进行编译即可。这里重点注意ffmpeg,一会儿会提到。
3. 编译opencv与opencv_contrib
编译之前,设置后pkg的路径,输入一下命令
export PKG_CONFIG_PATH=/home/xinzhe/Documents/opencv_depend/lib/pkgconfig:$PKG_CONFIG_PATH
首先从GitHub中clone得到两个文件夹之后,进入到opencv文件夹,进行以下操作
mkdir build
cd build
cmake-gui
之后,弹出cmake-gui的界面。
我们首先设置好source code与build的路径,然后点击configure,然后选择Unix Makefiles里的specify options for cross-compiling,然后进入到新的窗口,填入linux、arm、编译器、依赖库路径,点击finish。
然后configure开始运行。
运行结束后,我们从下面的log里,检查Video I/O:这一项,发现里面的ffmpeg处是NO,也就是没有检测到ffmpeg。这个时候我们需要增加一个值,添加OPENCV_ENABLE_PKG_CONFIG变量,并设其值为true,然后我们再configure,此时发现ffmpeg处为YES。
这样,我们编译出来的opencv能够读视频文件,否则不能够读取成功。
然后我们搜索设置以下内容,这里的selected文件夹中的modules是我从opencv_contrib中的modules下截取的,我只使用了opencv_contrib/modules中的bgsem,因此我把它放到selected/modules里。不把整个opencv_contrib/modules设置为extra_modules是因为,其中的某些库还需要另外的第三方库,我就懒得弄了,如果大家想编译整个opencv_contrib/modules,也是可以的。
OPENCV_EXTRA_MODULES_PATH=/home/xinzhe/Documents/selected/modules
并且设置好CMAKE_INSTALL_PREFIX安装路径之后 ,将以下这些值取消勾选
WITH_TIFF
WITH_GTK
WITH_CUDA
WITH_OPENCL
WITH_OPENEXR
WITH_1394
设置CMAKE_BUILD_TYPE=Release
之后,我们重新点击configure,完成后点击Generate生成Makefile。
关闭cmake-gui,并在build目录下
make
make install
这样我们就得到了opencv与opencv_contrib的交叉编译文件。
4. 交叉编译自己的cpp文件
在自己的cpp文件下,创建Compile.cmake与CMakeLists.txt文件。
其中CMakeLists.txt如下
cmake_minimum_required(VERSION 2.8)
Project(CVWorld)
set(CMAKE_FIND_ROOT_PATH /home/xinzhe/Documents/opencv_v853)
find_package(OpenCV REQUIRED)
##下面是输出信息
message(STATUS "Opnecv library status: ")
message(STATUS "> version: ${OpenCV_VERSION} ")
message(STATUS ">libraries: ${OpenCV_LIBS} ")
message(STATUS "> include: ${OpenCV_INCLUDE_DIRS} ")
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(VideoHitMan main.cpp)
target_link_libraries(VideoHitMan ${OpenCV_LIBS})
然后,我们创建build文件夹,按以往的操作编译,运行可执行文件,发现缺少一些.so动态库文件。
这个时候,我们将opencv_depend/lib下的所有库文件cp到opencv_v853/lib下,这样就可以编译成功了。
5. 在V853开发板上运行编译得到的程序
得到可执行文件后,将其与opencv_v853 push到板子上,然后输入
export LD_LIBRARY_PATH=/root/opencv_v853/lib:$LD_LIBRARY_PATH
运行程序,发现一大堆库有问题。这个时候就重新建立指向链接就行。
最后就可以运行成功啦。
root@TinaLinux:/# cd root
root@TinaLinux:~# export LD_LIBRARY_PATH=/root/opencv_v853/lib:$LD_LIBRARY_PATH
root@TinaLinux:~# ./VideoHitMan
the video is /root/4.mp4
Height:720 Width:1280
This is the start row :226
This is the end row :712
col_mid = 108
Height:720 Width:1280
This is the start row :226
This is the end row :704
col_mid = 108
Height:720 Width:1280
This is the start row :228
This is the end row :687
col_mid = 112
Height:720 Width:1280
This is the start row :229
This is the end row :672
col_mid = 115
Height:720 Width:1280
This is the start row :230
This is the end row :664
col_mid = 116
Height:720 Width:1280
This is the start row :231
This is the end row :663
col_mid = 116
Height:720 Width:1280
This is the start row :235
This is the end row :663
col_mid = 117
Height:720 Width:1280
This is the start row :238
This is the end row :663
col_mid = 117
Height:720 Width:1280
This is the start row :243
This is the end row :662
col_mid = 118
Height:720 Width:1280
This is the start row :246
This is the end row :661
col_mid = 118
Height:720 Width:1280
This is the start row :250
This is the end row :660
col_mid = 120
Height:720 Width:1280
This is the start row :252
This is the end row :656
col_mid = 121
Height:720 Width:1280
This is the start row :255
This is the end row :650
col_mid = 123
Height:720 Width:1280
This is the start row :256
This is the end row :642
col_mid = 126
Height:720 Width:1280
This is the start row :257
This is the end row :634
col_mid = 128
Height:720 Width:1280
This is the start row :257
This is the end row :621
col_mid = 132
Height:720 Width:1280
This is the start row :256
This is the end row :602
col_mid = 139
Height:720 Width:1280
This is the start row :256
This is the end row :601
col_mid = 138
Height:720 Width:1280
This is the start row :257
This is the end row :599
col_mid = 139
Height:720 Width:1280
This is the start row :258
This is the end row :596
col_mid = 140
Height:720 Width:1280
This is the start row :261
This is the end row :595
col_mid = 142
Height:720 Width:1280
This is the start row :263
This is the end row :595
col_mid = 143
Height:720 Width:1280
This is the start row :266
This is the end row :594
col_mid = 143
Height:720 Width:1280
This is the start row :269
This is the end row :594
col_mid = 145
Height:720 Width:1280
This is the start row :271
This is the end row :594
col_mid = 145
Height:720 Width:1280
This is the start row :273
This is the end row :593
col_mid = 146
location = 73216
Generated binary tensor from silhouette
root@TinaLinux:~#
今天就到这里啦,感谢看到的每个小伙伴!