Ask Your Question
0

while (1) { } and camera FPS

asked 2020-03-27 11:24:34 -0600

andrei186 gravatar image

the code samples using a camera I've seen so far read:

while (1) {      
 Mat frame;
 camera >> frame;
 if (frame.empty()) break;
     imshow("Webcam", frame);
 }

How does this interact with the camera FTP rate? The loop executes (I guess) in microseconds while a standard webcam delivers about 50ftp, i.e. 1 frame in 20 msec. Does the loop somehow waits for the next frame or keeps executing the same every microsecond uselessly overloading CPU? Do I need to somehow synchronize the loop with the camera FPS?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-03-27 13:50:02 -0600

mvuori gravatar image

If you read the documentation for >> operator of VideoCapture, you will see the description: "Stream operator to read the next video frame." Reading a whole frame obviously requires waiting for the frame to come available and reading until the whole frame has been read. So there's the balancing system: the bottleneck is either the back end's FPS or the speed of reading and processing the frames.

edit flag offensive delete link more

Comments

The reason I posted this question is exactly me reading this documentation and getting confused. What happens if the bottleneck is the back end's FPS? And it is not only camera FPS but also USB speed which may not cope with FPS multiplied by frame size. Does the loop somehow waits for the next frame or keeps executing the same every microsecond uselessly overloading CPU?

If the bottleneck is the speed of reading and processing the frames then what? Will some frames get lost? Or they queue untill certain queue length and then the whole thing collapses? Or VideoCapture will generate some "slow down" command to the camera, if the camera is able to execute such command?

andrei186 gravatar imageandrei186 ( 2020-03-27 14:25:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-03-27 11:24:34 -0600

Seen: 267 times

Last updated: Mar 27 '20