I am trying to implement pan and zoom functions in my RTSP camera stream using Python. I want to be able to use my mouse wheel to zoom in and out from the video and click and drag to move the video around. However, I have not been able to find any tutorials on handling these mouse events in OpenCV.
Is there such a way or will I have resort to using keystrokes to pan and zoom my video?
You can use mouse event and imshow to achieve this function.
def mouse_event_callback(self, event,x,y,flags,param):
if event == cv2.EVENT_LBUTTONDOWN:
elif event == cv2.EVENT_MOUSEMOVE:
elif event == cv2.EVENT_LBUTTONUP:
elif event == cv2.EVENT_MOUSEWHEEL:
...
cv2.namedWindow('Test')
cv2.setMouseCallback('Test',self.mouse_event_callback)
while True:
cv2.imshow('Test',img)