I want to get a position when move and click mouse in picturebox. I want to create rectangle in the image window when and where a mouse is clicked.
<
In tracking module of opencv-contrib, there is a nice feature of selectROI.
#include
// selectROI is part of tracking API
#include
using namespace std;
using namespace cv;
int main (int argc, char **arv)
{
// Read image
Mat im = imread("image.jpg");
// Select ROI
Rect2d r = selectROI(im, false); // false -> for creating rectangle from
// top-left to bottom-right
// Crop image
Mat imCrop = im(r);
// Display Cropped Image
imshow("Image", imCrop);
waitKey(0);
return 0;
}
Use the mouse to select the ROI(region of interest) and then press SPACE or ENTER button. Cancel the selection process by pressing c button.