跟着《OpenCV By Example》学到了第三章节,自己用的windows10+VS2017+OpenCV3.3.1
看到了交互界面添加按钮的代码,本以为代码不需要Qt,结果运行时报错:
OpenCV Error: The function/feature is not implemented (The library is compiled without QT support) in cv::createButton, file
代码如下:
#include <iostream>
#include <string>
#include <sstream>
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
using namespace cv;
using namespace std;
Mat img;
bool applyGray = false;
bool applyBlur = false;
bool applySobel = false;
void grayCallback(int state, void* userData);
void bgrCallback(int state, void* userData);
void blurCallback(int state, void* userData);
void sobelCallback(int state, void* userData);
void applyFilters();
int main()
{
img = imread("1.jpg");
namedWindow("img");
createButton("Blur", blurCallback, NULL, QT_CHECKBOX, 0);
createButton("Gray", grayCallback, NULL, QT_RADIOBOX, 0);
createButton("RGB", bgrCallback, NULL, QT_RADIOBOX, 1);
createButton("Sobel", sobelCallback, NULL, QT_PUSH_BUTTON, 0);
waitKey(0);
destroyAllWindows();
return 0;
}
void grayCallback(int state, void* userData)
{
applyGray = true;
applyFilters();
}
void bgrCallback(int state, void* userData)
{
applyGray = false;
applyFilters();
}
void blurCallback(int state, void* userData)
{
applyBlur = (bool)state;
applyFilters();
}
void sobelCallback(int state, void* userData)
{
applySobel = !applySobel;
applyFilters();
}
void applyFilters()
{
Mat result;
img.copyTo(result);
if (applyGray)
{
cvtColor(result, result, COLOR_BGR2GRAY);
}
if (applyBlur)
{
blur(result, result, Size(5, 5));
}
if (applySobel)
{
Sobel(result, result, CV_8U, 1, 1);
}
imshow("img", img);
}