qt交叉编译------------------------------------------------------------------------
1:资料准备
opencv-3.4.3.zip
opencv_contrib-3.4.3.zip
boostdescetc.zip
2:opencv目录下创建一个build和install文件夹
cmake-gui选择sourcecode和build目录
点击configure
next
点击finish
出现大量红色没事,继续勾选Grouped以及Advances
接着配置一下编译选项,search框输入CMAKE_INSTALL_PREFIX,指定你的安装路径,之前建立的install文件夹
输入CMAKE_CXX_FLAG与CMAKE_CXX_FLAG_DEBUG
BUILD_opencv_world 这个灰常重要
zlib
OPENCV_EXTRA_MODULES_PATH, 指向opencv_contrib-3.4.3/modules目录
打开opencv源码的3rdparty/protobuf/src/google/protobuf/stubs/common.cc文件
在一堆#include的下面, 加入#define HAVE_PTHREAD避免编译的时候报找不到pthread错误;
之后点击configure 再点击generate
ctrl+alt+t再开一个窗口
make -j 16
错误提示
1:undefined reference to”png_init_filter_functions_neon”
解决方法:修改
/opencv-3.4.3/3rdparty/libpng/pngpriv.h
错误2:
解决办法:将boostdescetc.zip里的.i文件复制到目录opencv_contrib/modules/xfeatures2d/src/下即可
编译完成
make install
至此opencv库编译完成;
测试----------------------------------------------------------------------------------------------------------
新建文件test.cpp
#include
#include
#include
using namespace std;
using namespace cv;
void cvTest()
{
Mat img = imread("/opt/1080.jpg");
Mat grad_x;
Sobel(img, grad_x, CV_16S, 1, 0);
Mat grad_y;
Sobel(img, grad_y, CV_16S, 0, 1);
Mat gradImage = abs(grad_x) + abs(grad_y);
double minGrad, maxGrad;
minMaxLoc(gradImage, &minGrad, &maxGrad);
Mat gradImage_8U;
gradImage.convertTo(gradImage_8U, CV_8U, 255./maxGrad);
Mat thresholdedImage;//阈值化后的二值图
threshold(gradImage_8U, thresholdedImage, 20, 255, THRESH_BINARY_INV);
imwrite("gradImage_8U.jpg",gradImage_8U);
imwrite("thresholdedImage.jpg",thresholdedImage);
}
int main()
{
cvTest();
return 0;
}
执行指令:
/opt/atk-dlrv1126-toolchain/bin/arm-linux-gnueabihf-g++ test.cpp -o test -fPIC -lrt -D_GNU_SOURCE -lpthread -lm -ldl -lopencv_world -I '/home/wzw/opencv_rv1126/opencv-3.4.3/install/include' -L '/home/wzw/opencv_rv1126/opencv-3.4.3/install/lib'
将test可执行文件用adb push到板端
./test
此时跳出错误
此时将opencv-3.4.3/install/lib/libopencv_world.so拷贝到板端的/usr/lib目录下
运行./test(注意一下图片的名称和路径)运行成功,如下图所示
载到pc端观看