Image processing while video streaming

2 views (last 30 days)
Adrian Lim
Adrian Lim on 27 Jun 2018
Edited: Florian Morsch on 2 Jul 2018
Greeting to the community, I have a few questions for image processing while video streaming for a smart traffic light project in my diploma. The main idea is to take a picture every 10 frame or a second and calculate the number of cars.There is a problem that I'm facing which is i can't get the picture periodically. As I start the video, the image remains the same and could not change after 10 frames or a second.
The code that I'm currently trying out are
vid = videoinput('winvideo', 1)
set(vid,'FramesPerTrigger',1)
set(vid,'TriggerRepeat',Inf)
FrameGrabInterval = 10
start(vid)
img=getdata(vid)
imshow(img)
The image that is shown stucked at the first image, is there any ways to fix this or an easier way to grab image and futher process it? Thanks in advance.

Answers (1)

Florian Morsch
Florian Morsch on 2 Jul 2018
Edited: Florian Morsch on 2 Jul 2018
If this is your code then of course you will only have shown the first picture, since there is no loop to show the new image. Your code gets the video input, set different camera settings, starts the video, get the data one time and displays them.
Now if you want to show the new data you will have to repeat the process of getting the data and show them again.
Is it important to show only one image every 1 second? Because if not you could just run a loop and show a new image when your code is done.
Something like:
vid = videoinput('winvideo', 1)
set(vid,'FramesPerTrigger',1)
set(vid,'TriggerRepeat',Inf)
FrameGrabInterval = 10
start(vid)
FrameCounter = 0;
while(FrameCounter<1000)
FrameCounter=FrameCounter+1;
img=getdata(vid)
imshow(img)
end
This loop runs for 1000 frames. Now if you only want a new frame every 1 second you could just add a pause into the loop with "pause = 1;", you could design your loop with a different condition to take a picture... There are a few options to achieve this.
EDIT: Depending on your camera (webcam? wlan-cam? something else?) you could also work with a video player object. You then take a picture and step it through the video player.

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!