请帮我写一段用matlab 调用usb摄像头的代码
时间: 2024-05-09 15:18:30 浏览: 96
Sure, I can help with that! Here's a sample code in MATLAB for accessing a USB camera:
```matlab
% Initialize the camera
cam = webcam;
% Set the resolution of the camera
cam.Resolution = '640x480';
% Preview the camera stream
preview(cam);
% Capture and save images from the camera
for i = 1:10
img = snapshot(cam);
filename = sprintf('image%d.jpg',i);
imwrite(img,filename);
end
% Close the camera
clear('cam');
```
This code will allow you to access and capture images from a connected USB camera. Remember to replace the resolution value and file names according to your needs. Let me know if you have any other questions!
阅读全文
相关推荐















