Ask Your Question

Revision history [back]

MouseCallback Lag

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?