赞
踩
mkdir ~/linux/mylib&&cd ~/linux/mylib
wget https://codeload.github.com/opencv/opencv/tar.gz/3.4.1 -O opencv-3.4.1.tar.gz
tar -xvf opencv-3.4.1.tar.gz&&cd opencv-3.4.1/
sudo apt-get install cmake cmake-qt-gui cmake-curses-gui
mkdir build install&&cd build
cmake-gui
(1)指定源码的路径和构造目录
(2)配置CMake参数
(3)填写交叉编译器的路径,Finish
(4)Cmake配置完成
在 build
文件夹生成文件:
(5)配置要编译的库、信息,指定依赖库的链接参数
搜索 CMAKE_EXE_LINKER_FLAGS ,添加上 -lpthread -lrt -ldl
(6)指定安装目录到新建的 install 目录
搜索CMAKE_INSTALL_PREFIX, /usr/local
改为 /home/pjw/linux/mylib/opencv-3.4.1/install
(7)改为正式版,优化速度
搜索CMAKE_BUILD_TYPE,将这个键的值改成Release
(8)生成 Makefile 等文件
点击 Configure,再点击 Generate 就可以生成。
因为 HAVE_PTHREAD 宏定义了 pthread 库。所以要添加宏定义才可以编译得过。
cd .. //返回opencv顶层目录
vim 3rdparty/protobuf/src/google/protobuf/stubs/common.cc
#define HAVE_PTHREAD
//进入build文件夹编译
cd build/&&make -j16
//把库安装到创建的 install 目录&&查看安装目录 install
make install&&ls install/
vim ~/.bashrc
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:~/linux/mylib/opencv-3.4.1/install/lib/pkgconfig
source ~/.bashrc
//查看路径
pkg-config --libs --cflags opencv
//输出
-I/home/pjw/linux/mylib/opencv-3.4.1/install/include/opencv -I/home/pjw/linux/mylib/opencv-3.4.1/install/include -L/home/pjw/linux/mylib/opencv-3.4.1/install/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
编写:cv_test.cpp
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
int main(){
cv::Mat image = cv::imread("picture.png");
cv::namedWindow("picture");
cv::imshow("picture",image);
cv::waitKey(5000);
return 0;
}
编译:
arm-linux-gnueabihf-g++ -o cv_test cv_test.cpp `pkg-config --cflags --libs opencv`
查看生成的可执行文件属性,为ARM架构:
1、参照文章在开发板根文件下挂载目录:
2、把OpenCV的 install/lib
下的所有库,拷贝到文件系统下的 /lib
目录下。
//拷贝opencv的lib文件夹到nfs目录
cp -r ~/linux/mylib/opencv-3.4.1/install/lib ~/linux/nfs
开发板终端查看:
//进入nfs挂载目录下的lib文件夹
cd ~/mountnfs/lib/
//拷贝所有文件到开发板 `lib` 下
cp * /lib/
可以看到,全部拷贝过来了。
3、把测试app拷贝过来:
cp -r ~/linux/project/opencvApp/cv_test ~/linux/nfs
4、执行测试app
./cv_test
报错:
OpenCV(3.4.1) Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /home/pjw/linux/mylib/opencv-3.4.1/modules/highgui/src/window.cpp, line 618
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.1) /home/pjw/linux/mylib/opencv-3.4.1/modules/highgui/src/window.cpp:618: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow
Aborted
这是因为没有GTK,跑不了UI,而代码中使用了opencv的窗口创建和显示函数,所以报错,就是以下2句代码:
cv::namedWindow("picture");
cv::imshow("picture",image);
参考 【正点原子】I.MX6U 移植OpenCV V1.2、OpenCV移植到ARM全过程-III
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。