您将无法使用软件获得同步的帧速率,但您可能会获得可接受的结果。基本上,您必须将捕获每一帧所需的时间减少到最低限度,这次设置您的最大帧率(在您的情况下,两个摄像机的帧率/2)。我使用两种技术在 matlab 中实现了可接受的视频录制:
创建一个计时器对象以定期捕获帧。
不要使用getsnapshot。它很慢。相反,配置相机
手动,然后发出触发命令来捕获图像。
这段代码说明了单相机的想法:
function RecordFromCamera
% RECORDFROMCAMERA Captures still images and appends them to a video file
% % Camera setup
cam_fps = 1; % target framerate. Actual performance depends on hardware.
camInfo=imaqhwinfo;
cam = videoinput(camAdaptor,camInfo.DeviceID,camInfo.DefaultFormat);
% setup camera for individual image mode
triggerconfig(cam, 'manual');
set(cam,'TriggerRepeat',Inf);
set(cam,'FramesPerTrigger',1);
% % Timer Object for capturing camera images
camTimer=timer('ExecutionMode','fixedRate','Period',1/cam_fps,'Name','camTimer');
set(camTimer,'TimerFcn',@getCamImage);
% save the camera object for the timer to use
camTimerInfo.cam=cam;
camTimerInfo.video=VideoWriter('camera_video_images.avi','Motion JPEG AVI');
set(camTimer,'UserData',camTimerInfo);
% Test the functionality; capture images for 5 seconds
start(camTimer)
pause(5)
stop(camTimer)
delete(timerfind)
%% sub: getCamImage
function getCamImage(obj,event)
% GETCAMIMAGE gets and saves an image from the camera
% Intended for use as a TimerFcn
disp('getCamImage')
% disp(event.Data) % this will include a timestamp
% the camera handle is stored in the UserData
camTimerInfo=obj.UserData;
% get an image, add it to video file
try
trigger(camTimerInfo.cam);
pic=getdata(camTimerInfo.cam,1);
writeVideo(camTimerInfo.video,pic);
catch imgEx
fprintf(1,'getCamImage: WARNING: camera image acquisition error at %s\n "%s"\n',datestr(now),imgEx.message);
%stop(obj);
end
您需要为第二个摄像头创建第二个摄像头对象,但您可以为这两个摄像头使用相同的计时器对象。您还可以为第二个摄像头创建第二个计时器对象,但不能保证两个计时器执行之间的同步。