How can I reduce delay when using timer for capturing 'video' from webcam?

I am trying to make some sort of game which involves the use of the webcam - and i need to get live feed from the webcam - process some of the frames and also display the video I recieve (with some added plots on the image therefore preview is not an option, also i need to flip the image...).
My thought was that if I'll use timed snapshots (using timer) I will recieve a steady fps displayed and will not have to worry about my processing taking long time, but in practice I found out that even with no processing at all - only displaying the images and plotting using timer the program generates a delay.
At the first few seconds it is not noticable but after 10 seconds there is a slight delay, and waiting 10 minutes cause a delay of a second or more.
Anyway my setup for the timer was:
StartDelay 2, Period 0.05-0.3 (tried some values in this range)
ExecutionMode- tried all of them but thought fixedRate should be the best for a steady fps.
BusyMode - drop.
some StartFcn, and a not to heavy to process TimerFcn.
also I was trying to pass a complex structure of data using the UserData field, including the camera, and some state field for the display options.
Would really appreciate some help on this - I haven't found anyone using this method - maybe I was wrong to use it in the first place.
Also, I would like to know if there is a better way to process live feed images and display them other then loop snapshots.
Thanks for the help.

2 件のコメント

Geoff Hayes
Geoff Hayes 2020 年 2 月 14 日
Ron - are you saying that the longer you run your app, the greater the delay in displaying the image (from the webcam)? Could you share a small sample of your code (that demonstrates this behaviour) and in particular, your timer callback?
Ron Sofer
Ron Sofer 2020 年 2 月 15 日
Thank you for your fast reply and for the willingness to help out!
Yes, the delay increased through time.
Anyway, I have just discovered a fix to my problem was using a video player instance and the step function instead of imshow each time the timer tick which fixed all of the problem.

サインインしてコメントする。

回答 (0 件)

製品

リリース

R2017b

質問済み:

2020 年 2 月 13 日

コメント済み:

2020 年 2 月 15 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by