I'm having trouble recording frames from a live video and saving each frame to a playable avi file. I get the error "Operands to the || and && operators must be convertible to logical scalar values."
I'm using Matlab 2018a version, and the video input is using a frame grabber device with serial and cameralink connection.
% Specifies the Range of Interest
if exist('ROI','var') % Becomes True if the ROI variable was assigned in the function
CurROI = vid.ROIPosition; % Specifies Region of Interest(ROI) window
vid.ROIPosition = [max(0,ROI(1)),max(0,ROI(2)),min(ROI(3),CurROI(3)),min(ROI(4),CurROI(4))]; % Creates boundaries for ROI window
end
% Creates a video file from an array or file of images
diskLogger = VideoWriter(FileNameVideo,'Uncompressed AVI'); % VideoReader
diskLogger.FrameRate = 10; % Sets the framerate of the recorded and saved avi video file
set(vid,'Timeout',50);
% Starts the video
open(diskLogger);
preview(vid);
start(vid); % Triggers the acquisition of the live video
data = getdata(vid,vid.FramesAvailable,'uint8');
writeVideo(diskLogger,data)
implay(data);
%Close, stop, and end the video
close(diskLogger); % Closes the file the video was saved to
stop(vid); % Stops the triggering of the live camera feed
stoppreview(vid)
I had an earlier version that showed the same error.
for ii = 1:numFrames % Loops through each frame of the live camera feed saved
writeVideo(diskLogger, data(:,:,:,ii)); % writes each frame of the live feed to a video file
end
This replaced the writevideo line. IF there is any solution to this, I need it as soon as possible. Any ideas?

7 commentaires

Walter Roberson
Walter Roberson le 5 Juin 2019
I do not see anything obviously wrong. Please post the complete error message showing the traceback.
Cordelia David
Cordelia David le 5 Juin 2019
Modifié(e) : Cordelia David le 5 Juin 2019
Sure, sorry about that. There seems to be a problem with the text inside of the for loop.
Warning: No video frames were written to this file. The file may be invalid.
> In VideoWriter/close (line 270)
In VideoWriter/delete (line 205)
In Video_File (line 30)
In InitializationScript (line 60)
Error using VideoWriter/writeVideo (line 402)
Operands to the || and && operators must be convertible to logical scalar values.
Error in Video_File (line 50)
writeVideo(diskLogger,data)
Error in InitializationScript (line 60)
Video_File(vid, NumFrames, FileNameVideo, ROI ); % Function will play and save the live camera
feed to an avi video file and delete from the Matlab workspace
There is a script that calls the function Video_File where this is all written, but there isn't anything wrong with the script.
Walter Roberson
Walter Roberson le 5 Juin 2019
You using the default frames per trigger count of 1, and by default triggers are configured to go immediately when you start(). But you are not delaying to give time to acquire, so the frames available could be 0, and that triggered frame might not arrive until after you tell it to read all 0 of the available frames.
Cordelia David
Cordelia David le 5 Juin 2019
So if I set the framespertrigger of the videoinput = NumFrames, (wherein NumFrames is greater than 1) and include a delay start (how would I do that??) then I should be able to get data, which will mean the matrix has something to write to the disklogger? I think that's how I'm understanding it.
Cordelia David
Cordelia David le 6 Juin 2019
Thank you Walter I'll give this a try!
Cordelia David
Cordelia David le 6 Juin 2019
Modifié(e) : Cordelia David le 6 Juin 2019
After implementing the manual trigger and wait period the software worked very well for some cameras, however sometimes I get the error
Error using imaqdevice/wait (line 120)
WAIT reached its timeout before OBJ stopped running.
Error in Video_File (line 46)
wait(vid,10); % Delays saving video so images have been acquired
Error in InitializationScript (line 57)
Video_File(vid, NumFrames, FileNameVideo, ROI ,Pattern); % Function will play and save the
live camera feed to an avi video file and delete from the Matlab workspace
I tried lengthening the wait time period or stopping the video before the wait command, but that doesn't seem to work. Is this a problem with the output of my camera, or with the code?
The code:
diskLogger = VideoWriter(FileNameVideo,'Uncompressed AVI');
diskLogger.FrameRate = 30; % Sets the framerate of the recorded and saved avi video file
set(vid,'Timeout',50);
open(diskLogger);
preview(vid); % Opens a window with a preview of the video
start(vid); % Starts the video
stoppreview(vid);
trigger(vid); % Triggers the acquisition of the live video
wait(vid,10); % Delays saving video so images have been acquired
data = getdata(vid,vid.FramesAcquired,'uint8');
writeVideo(diskLogger,data)
implay(data);
Edit: After reading information about the command wait() I realized I wasn't acquiring all images I had commanded the triggers to acquire because of a delay between when the camera started sending frames and my code started acquiring and saving it. To fix this, I simply added 100 frames to the number of frames the camera would send, so it was a little extra than what my code would acquire. There's probably a simpler and easier way to do this, but hey, it works.
Thank you for all the help and time @Walter Roberson, your answers helped immensely!

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by