poster
2019-12-10, 16:49
我想知道如何使用网络摄像头在MATLAB中录制视频。
回答:
注意: 由于某些较旧的功能已被取代并删除,因此现在已更新此版本以与新版本的MATLAB一起使用。
如果您已经知道如何从网络摄像头捕获单个图像 (https://stackoverflow.com/q/1467692/52738) ,则只需将图像缝合在一起即可。您可以使用VideoWriter对象 (https://www.mathworks.com/help/matlab/ref/videowriter.html)打开影片文件,然后使用writeVideo (https://www.mathworks.com/help/matlab/ref/videowriter.writevideo.html)方法添加连续图像。例如:
aviObject = VideoWriter('myVideo.avi'); % Create a new AVI file for iImage = 1:100 % Capture 100 frames % ... % You would capture a single image I from your webcam here % ... writeVideo(aviObject, I); % Add the image to the AVI file end close(aviObject); % Close the AVI file 我只是使用了for循环作为简单示例,但是如果您想捕获图像并将其以固定的时间间隔添加到AVI文件中,则可能需要使用timer (https://www.mathworks.com/help/matlab/ref/timer-class.html) 。
更多&回答... (https://stackoverflow.com/questions/1637589)
回答:
注意: 由于某些较旧的功能已被取代并删除,因此现在已更新此版本以与新版本的MATLAB一起使用。
如果您已经知道如何从网络摄像头捕获单个图像 (https://stackoverflow.com/q/1467692/52738) ,则只需将图像缝合在一起即可。您可以使用VideoWriter对象 (https://www.mathworks.com/help/matlab/ref/videowriter.html)打开影片文件,然后使用writeVideo (https://www.mathworks.com/help/matlab/ref/videowriter.writevideo.html)方法添加连续图像。例如:
aviObject = VideoWriter('myVideo.avi'); % Create a new AVI file for iImage = 1:100 % Capture 100 frames % ... % You would capture a single image I from your webcam here % ... writeVideo(aviObject, I); % Add the image to the AVI file end close(aviObject); % Close the AVI file 我只是使用了for循环作为简单示例,但是如果您想捕获图像并将其以固定的时间间隔添加到AVI文件中,则可能需要使用timer (https://www.mathworks.com/help/matlab/ref/timer-class.html) 。
更多&回答... (https://stackoverflow.com/questions/1637589)