Panning image window programmatically [closed]

asked 2019-09-07 02:31:06 -0600

fogx gravatar image

updated 2019-09-07 04:44:31 -0600

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?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-01 11:11:17.846959

Comments

LBerger gravatar imageLBerger ( 2019-09-07 03:27:34 -0600 )edit

@LBerger read the question properly please. as explicitly stated, handling the mouse event is not the issue here

fogx gravatar imagefogx ( 2019-09-07 04:11:26 -0600 )edit
sturkmen gravatar imagesturkmen ( 2019-09-07 04:57:00 -0600 )edit

@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?

fogx gravatar imagefogx ( 2019-09-07 05:30:48 -0600 )edit

"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

sturkmen gravatar imagesturkmen ( 2019-09-07 05:41:15 -0600 )edit

"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

LBerger gravatar imageLBerger ( 2019-09-07 05:57:05 -0600 )edit

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...

fogx gravatar imagefogx ( 2019-09-07 06:06:09 -0600 )edit

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 the x0,y0, get a new im2 and display it. A quite simple solution, without messing with the library.

kbarni gravatar imagekbarni ( 2019-09-09 09:28:08 -0600 )edit

@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.

fogx gravatar imagefogx ( 2019-09-10 03:35:17 -0600 )edit