Hi, I am trying to use mouse callback function to crop out the rectangular area by clicking twice on the image. Below is code and error message.
include "opencv2/opencv.hpp"
using namespace std; using namespace cv;
vector<point>pt; Mat RectifiedImage; int main() { Mat RectifiedImage= imread("image.png"); imshow("Rectified Image", RectifiedImage); setMouseCallback("Rectified Image", onMouse, &pt); Mat ROI; while (true) { if (pt.size() <= 2) { int x = pt[0].x; int y = pt[0].y; int x1 = pt[1].x; int y1 = pt[1].y; ROI = RectifiedImage(Rect(x, y, x1 - x, y1 - y)); return false; }
}
imshow("left video stream", ROI);
static void onMouse(int event, int i, int j, int flags, void* param)
{
Mat &RectifiedImage = ((Mat)param);
Point p;
if (event == EVENT_LBUTTONDOWN)
{
p = { i,j };
pt.push_back(p);
cout << i << j << endl;
}
}
waitKey(0);
return 0;
}