0

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!

0

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.