Change the location of a fixed rectangle in the image by moving the mouse
I am using OpenCV for a C++ application.I have a fixed rectangle in my image.I want when I click on the mouse on the rectangle,than The rectangle position changes to where the mouse is released.I'm beginner in opencv and c++.do you have any idea to do this?this is my code:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
// Open the video file
VideoCapture capture("blowcontrast1.avi");
if (!capture.isOpened())
return 1;
bool stop(false);
Mat frame; //current video frame
namedWindow("Extracted Frame");
int delay = 1;
cout << capture.get(CV_CAP_PROP_FPS);
capture.set(CV_CAP_PROP_POS_AVI_RATIO, 0.5);
while (!stop)
{
if (!capture.read(frame))
break;
Rect rectangle(200 , 150, 40, 40);
rectangle(frame, rectangle, Scalar(255, 255, 255));
imshow("Extracted Frame", frame);
if (waitKey(delay) >= 0)
stop = true;
}
waitKey();
}
take a look at this