MouseCallback Lag

asked 2015-06-27 20:17:54 -0600

I'm running OpenCV 3 on Python 3.4 on a 2015 15" MacBook Pro. Below is a minimal example that illustrates my problem:

import cv2 as cv
import numpy as np

def mouse_callback(event, x, y, flags, param):
    if event == 1:

cv.setMouseCallback("Display", mouse_callback)

while True:
    img = np.zeros((512,512,3), np.uint8)
    cv.imshow("Display", img)

    if cv.waitKey(1) == ord("q"):

When I click on the black screen, the text "Callback!" takes about one second to appear on the terminal screen, although sometimes the delay is up to three seconds, and other times there is little delay. Additionally, I wrote a similar program in C++, and found that the C++ OpenCV libraries also suffer from this lag.

Any tips on how I can reduce or eliminate the lag?

edit retag flag offensive close merge delete



this should not happen in the 1st place (and does not here, on win)

i'd rather suspect, there's something murky with your build. which gui toolkit do you use there ?

berak gravatar imageberak ( 2015-06-28 01:33:48 -0600 )edit

Yeah, I just tested the exact same code on Ubuntu, and the problem doesn't occur. I'm honestly not sure which GUI toolkit I'm using--how would I check that?

Shivam Sarodia gravatar imageShivam Sarodia ( 2015-06-29 01:10:41 -0600 )edit

First guess, your repaint method of your gui interface is called in fixed intervals, thus the delay is occuring, but in fact it is not... how to fix this however, no idea...

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-29 07:59:49 -0600 )edit