Qt OpenCv Contrib 环境配置

Qt OpenCv Contrib 环境配置

Qt OpenCv基本配置参考: here.

在以上配置中,CMake到了设置以下变量时:

Set Qt5Concurrent_DIR to D:\Qt\Qt5.12.1\5.12.1\mingw73_64\lib\cmake\Qt5Concurrent
Set Qt5Core_DIR to D:\Qt\Qt5.12.9\5.12.9\mingw73_64\lib\cmake\Qt5Core
Set Qt5Gui_DIR to D:\Qt\Qt5.12.9\5.12.9\mingw73_64\lib\cmake\Qt5Gui
Set Qt5OpenGL_DIR to D:\Qt\Qt5.12.9\5.12.9\mingw73_64\lib\cmake\Qt5OpenGL
Set Qt5Test_DIR to D:\Qt\Qt5.12.9\5.12.9\mingw73_64\lib\cmake\Qt5Test
Set Qt5Widgets_DIR to D:\Qt\Qt5.12.9\5.12.9\mingw73_64\lib\cmake\Qt5Widgets
Set Qt5_DIR to D:\Qt\Qt5.12.9\5.12.9\mingw73_64\lib\cmake\Qt5

如以上变量不在CMake gui中展示,则需手动点击Add Entry来设置变量:
Qt OpenCv Contrib 环境配置_第1张图片

contrib设置:
在第一次Finish后,在选择WITH_OPENGL以及WITH_QT时,找到OPENCV_EXTRA_MODULES_PATH,将其设置为Contrib的modules文件夹下,如:C:/Program Files/opencv_contrib-4.5.4/modules
在这里插入图片描述

跟随上述链接博文配置完成后,在Qt中即可链接Contrib第三方库,如barcode:

#include 

简单示例,展示图片轮廓:

#include 
#include 
#include 
#include 
using namespace cv;
int g_nThresholdValue = 100;
int g_nThresholdType = 3;
// 图片格式暂不支持.gif,详见 https://docs.opencv.org/3.4/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56
Mat image = imread("C:/Users/Administrator/Pictures/Camera Roll/78375788_p0.jpg", IMREAD_ANYCOLOR);
Mat g_srcImage, g_grayImage, g_dstImage;

if (nullptr == image.data)
{
    QMessageBox::critical(this, "Error", "img no data");
}
else
{
    Mat z1, z2;
    cvtColor(image, z1, COLOR_BGR2GRAY);
    adaptiveThreshold(z1, g_grayImage, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 7, 25);
    threshold(g_grayImage, g_dstImage, g_nThresholdValue, 255, g_nThresholdType);
    imshow("Image Source", image);
    imshow("Image Output", g_dstImage);
}

运行结果:
Qt OpenCv Contrib 环境配置_第2张图片

你可能感兴趣的:(qt,qt,opencv)