Panning image window programmatically [closed]
Hey everyone,
im trying to pan my image (after zooming in) using the RB event instead of the LB event, but i can't find any information on how to do that. i open an image using cv2.imshow(...) and zoom in on it. Now, holding and dragging the left mouse button i can pan across the image. I would like to enable this behavior when clicking the right mouse button instead.
Catching/handling the RBDOWN event is not an issue, but i don't know what to do afterwards. I would prefer not to use another library if possible (because of multi platform, maintenance and space)
possible solutions i can think of but am not sure how to implement:
- "reroute" RB click to LB click using a click event (this probably needs another library?)
- call the underlying panning function that triggers when LBDOWN+ drag happens (can't find anything on this?)
does anyone have ideas on how to solve this problem?
read tutorials
@LBerger read the question properly please. as explicitly stated, handling the mouse event is not the issue here
is your window like this https://docs.opencv.org/master/Succes...
@sturkmen i dont quite understand your question.Yes my window looks like that,its the normal cv2.imshow(). Are you asking whether i am using Qt?
"Are you asking whether i am using Qt?" yes. i did not use QT before and wondered how did you zoom the image. maybe one way is to change OpenCV c++ source code (change RB event instead of the LB) and rebuild for python. but i have no idea to do that
"read the question properly please. as explicitly stated, handling the mouse event is not the issue here" Explain your problem. Now opencv is an image processing library and not gui library
"reroute RB click to LB click using a click event (this probably needs another library?" use a flag
i dont think changing the library is a good option. I guess i will have to go with something like pyautogui and simulate the LB click, then catch that inside my mouse Callback function...
I consider the OpenCV GUI as a basic solution, mainly for development/debugging purposes. For finished products I would use another library, like Qt (also cross-platform).
Another solution for this problem would be to programatically zoom/pan the image. Define a ROI on the image
im2=im(x0,y0,w,h)
, and display this image. On RB+Drag update thex0,y0
, get a newim2
and display it. A quite simple solution, without messing with the library.@kbarni thanks for your reply. I want to modify an existing project which uses only the openCV GUI, so sadly i can't switch to Qt. Doesn't the opencv gui also use Qt if available though? i couldn't quite figure it out from the source code. But since i can't get a handle for that qt window it probably does not matter. Updating the image and showing only that new ROI seems like a good solution! I've settled on disabling the LB function if RB is clicked, so i can pan using the LB normally.