0

I have a script I'm testing:

import cv2

cap = cv2.VideoCapture(config['camera_number'])
frame_width = cap.get(3)
frame_height = cap.get(4)

print('w: ' + str(frame_width) + ', h: ' + str(frame_height))

while(True):
    ret, frame = cap.read()
    cv2.imshow('preview', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cap.destroyAllWindows()

I thought my code would run in order. However, the first thing I see is the preview window. When I close it by pressing "q", it then prints the frame width and height. Why is this?

Cit5
  • 400
  • 5
  • 19
  • Possible duplicate of [python delayed execution of print command?](https://stackoverflow.com/questions/4699186/python-delayed-execution-of-print-command) – FlyingTeller Sep 10 '18 at 07:38
  • Concurrently means "in parallel" not in sequence, which I think you meant, unless there is some other threading going on that isn't showed here? – alkasm Sep 11 '18 at 06:32
  • How are you running this and where are you getting the output? – alkasm Sep 11 '18 at 06:49
  • I am running the script through command line. The output is: first my window pops up with my camera displaying video. Once I closed the window by pressing `q`, then the terminal prints the text. – Cit5 Sep 12 '18 at 02:38

0 Answers0