opencv 用户交互窗口添加按钮

跟着《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);
}



评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值