一、轨迹条的创建和使用
#include <iostream>
#include <opencv2\opencv.hpp>
using namespace cv;
Mat mm = imread("girl.jpeg"); //也可以使用user传参,把它写进局部变量里
void mohu(int pos , void*user) //第一个参数将由滑动条函数的position传入,第二个参数又用户定义参数,当滑动条的值改变时,才会执行这个响应函数
{
Mat implicitpic;
blur(mm, implicitpic, Size(1+pos, 1+pos)); //模糊操作
imshow("picPro", implicitpic);
printf("%d", getTrackbarPos("SLIDE", "picPro"));//获取滑动条位置
}
int main()
{
int position = 50;
namedWindow("picPro");
int positon;
createTrackbar("SLIDE", "picPro", &position, 100, mohu); //创建轨迹条
mohu(100,0); //100代表滑动条的初始位置
// posNow = getTrackbarPos("SLIDE", "picPro"); //获取滑动条位置
waitKey(0);
return 0;
}
二、鼠标动作的捕捉和响应
#include <iostream>
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
void OnMouseAction(int event, int x, int y, int flags, void* ustc)
{
int static times; //记录调用次数
times++;
//cout << "第 " << times << " 次回调鼠标事件" << endl;
switch (event)
{
case EVENT_MOUSEMOVE:
cout << "触发鼠标移动事件" << endl;
case EVENT_LBUTTONDOWN:
cout << "触发左键按下事件" << endl;
case EVENT_LBUTTONUP:
cout << "触发左键抬起事件" << endl;
case EVENT_RBUTTONDOWN:
cout << "触发右键按下事件" << endl;
case EVENT_RBUTTONUP:
cout << "触发右键抬起事件" << endl;
case EVENT_LBUTTONDBLCLK:
cout << "触发左键双击事件" << endl;
case EVENT_RBUTTONDBLCLK:
cout << "触发右键双击事件" << endl;
}
}
int main()
{
namedWindow("ceshi");
setMouseCallback("ceshi", OnMouseAction);
waitKey();
system("pause");
return 0;
}