新人求助,matlab调用摄像头

 我来答
huanglenzhi
2016-08-20 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117538 获赞数:517195
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部
  首先确定安装好了摄像头的驱动,打开“应用程序”>“image acquisition”查看

  新建图形用户界面:“新建”>“图形用户界面”

  从左侧选择控件,添加到面板

  双击空间进行属性设置,“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.
  % hObject handle to figure
  % eventdata reserved - to be defined in a future version of MATLAB
  % handles structure 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);
  % hObject handle to figure
  % eventdata reserved - to be defined in a future version of MATLAB
  % handles structure 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)
  % hObject handle to pushbutton2 (see GCBO)
  % eventdata reserved - to be defined in a future version of MATLAB
  % handles structure with handles and user data (see GUIDATA)
  axes(handles.axes2);
  global vid;
  f=getsnapshot(vid);
  imshow(f);

  6
  点击运行,单击”preview“进行预览,单击”snapshot“捕获图像
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式