Unable to get double click event in OpenCV for python

opencv mouse click events
python get coordinates of mouse click on image
click and crop opencv
python click on image
opencv mouse control python
opencv select roi mouse python
python wait for mouse click
python detect mouse click
OpenCV with python(MAC OS X EL Capitan)

I'm creating a demo project to track mouse events in openCV. using standard mouseCallback from openCV.

following is my code for the same.

drawWithMouse.py

#!/usr/local/bin/local/python3
import numpy as np
import cv2 as cv

#Mouse callback function
def draw_shape(event,x,y,flags,param):
    print("event : ",event)
    if event == cv.EVENT_LBUTTONDBLCLK:
        cv.circle(img,(x,y),100,(255,0,0),-1)

#Create a black image, a window and bind the function to the window
img = np.zeros((780,780,3),np.uint8)
cv.namedWindow('DrawWithMouse')
cv.setMouseCallback('DrawWithMouse',draw_shape)

while(1):
    cv.imshow('DrawWithMouse',img)
    if cv.waitKey(10) & 0xFF == 27: #ANDing with 0xFF as my machine is 64 bit
        break

cv.destroyWindow('DrawWithMouse')

with this implementation i'm always getting mouse down and mouseup event and only single click event. i'm unable to get double click event(EVENT_LBUTTONDBLCLK). value for this constant is 7.

i'm getting following output

You can try to workaround problem with time measurement, for example time.clock() (not precise butthe simplest) and calculation of time difference between click and previous one. If time is less than threshold perform double click action.

time =0
thresh = 1
#Mouse callback function
def draw_shape(event,x,y,flags,param):
  print("event : ",event)
  if event == cv.EVENT_LBUTTONDBLCLK:
    if time.clock - time < thresh:
       //double click
    time = time.clock()
    cv.circle(img,(x,y),100,(255,0,0),-1)

Unable to get double click event in OpenCV for python, OpenCV with python(MAC OS X EL Capitan). I'm creating a demo project to track mouse events in openCV. using standard mouseCallback from openCV. There can be different types of mouse events such as left button click, right button click, double_click, etc. To manage these events we need to design callback functions for each type of mouse click event while the window or frame is opened by OpenCV.The callback function will be helpful to implement what type of functionality you want with a

I just tried running your code, to me everything seems fine. I click down and hold a 1 comes up, I release and there is a 4. When I double click there is a 7. This however doesn't work if the mouse is moving. Try keeping your mouse still while you double click or try another mouse

Unable to get double click event in OpenCV for python, OpenCV with python(MAC OS X EL Capitan) I'm creating a demo project to track mouse events in openCV. using standard mouseCallback from openCV. OpenCV and Python versions: In order to run this example, you’ll need Python 2.7 and OpenCV 2.4.X. Capturing mouse click events with Python and OpenCV. Let’s go ahead and get this example started. Open up a new file, name it click_and_crop.py , and we’ll get to work:

I freshly downloaded opencv-python in El Capitan for Python 3 since I didn't have it:

Downloading opencv_python-3.3.0.10-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (43.8MB)

Ran the example code and left button double click worked fine, creating lots of blue circles. I then tried to make it fail. The only thing I found that came close was setting double click speed to the highest mark in Systems Preferences / Mouse:

I found a significant difference between the highest setting and the second highest. Searching the web, using either the Fast or Slow extreme can be troublesome with double clicking.

Have you verified that your double clicking works in general? Although I can't find it currently, I believe there were once settings that converted double clicks into two individual clicks and other potential Macintosh quirks. Is X-Windows in any way involved with your setup?

Good luck.

How to read a mouse left click event in python?, You can try a workaround with time measurement, for example time.clock () (not accurate, but the easiest) and calculating the time difference between the click  Mouse event can be anything related to mouse like left-button down, left-button up, left-button double-click etc. It gives us the coordinates (x,y) for every mouse event. With this event and location, we can do whatever we like. To list all available events available, run the following code in Python terminal:

For people like me who want to copy-paste:

import time

last_time = None

def double_click(self, event, x, y, flags, params)
    """handle double click"""
    if event == cv2.EVENT_LBUTTONDOWN:

        if last_time is not None and time.time() - last_time < 1:
            cv2.circle(img, (x, y), 20, (255, 0, 0), 2)
           last_time = None
        else:
           last_time = time.time()

You can use the last parameter params to pass your frame when setting the callback:

cv2.setMouseCallback("image", double_click, img)

Capturing mouse click events with Python and OpenCV , For example, I would like to make a code like this: while True: [. not explain how to have Python only recognize the mouse left click event. can't seem to get the code to work: def mouse(event,x,y,flags,param): if event == cv2. In this blog post I'll show you how to capture mouse events using Python and OpenCV. Using these techniques you'll be able to crop your image by selecting a rectangular region of the image using

Temporary simple hack (until someone comes up with a real answer):

Change event from 'EVENT_LBUTTONDBLCLK' to any non double click events (e.g. 'EVENT_LBUTTONDOWN')

OpenCV-Python/mouse_callback.py at master · abidrahmank , Capturing mouse click events with Python and OpenCV. by Adrian Rosebrock on It means not being able to drive to the gym. And it means being stuck in Python and OpenCV. Let's go ahead and get this example started. Drawing shapes on image file with mouse event. Contribute to farcompen/Opencv-drawing-with-mouse development by creating an account on GitHub.

Mouse as a Paint-Brush, Contribute to abidrahmank/OpenCV-Python development by creating an Find file Copy path A simple example about generating mouse callback function. It is targeted on an absolute beginner.This program just print the coordinates in the terminal when you double click at any You can't perform that action at this time. These Mouse events include mouse clicks (like left-button down, left-button up, left-button double-click etc) and movements over an attached OpenCV window. Capturing mouse click events with Python

How to Detect Mouse Clicks and Moves, Learn to handle mouse events in OpenCV; You will learn these functions : cv2. a simple application which draws a circle on an image wherever we double-click on it. Next we have to bind this mouse callback function to OpenCV window. Capturing mouse click events with Python and OpenCV – PyImageSearch. opencv python. Follow. Best Python Courses online, If you’re looking to move into the

Python mouse click event, All you have do is to define a callback function in the OpenCV C++ code attaching to the OpenCV window. That callback cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl; } //if fail to read the image This is what we will do in this blog i.e. write text on images at mouse click position. To do this, we will create a mouse callback function and then bind this function to the image window. Mouse callback function is executed whenever a mouse event takes place. Mouse event refers to anything we do with the mouse like double click, left click etc.

Comments
  • I'd tried this on two different computers. Both are MAC machines.
  • And I'm unable to get double click on any of them with two different mouse.
  • @RajendrasinhParmar the same occurs to me on macos
  • @Fred did you found any solution?
  • i tried that. it's long time now. i should try it again. as everything is updated now in my system.
  • I think this might be related to some other problem related to MAC pointing device driver and OpenCV interaction. However, your solution for EVENT_LBUTTONDOWN seems to do the trick.