OpenCV3添加滑动条和鼠标事件到图形界面
鼠标事件和滑动条控制在计算机视觉和OpenCV中非常有用,使用这些控件,用户可以直接与图形界面交互,改变输入图像或者变量的属性值。
/*
In this section, we are going to introduce you to the concepts of adding slider and
mouse events for basic interactions. To understand this correctly, we will create a small
project, where we paint green circles in the image using the mouse events and blur the
image with slider.
*/
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
using namespace cv; // Create a variable to save the position value in track
int blurAmount = ; // Trackbar call back function
static void onChange(int pos, void* userInput); // Mouse callback
static void onMouse(int event, int x, int y, int, void* userInput); int main(int argc, const char** argv)
{
// Read images
Mat boy = imread("../images/eating.jpg"); // Create windows
namedWindow("Boy"); // Create a trackbar
createTrackbar("Boy", "Boy", &blurAmount, , onChange, &boy); setMouseCallback("Boy", onMouse, &boy); // Call to onChange to init
onChange(blurAmount, &boy); // wait app for a key to exit
waitKey(); // Destroy the windows
destroyWindow("Boy"); return ;
} // Trackbar call back function
static void onChange(int pos, void* userInput)
{
if (pos <= ) return;
// Aux variable for result
Mat imgBlur; // Get the pointer input image
Mat* image = (Mat*)userInput; // Apply a blur filter
blur(*image, imgBlur, Size(pos, pos)); // Show the result
imshow("Boy", imgBlur);
} // Mouse callback
static void onMouse(int event, int x, int y, int, void* userInput)
{
if (event != EVENT_LBUTTONDOWN) return; // Get the pointer input image
Mat *image = (Mat*)userInput; // Draw circle
circle(*image, Point(x, y), , Scalar(, , ), ); // Call onChange to get blurred image
onChange(blurAmount, image);
}
程序运行效果如下:

OpenCV3添加滑动条和鼠标事件到图形界面的更多相关文章
- OpenCV——图像的载入、显示、输出到文件和滑动条、鼠标操作
图像的载入.显示.输出到文件和滑动条 滑动条 示例: 鼠标操作
- OpenCV 为程序界面添加滑动条
#include <cv.h> #include <highgui.h> using namespace cv; /// 全局变量的声明与初始化 ; int alpha_sli ...
- 1.0.2-学习Opencv与MFC混合编程之---为播放AVI视频添加滑动条
源代码地址:http://download.csdn.net/detail/nuptboyzhb/3961642 版本1.0.2新增内容 Ø 全局变量和函数的添加: 在CVMFCview.cpp文件 ...
- Slider 滑动条效果
转载自:http://www.cnblogs.com/cloudgamer/archive/2008/12/24/Slider.html 这个滑动条(拖动条)效果,一开始是参考了BlueDestiny ...
- 给div"上"滑动条
最近做项目时修改一个遗留的bug,大概是这样:有一个聊天窗口,用户聊天内容展现在窗口上.其实这个窗口是一个带滑动条的div,随着聊天内容的添加,滑动条也越来越长了,这不是重点,重点是每次刷新窗口时候, ...
- 关于Unity中NGUI的Checkbox复选框、Slider滑动条和Button的6种触发回调事件的方式
Checkbox复选框 1.创建一个NGUI背景Sprite1节点 2.打开NGUI---->Open---->Prefab Toolbar---->选择一个复选框节点,拖拽到背景节 ...
- opencv学习之路(5)、鼠标和滑动条操作
一.鼠标事件 #include<opencv2/opencv.hpp> #include<iostream> using namespace cv; using namespa ...
- 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结
史上最全的CSS hack方式一览 2013年09月28日 15:57:08 阅读数:175473 做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我 ...
- 【WPF】点击滑动条(Slider),移动滑块(Tick)到鼠标点击的位置
问题:点击Slider控件时,滑块会自动跳到滑动条的最边缘位置,无法跳到鼠标点击的位置上. 办法:给Slider控件设置属性IsMoveToPointEnabled="True"即 ...
随机推荐
- lucene_indexWriter说明、索引库优化
IndexWriter Hibernate的SessionFactory 在Hibernate中.一般保持一个数据库就仅仅有一个SessionFactory.由于在SessionFactory中维护二 ...
- 通过缓存数据库结果提高PHP性能(转)
众所周知,缓存数据库查询的结果可以显著缩短脚本执行时间,并最大限度地减少数据库服务器上的负载.如果要处理的数据基本上是静态的,则该技术将非常有效.这是因为对远程数据库的许多数据请求最终可以从本地缓存得 ...
- PHP写入文件用file_put_contents代替fwrite优点多多(转)
使用php有一段时间了,之前一直用fwrite写入文件,不过当我知道file_put_contents这个函数之后,fwrite就比较少用了,file_put_contents比fwrite代码更简洁 ...
- 目录操作函数opendir、readdir和closedir
首先,明确一个类型DIR的含义: #include <dirent.h> DIR A type representing a directory stream. DIR是在目录项格式 ...
- Android 定时器实现的几种方式和removeCallbacks失效问题详解
实现定时器有很多种方式,在这里我简单的介绍几种方式 (1)使用Handler + Runnable的方式 Handler handler = new Handler(); Runnable runna ...
- Turn the pokers
Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...
- View绘制详解(五),draw方法细节详解之View的滚动/滑动问题
关于View绘制系列的文章已经完成了四篇了,前面四篇文章主要带小伙伴们熟悉一下View的体系的整体框架.View的测量以及布局等过程,从本篇博客开始,我们就来看看View的绘制过程.View的绘制涉及 ...
- [翻译]Json.NET API-Linq to Json Basic Operator(基本操作)【转】
在Json.NET开源的组件的API文档中看到其中有个Linq To Json基本操作.详细看了其中API 中Linq to SQL命名空间下定义类方法.以及实现, 觉得参与Linq 来操作Json从 ...
- ios数据缓存方法
转载自:http://zhidao.baidu.com/link?url=jNTz6lkL1way8bJ-WPY197Pe9aEM_ql-MZbVJsM5tXr7Mv82W70QQ5a9UlvhMMS ...
- 【AR】增强现实安卓编程 - Vuforia SDK 的安装和使用 (Android Studio)
Vuforia是个强大的AR平台.使用Vuforia API 可以实现物体识别,图片追踪,柱型追踪,多对象追踪,自定义目标追踪,云识别,文字识别,帧标识和虚拟按钮等功能. 它支持Android, iO ...