问题遇到的现象和发生背景 c++opencv调用setmousecallback时运行顺序不正确,就是代码中先输出1,再出现图片
问题相关代码,请勿粘贴截图
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
#define WINDOW "原图"
Mat g_srcImage;
Point previousPoint;
void On_mouse(int event, int x, int y, int flags, void*);
int main()
{
g_srcImage = imread("test.png", 1);
imshow(WINDOW, g_srcImage);
setMouseCallback(WINDOW, On_mouse, 0);
cout << 1;
waitKey(0);
return 0;
}
void On_mouse(int event, int x, int y, int flags, void*)
{
if (event == EVENT_LBUTTONDOWN)
{
previousPoint = Point(x, y);
}
else if (event == EVENT_MOUSEMOVE && (flags & EVENT_FLAG_LBUTTON))
{
Point pt(x, y);
line(g_srcImage, previousPoint, pt, Scalar(0, 0, 255), 2, 5, 0);
previousPoint = pt;
imshow(WINDOW, g_srcImage);
}
}