Pick up the (10) day of MATLAB

Matlab camera photo acquisition

Camera opening code

Sentence to turn on the camera:

obj =videoinput('DeviceName',1,'YUY2_640*480');
  • DeviceName is your available audio and video input device.

  • "1" means an open device.

  • YUY2_640*480 represents a format.

Format configuration

set(obj,'ReturnedColorSpace','rgb')

The configuration format is RGB format.

preview(obj);

Get image

getphoto = getsnapshot(obj);
filename = int2str(1);
filename = [filename,'jpg']
inwrite(getphoto,filename);

Turn off the camera

stop(obj);
closepreview(obj);
delete(obj);
clear;

About the problem

1. Use obj =videoinput('DeviceName',1,'YUY2_640*480'); after
using videoinput incorrectly (line 217)
Invalid ADAPTORNAME specified. Type'imaqhwinfo' for a list of available ADAPTORNAMEs. Image acquisition adaptors may be available as downloadable support packages. Open Support
Package Installer to install additional vendors.
The reason for this problem may be that you are using the wrong DeviceName, or the installed version of Matlab lacks plug-ins. So first find the corresponding device name, use:

info=imaqhwinfo

The following message will appear:

info = 

    InstalledAdaptors: {
    
    }
        MATLABVersion: '8.3 (R2014a)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '4.7 (R2014a)'

There should be a device name in InstalledAdaptors, but it doesn't. This proves that it is because of the lack of plug-ins. So look at the error message above again,

Support Package Installer 

This sentence is underlined, click on it, the plug-in download interface will appear, just download and install. Finally, you can see the device when it is running

info = 

    InstalledAdaptors: {
    
    'dcam'}
        MATLABVersion: '8.3 (R2014a)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '4.7 (R2014a)'

The name of my device is dcam.
Finally, the code for a camera to take an image in 0.5s is given:

clear;
clc;
obj =videoinput('winvideo',1);
set(obj,'ReturnedColorSpace','rgb');
preview(obj);
for i=1:10
getphoto = getsnapshot(obj);
filename = int2str(i);
filename = [filename,'.jpg']
imwrite(getphoto,filename);
pause(0.5);
end
stop(obj);
closepreview(obj);
delete(obj);
clear;

Guess you like

Origin blog.csdn.net/qq_42312125/article/details/108333041