Ask Your Question
0

How can i set mouse callbacks to different windows with python

asked 2018-02-20 14:02:10 -0600

Nonso gravatar image

I am working on a project that will require me to have two OpenCV windows,i want to set callbacks for the different windows,how do i go about it using python

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-02-20 15:02:33 -0600

LBerger gravatar image

use tutorials and specifcally here

import numpy as np
import cv2 as cv
# mouse callback function
def draw_circle1(event,x,y,flags,param):
    if event == cv.EVENT_LBUTTONDBLCLK:
        cv.circle(img1,(x,y),100,(255,0,0),-1)
def draw_circle2(event,x,y,flags,param):
    if event == cv.EVENT_LBUTTONDBLCLK:
        cv.circle(img2,(x,y),100,(0,255,0),-1)
# Create a black image, a window and bind the function to window
img1= np.zeros((512,512,3), np.uint8)
cv.namedWindow('image1')
cv.setMouseCallback('image1',draw_circle1)
img2 = np.zeros((512,512,3), np.uint8)
cv.namedWindow('image2')
cv.setMouseCallback('image2',draw_circle2)
while(1):
    cv.imshow('image1',img1)
    cv.imshow('image2',img2)
    if cv.waitKey(20) & 0xFF == 27:
        break
cv.destroyAllWindows()
edit flag offensive delete link more

Comments

Thanks @LBerger

Nonso gravatar imageNonso ( 2018-02-22 07:29:45 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-20 14:02:10 -0600

Seen: 1,622 times

Last updated: Feb 20 '18