Sporadic error with FramesAcquiredFcn and getdata

8 次查看(过去 30 天)
I'm encountering a sporadic error with getdata inside a FramesAcquiredFcn callback during video acquistion. I am attempting to record the time of frame grabs, similar to this question (link), though with absolute time instead of time relative to the start of frame capture.
Here is the code I am using to create and start the video acquisition object:
vidObjFLIR = videoinput('gentl', 1);
vidObjFLIR.FramesPerTrigger = inf; % Continuous acquisition
vidObjFLIR.LoggingMode = 'disk&memory'; % Log data to disk
vidObjFLIR.FramesAcquiredFcnCount = 1;
vidObjFLIR.FramesAcquiredFcn = {'framesAcquiredTimeStamp'};
DiskLogger = VideoWriter('video', 'Motion JPEG AVI');
DiskLogger.Quality = 50;
vidObjFLIR.DiskLogger = DiskLogger;
start(vidObjFLIR)
Here is my FramesAcquiredFcn callback function:
function framesAcquiredTimeStamp(obj, event)
try
[~, ts, meta] = getdata(obj);
catch
[~, ts] = getdata(obj);
ts
obj
[~, ts, meta] = getdata(obj);
end
for i = length(meta)
obj.UserData = [obj.UserData;meta(i).AbsTime];
end
end
Typically this code will run correctly for a few frames, then error with the following message:
Error using imaqdevice/getdata (line 164)
Invalid input argument of type 'double'. Input must be a structure or a Java or COM object.
Error in framesAcquiredTimeStamp (line 10)
[~, ts, meta] = getdata(obj);
Whenever it errors, it displays the value of ts and it isn't empty, so getdata is able to retreive the relative time stamp. Furthermore, when it errors, the obj is still a video acquisition object, so I don't know why the error is saying it is a double. I tried to look at the code of getdata, but I don't understand what it is doing well enough to figure out why this is happening. Since the relative time stamp seems to always record properly, I could work up some wonky system to try to get an absolute time stamp for one frame, then record all the relative time stamps, then convert them to absolute time, but that seems annoying. I'd appreciate any suggestions people might have about how to resolve this error. Thanks!
~Nick

回答(1 个)

Kanishk
Kanishk 2024-9-20
Hi Nick,
I understand you want to record the accurate timestamps of each frame in absolute time.
To accurately record the timestamps while using the “FrameAcquiredFcn” callback, you can utilize the “event.Data.AbsTime” property. This approach ensures that you capture the precise timestamp for each frame.
Below is the modified “framesAcquiredTimeStamp function:
function framesAcquiredTimeStamp(obj, event)
obj.UserData = [obj.UserData;event.Data.AbsTime];
end
This function appends the absolute timestamp of each acquired frame to the “UserData property of the video input object.
To verify the correctness of the recorded timestamps, you can compare the number of frames acquired with the size of the “UserData array. This ensures that each frame's timestamp is accurately captured.
Please go through this official MATLAB documentation of ‘videoinput’ to learn more about it. https://iwww.mathworks.com/help/releases/R2024a/imaq/videoinput.html
Hope this helps!!
Thanks

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by