2

I am using the CreateTrackBar function in OpenCV to create a trackbar. But I don't want any callback to happen on change. I will be doing that in a separate loop where I get the trackbar value using cv2.getTrackbarPos(). But Python returns an error if I don't give a callable function as an argument to CreateTrackBar(). The documentation for OpenCV says :

If the callback is the NULL pointer, no callbacks are called, but only value is updated.

I am guessing that is for the C++ implementation. Is there a similar null pointer or a null or None function in Python? I understand that I can just make a function that does nothing. Just seeing if there is a more elegant way of doing this. I tried None and got the error that None is not callable.

import cv2
cv2.namedWindow("Window")
cv2.createTrackbar("Value", "Window", 100, 255, None)

#Do stuff here in a while loop

cv2.waitKey(0)
cv2.destroyAllWindows()
abhigdeal
  • 162
  • 3
  • 9

1 Answers1

1

I think you might just need to define a quick function. You can use an anonymous lambda and avoid explicitly defining a function to return None:

cv2.createTrackbar("Value", "Window", 100, 255, lambda x:x)
mschoder
  • 44
  • 3