您将无法使用软件获得同步帧率,但您可能能够获得可接受的结果。基本上你必须减少捕获每帧所需的时间到最小,这次设置你的最大帧速率(在你的情况下,两个摄像机的帧率/ 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
您需要创建第二相机的第二相机的对象,但你可以使用同一个定时器对象两者。您也可以为第二台摄像机创建第二个计时器对象,但不保证两个计时器执行之间的同步。
您正面临一个非平凡的挑战,尤其是选择一种不支持多线程的编程语言。对于MATLAB我不知道任何解决方案。如果您愿意切换到simulink,您可以快速构建解决方案。使用两个[从视频设备](http://www.mathworks.com/help/imaq/saving-video-data-to-a-file.html)块并连接输出以获得连接两个数据的宽屏视频。然后你可以很容易地检查它是否真的是同步录制的,例如在两台摄像机前放置一些东西,并确认两者在同一高度。 – Daniel