I have a OpenCV program written in python which tracks the position of a ball and uses a webcam as the input.
How would I now implement a function, that can get the position of the ball only when it's called (i.e. by a keyboard event).
The problem is that the OpenCV algorithm is running in a while loop which would have to be killed before I can call another function.
I'm still kinda new to python and therefore don't know whether or not this is a dumb question.
Thanks in advance!
Add a comment
|
1 Answer
Yep, it's doable! You can get keyboard input from cv2.waitKey(milliseconds).
import cv2
# make it brighter
def brighten(img):
img[:,:,:] += 10;
# get image
img = cv2.imread("image.jpg");
# loop
done = False;
while not done:
# do processing stuff
# show image
cv2.imshow("Image", img);
key = cv2.waitKey(1);
# check for keypresses
done = key == ord('q'); # when q is pressed
if key == ord('b'):
brighten(img);