using peekdata or getdata for live video stream

Hi,
I'm having a lot of trouble processing frames from a continuous feed in real time. I want to first get the pixel data from each 100th frame using either the peekdata function or the getdata function. However, my code only seems to return the information for one frame rather than every hundred frames. This is what I came up with so far:
while isrunning(vid) == 1
if mod(vid.FramesAcquired,100) == 0
for i = vid.FramesAcquired/100
Frame100(i) = peekdata(vid,1);
regionsprops(Frame100(i));
end
end
end
Does anyone have any insight?

Answers (1)

peekdata() returns a height by width by bands by frames numeric matrix. You are trying to store that matrix into a single location Frame(i) . That is going to cause an error unless you have set your ROI to be a single pixel on a greyscale image.

6 Comments

Thank you very much for the reply; I appreciate it! I tried changing that line to :
while isrunning(vid) == 1
if mod(vid.FramesAcquired,100) == 0
for i = vid.FramesAcquired/100
Frame100(:,:,:,i) = peekdata(vid,1)
regionsprops(Frame100(i));
end
end
end
However, I am still encountering some problems that may or may not have to do with indexing.
1. Matlab doesn't wait for the if statement condition to be satisfied before running subsequent lines. (runs subsequent lines before every hundredth frame is acquired)
2. A warning comes up indicating that peekdata could not return all the frames requested even when vid.FramesAcquired exceeds the number of frames in the peekdata command.
3. Image processing is quite slow even though I attempt to log data in both memory and disk.
I would really appreciate any advice you may have on these issues if possible.
I meant to write:
regionprops(Frame100(:,:,:,i))
for the last line of code.
You do not assign the results of regionprops() to anything so it is not clear why you call it there?
The loop you are doing does not process every 100 frames. The loop you are doing asks, at each time, whether it just happens to be the case that right now a multiple of 100 frames has been read in. Suppose that last time you tested FramesAcquired had been 199 but then because the looping takes time, two frames are returned to the buffer before the next test, so FramesAcquired is now 201, then you would not do any processing of frame #200.
"The number of frames available to peekdata is determined by recalling the last frame returned by a previous peekdata call, and the number of frames that were acquired since then."
This implies that if you want to peek a frame you cannot peek with a lower frame count and then go back to peek with a larger count to get more of the recent frames.
But I think I am getting confused here. What is the state of the Running property at the time you are trying to do the peekdata ?
Hello!
I apologize for asking any questions that should have obvious answers but thank you for putting the potential issues with the if statement into context. Does that mean that there is no fool proof way to do any analysis of every nth frame? Should I possibly consider doing something like this (I'm mostly way off base):
if mod(vid.FramesAcquired,100) == 0
data = peekdata(vid,100);
% find the nearest 100th frame
framevalue = vid.FramesAcquired-mod(vid.FramesAcquired,100);
%find average of frames
avgdata (framevalue,:) = mean(data);
analysis = regionprops(avgdata(framevalue,:));
As for the running property is, there is live video input coming in so the variable "vid" is running during the time that I am trying to process the incoming frames.

Sign in to comment.

Asked:

on 16 Jan 2018

Commented:

on 18 Jan 2018

Community Treasure Hunt

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

Start Hunting!