#include<opencv2/opencv.hpp>
int current = 0;
//鼠标事件函数
void OnMouse(int Event, int x, int y, int flags, void* param)
{
switch (Event)
{
case CV_EVENT_LBUTTONDOWN: //左键按下
current ^= 1; //交替 0 和 1
break;
default: break;
}
return ;
}
int main()
{
cv::Mat img0 = cv::imread("img0.png",0);
cv::Mat img1 = cv::imread("img1.png",0);
cv::namedWindow("My Window", CV_WINDOW_NORMAL);
cv::setWindowProperty("My Window", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
cv::setMouseCallback("My Window", OnMouse);
//窗口开始
while(true){
if (current == 0) cv::imshow("My Window", img0);
if (current == 1) cv::imshow("My Window", img1);
char key = cvWaitKey(20); // 20ms刷一帧
} //窗口结束
return 0;
}