setMouseCallback multiples rectangles
Dear all,
I am trying to show various fixed rectangles within a video flow, using the mouse. The fixed rectangle is set as follow within the onMouse function::
void onMouse(int event, int x, int y, int flags, void* param)
{
Rect rec = Rect(x, y, 100, 150);
if(event == EVENT_LBUTTONDOWN)
{
counter++;
}
}
So, when I move the mouse, I see the "rec" moving until I click down the left button. When a click is detected, I would like to show the ROI build within the main frame, and build outside the main frame my ROI through:
roi1 = frame(rec);
imshow("Roi1", roi1);
The problem is that the ROI is frozen and doesn't show the real time roi frame. I need also to repeat the operation 3 times.
Could you help me to solve this problem ?
Thanks for your help and support.
Regards,
Christophe
Have you try selectROI ?
Yes, thank you for the proposal. The problem with the selectRoi is that I need to use it during the video flow. Unfortunately, this function doesn't work properly if I start the video without passing through the first frame (fixed image). I could use the selectRoi if and only if it works within the while loop.
Do you have some idea for that ?
Regards,
@cherault, maybe you should rethink the whole workflow here,
the "human selection" mode is something entirely artificial, and probably only there to simplify the sample.
in the real world, you would get your initial Rects from e.g. some object detection, and there might be no human interaction at all.
that's for a reason. it's next to impossible to mark a (tight enough) fitting bbox on moving video ;)
what are you trying to achieve with the tracking, in general ? what is your "use-case" ?
Hello Berak, Thanks for your answer as LBerger. I understand what you wrote, and I don't really need the trackers to achieve my goal, but sometimes, real world is not enough ! ;-)
Seriously, I will try to explain my need:
I have an active video flow (640x480px). Within this flow, I will use the mouse to activate a square or rectangle which is defined (for example 100x150px). The mouse permit to activate (click left button down), move (left button down + move) and defined the final position (left button up). I just need to repeat this operation 3 times, and show the 3 squares on screen (active video flow), once it's done.
Do you think it's possible to realize this ?
Regards,
@cherault see the code on other question i think it will be helpful
@sturkmen, morning ;) wrong link above ?
@cherault, again there is selectROIs (note the plural !). and sure it would be possible to write something similar on your own.
also, your previous examples were using video files, so no problem to stop it for a moment.
how do you know about those numbers ? it might vary, no ?
i probably misunderstand the purpose of your program (and you're still a bit unclear here), but if it's for tracking, a fixed roi size won't work nicely.
Hello Sturkmen and Berak, thanks for your informations. Is the selectRois works...perfect ! I will try it again. For the number (x3) it's just my need, and yes, it might vary, but now, I want just 3 "rois" represented by rectangles or squares defined in the code. Show them within the frames.
So, thanks to you. I will try to do something "smart", and go back to you if needed.
Regards, and have a good day.
To be clear, I just want to draw, with a mouse, 3 formated squares within a video frame. I though it was a simple task, but it's not ! :-)