新建图形用户界面:“新建”>“图形用户界面”
从左侧选择控件,添加到面板
双击空间进行属性设置,“string”为显示名称,“tag”为id。将两个axes的“visable“属性设置为”off“
更改”.m“文件:
function varargout = untitled1(varargin)
% UNTITLED1 MATLAB code for untitled1.fig
% UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing
% singleton*.
%
% H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to
% the existing singleton*.
%
% UNTITLED1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED1.M with the given input arguments.
%
% UNTITLED1('Property','Value',...) creates a new UNTITLED1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled1_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled1
% Last Modified by GUIDE v2.5 12-Mar-2015 20:53:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled1_OpeningFcn, ...
'gui_OutputFcn', @untitled1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', [])
if nargin &&ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1})
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:})
else
gui_mainfcn(gui_State, varargin{:})
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled1 is made visible.
function untitled1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObjecthandle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handlesstructure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled1 (see VARARGIN)
% Choose default command line output for untitled1
handles.output = hObject
% Update handles structure
guidata(hObject, handles)
% UIWAIT makes untitled1 wait for user response (see UIRESUME)
% uiwait(handles.figure1)
% --- Outputs from this function are returned to the command line.
function varargout = untitled1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT)
% hObjecthandle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handlesstructure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output
global vid
vid = videoinput('winvideo')
%set(vid,'ReturnedColorSpace','grayscale')
function pushbutton1_Callback(hObject, eventdata, handles)
axes(handles.axes1)
global vid
vidRes = vid.VideoResolution
nBands = vid.NumberOfBands
hImage = image( zeros(vidRes(2), vidRes(1), nBands) )
preview(vid, hImage)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObjecthandle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handlesstructure with handles and user data (see GUIDATA)
axes(handles.axes2)
global vid
f=getsnapshot(vid)
imshow(f)
6
点击运行,单击”preview“进行预览,单击”snapshot“捕获图像
首先打开已经注册过的MATLAB软件,界面如图。如何利用MATLAB调用USB摄像头并显示图像
通过imaqhwinfo函数查看电脑上视频设备。
如何利用MATLAB调用USB摄像头并显示图像
选择‘winvideo’,并将设备信息赋值给变量info,
如何利用MATLAB调用USB摄像头并显示图像
返回的也是一个结构体,将设备的信息赋值给dev_info,
如何利用MATLAB调用USB摄像头并显示图像
同样返回的是一个结构体,我想需要的是设备的ID和其支持的分辨率,查看SupportedFormats中的详细信息.
如何利用MATLAB调用USB摄像头并显示图像
下面就可以创建视频输入对象了,定义为vid,vid函数有好几种形式,我们选择视频为最大分辨率,将显示设备的一些信息。
如何利用MATLAB调用USB摄像头并显示图像
使用preview函数即可将图像数据显示在屏幕上,preview(vid).
如何利用MATLAB调用USB摄像头并显示图像
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)