⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webcam.asv

📁 是一个在matlab下的机器人运动仿真的软件
💻 ASV
字号:
function varargout = WebCam(varargin)
% WEBCAM M-file for WebCam.fig
%      WEBCAM, by itself, creates a new WEBCAM or raises the existing
%      singleton*.
%
%      H = WEBCAM returns the handle to a new WEBCAM or the handle to
%      the existing singleton*.
%
%      WEBCAM('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in WEBCAM.M with the given input arguments.
%
%      WEBCAM('Property','Value',...) creates a new WEBCAM or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before WebCam_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to WebCam_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

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help WebCam

% Last Modified by GUIDE v2.5 20-Dec-2006 22:28:24

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @WebCam_OpeningFcn, ...
                   'gui_OutputFcn',  @WebCam_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 WebCam is made visible.
function WebCam_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 WebCam (see VARARGIN)


set(handles.figure4,'Color',[0.16 0.2117  0.36]);
% Choose default command line output for WebCam

[a,map,b]=imread('_Iniciar.JPG');
set(handles.pbfaz,'CData',a);

set(handles.uipanel1,'Title','Aquisi玢o de Imagens');
set(handles.uipanel3,'Title','Detec玢o de Cores');
set(handles.uipanel2,'Title','Detec玢o de Movimento'); 
set(handles.textMovDetec,'String','N鉶'); 

global rc gc bc
rc=0;
gc=0;
bc=0;
set(handles.corselect,'BackgroundColor',[rc gc bc]);

global s
s=1;
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

   


% UIWAIT makes WebCam wait for user response (see UIRESUME)
% uiwait(handles.figure4);

% --- Outputs from this function are returned to the command line.
function varargout = WebCam_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;







function Red_Callback(hObject, eventdata, handles)
% hObject    handle to Red (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Red as text
%        str2double(get(hObject,'String')) returns contents of Red as a double
global rc gc bc

r = str2num(get(handles.Red,'String'));
if(r<0 || r>255)
   errordlg('Valor fora da Gama ','Erro','on')
   set(handles.Red,'String',' '); %limpar a caixa
else
rc=r/255;
set(handles.corselect,'BackgroundColor',[rc gc bc]);
end
% --- Executes during object creation, after setting all properties.
function Red_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Red (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Green_Callback(hObject, eventdata, handles)
% hObject    handle to Green (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Green as text
%        str2double(get(hObject,'String')) returns contents of Green as a double
global rc gc bc

g = str2num(get(handles.Green,'String'));
if(g<0 || g>255)
   errordlg('Valor fora da Gama ','Erro','on')
   set(handles.Green,'String',' '); %limpar a caixa
else
gc=g/255;
set(handles.corselect,'BackgroundColor',[rc gc bc]);
end

% --- Executes during object creation, after setting all properties.
function Green_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Green (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Blue_Callback(hObject, eventdata, handles)
% hObject    handle to Blue (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Blue as text
%        str2double(get(hObject,'String')) returns contents of Blue as a double
global rc gc bc

b = str2num(get(handles.Blue,'String'));
if(b<0 || b>255)
   errordlg('Valor fora da Gama ','Erro','on')
   set(handles.Blue,'String',' '); %limpar a caixa
else
bc=b/255;
set(handles.corselect,'BackgroundColor',[rc gc bc]);
end

% --- Executes during object creation, after setting all properties.
function Blue_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Blue (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pbfaz.
function pbfaz_Callback(hObject, eventdata, handles)
% hObject    handle to pbfaz (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.output = hObject;

global s

R = str2num(get(handles.Red,'String'));
G = str2num(get(handles.Green,'String'));
B = str2num(get(handles.Blue,'String'));


s=1;
x=0; 
rel1=0;
rel=0;
vfm('show',0);
%**************Aquisi玢o de imagem*************************
A=vfm('grab',1);
while (s==1) 
  %  pause(0.01);
    B=vfm('grab',1);
%                           Cb=A(:,:,3);
%                           Cr=A(:,:,1);
%                           Cg=A(:,:,2);
    axes(handles.axes1);    
    %subplot(2,2,1);
    image(A);
    axis off;    
    axes(handles.axes2);
    image(B);
    axis off;  
    axes(handles.axes3);
    %diferen鏰 entre duas imagens consecutivas
    C=B-A;
    image(C);
    axis off;
    A=B;
%    tic
   %somat髍io dos elementos da diferen鏰 entre duas imagens consecutivas
    D=sum(C);
    E=sum(D);
    F=sum(E);
 %   toc
 % *****************detectar movimento*********************
  set(handles.textMovDetec,'string','N鉶');
    if F>350000%480x640/2500000%3200000
             %   x=x+1;
                set(handles.textMovDetec,'string','Sim');
              %  tic;
    else set(handles.textMovDetec,'string','N鉶');
    end
    
    %*******************detectar cor****************************
    %laranja 210/150/190
    %vermelho caneta 255/110/160
%     R=200;
%     G=20;
%     B=40;
    k=0;
    si=0;
    sj=0;
    filtR=50;   %pode ser constante
    filtG=30;   % //   //   //
    filtB=50;   % //   //   //

%     for i=1:240
%         for j=1:320
%             if (A(i,j,1)>=R-filtR & A(i,j,1)<=R+filtR &...
%                A(i,j,2)>=G-filtG & A(i,j,2)<=G+filtG &...      
%                A(i,j,3)>=B-filtB & A(i,j,3)<=B+filtB)
%                 si=si+i;
%                 sj=sj+j;
%                 k=k+1;
%             end
%         end
%     end
    
%     si=si/k;
%     sj=sj/k;
%      hold on;
%     plot(sj,si,'*');  %Testar
%     axis off;
%     
% hold off;
    
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -