MouseCallback Lag

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

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:
        print("Callback!")

cv.namedWindow("Display")
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"):
        break

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

Comments

3

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 -0500 )edit
1

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 -0500 )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 -0500 )edit