【图像识别】基于机器视觉颜色识别系统matlab 源码

一、简介

二、源代码

function varargout = maingui(varargin)
% MAINGUI M-file for maingui.fig
%      MAINGUI, by itself, creates a new MAINGUI or raises the existing
%      singleton*.
%
%      H = MAINGUI returns the handle to a new MAINGUI or the handle to
%      the existing singleton*.
%
%      MAINGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MAINGUI.M with the given input arguments.
%
%      MAINGUI('Property','Value',...) creates a new MAINGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before maingui_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to maingui_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 maingui

% Last Modified by GUIDE v2.5 03-Mar-2008 14:56:06

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

% warning off;

splash('thirdeye.kon','png');

axes(handles.axes2); %initialise axes where color will be displayed
img = im2uint8(zeros([128 128 3])); %set it to black color initially
handles.h2 = image(img);
axis off;

axes(handles.axes1);%initialise axes where preview will be displayed
axis off; drawnow;

axes(handles.axes1);
handles.h1 = imshow(im2uint8(ones([240 320 3])));%intial white colored image on the axis


try %intialise sound card for sound alert
    [y,Fs] = wavread('warning.wav');% read a warning wave file
    handles.player = audioplayer(y, Fs);
catch %if sound card not present display following error message
    errstr = lasterr;
    h2 =  errordlg(['Sound Card Not Present OR ' errstr] ,'Sound Card Error');
    setWindowOnTop(h2,'true');
end

handles.guifig = gcf;


try
    if exist('startupdata.mat','file') %load startup data. This contains information about initial conditions set. If not found GUI will load its default values
        load startupdata
        set(handles.animation,'Checked',animation);
        set(handles.sound_alert,'Checked',sound_alert);
        set(handles.auto_hide,'Checked',auto_hide);
        set(handles.on_top,'Checked',on_top);
        if strcmp(get(handles.on_top,'Checked'),'on')
            setWindowOnTop(handles.guifig,'true');
        end        
    end
catch
    errordlg(lasterr);
end

handles.displayperiod = 2; %pause for the amount specified

handles.tmr = timer('TimerFcn', {@TmrFcn,handles.guifig},'BusyMode','Queue',...
    'ExecutionMode','fixedRate','Period',0.1);%intialise a Timer Function

    
guidata(handles.guifig, handles);

% Choose default command line output for maingui
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes maingui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


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

% ---Executes on Timer Event
function TmrFcn(src,event,handles)
handles = guidata(handles);

pause(handles.displayperiod);%pause for the number of seconds intialised initially

str = [pwd '\product images'];%product images stored here
names = dir([str '\*.jpg']);
rand_num = random_integer_generator(1,numel(names),1);%generates  a random number from the number of JPG files present in the product directory
handles.reference_image = imread([str '\' names(rand_num,1).name]);% reads any one random image

drawnow;
set(handles.h1,'CData',handles.reference_image);% displays the randome image on the axis

if strcmp(get(handles.auto_hide,'Checked'),'on')
    setWindowState(handles.guifig,'restore'); %sets the gui figure to restore
    drawnow;
end


if isfield(handles,'second') %the color from first variable is stored in variable second. Not true while startup
    if ~strcmp(handles.first,'NOCOLOR')
        handles.second = handles.first;
    end
end

%%%%%%%%%%%%%%%%%%COLOR MATCHING FUNCTION
[output_color output_image] = validate_color_new(handles.reference_image,handles.data);%new main function for finding color match
%%%%%%%%%%%%%%%%%%%%
set(handles.color_text,'string',upper(output_color)); %sets the string value the name of the color

img = im2uint8(zeros([128 128 3])); %create a img file which can display the color
val = output_image(round(size(output_image,1)/2),round(size(output_image,2)/2),:);
val = squeeze(val)';
img(:,:,1) = val(1);
img(:,:,2) = val(2);
img(:,:,3) = val(3);
set(handles.h2,'CData',img);drawnow; %outputs the color on this img

handles.first = output_color; %store the output color in first variable


if ~strcmp(output_color,'NOCOLOR') %if color cannot be identified from the stored colors then dont give audiovisual indication
    if ~isfield(handles,'second') %check condition in first run, if condition is not satisfied then second varaible = first variable
        handles.second = output_color;
    end

    if ~strcmp(handles.first,handles.second) %if colors are different then do the following activity

        try%necessary if sound card is not present
            if strcmp(get(handles.sound_alert,'Checked'),'on')%give and alert only if sound_alert is set to on
                play(handles.player);
            end
        catch
            errordlg(lasterr);
        end

        if strcmp(get(handles.animation,'Checked'),'on') %do the animation if animation is set to on
            model_color(output_color);%calls a model wearing the color.Default time duration of 3 seconds
        end


    end
end

    if strcmp(get(handles.auto_hide,'Checked'),'on')
        pause(handles.displayperiod);%pause for the number of seconds intialised initially
        setWindowState(handles.guifig,'minimize'); %sets the gui figure to minimize        
    end


if strcmp(get(handles.auto_hide,'Checked'),'off')%This is useful to keep a pause of the same time irrespective of auto hide on or off
    pause(handles.displayperiod);%pause for the number of seconds intialised initially
end


三、运行结果

【图像识别】基于机器视觉颜色识别系统matlab 源码_第1张图片
【图像识别】基于机器视觉颜色识别系统matlab 源码_第2张图片
【图像识别】基于机器视觉颜色识别系统matlab 源码_第3张图片

四、备注

完整代码或者代写添加QQ1575304183

往期回顾>>>>>>

【图像识别】国外车牌识别matlab源码

【图像识别】基于svm支持向量机算法表情识别matlab源码

【图像识别】基于cnn卷积神经网络之验证码识别matlab源码

【图像识别】基于svm植物叶子疾病检测和分类matlab源码​​​​​​​

【图像识别】路面裂缝识别含GUI源码matlab源码​​​​​​​

【图像识别】基于RGB和BP神经网络的人民币识别系统含GUI界面matlab源码​​​​​​​

【图像识别】条形码识别系统matlab源码​​​​​​​

【图像识别】基于不变矩的数字验证码识别含GUI界面matlab源码​​​​​​​

【图像识别】基于模板匹配之手写数字识别系统GUI界面matlab源码​​​​​​​

【图像识别】基于贝叶斯分类器之目标识别matlab源码

【图像识别】身份证号码识别matlab源码

【图像识别】条形码识别系统matlab源码​​​​​​​

【模式识别】基于特征匹配的英文印刷字符识别matlab源码

【图像分类】基于极限学习分类器对遥感图像分类matlab源码​​​​​​​

【图像识别】基于BP神经网络之字母识别matlab源码

【图像特征处理】指纹图像细节特征提取matlab源码

【图像识别】基于反馈神经Hopfield的数字识别matlab源码

【图像识别】基于二值膨胀差分和椒盐滤波之教室内人数识别系统matlab源码

【图像识别】火灾检测matlab源码GUI

【模式识别】基于 Hough变换视频车道线检测matlab源码​​​​​​​

【模式识别】基于matlab Hough变换图片车道线检测

【模式识别】基于差影法之三维人体姿态行为识别matlab源码

【模式识别】指针式表盘识别matlab源码

【图像识别】表情检测matlab源码

【图像检测】基于LSD直线检测matlab源码

【图像识别】基于帧差法跌倒检测matlab源码

【图像识别】基于组合BCOSFIRE过滤器进行墙体裂缝识别matlab源码

【图像边缘检测】基于插值法亚像素边缘检测matlab源码

【模式识别】基于贝叶斯最小错误率手写数字识别matlab 源码

【模式识别】基于PCA手写数字识别matlab 源码

【模式识别】基于模板匹配的手写体数字识别matlab源码

【图像识别】基于模板匹配车牌识别matlab源码含GUI

【图像识别】基于模板匹配之人脸表情识别matlab源码含GUI

【图像识别】基于LBP+LPQ算法融合人脸表情识别matlab源码

【图像识别】基于HSV和RGB模型水果分类matlab源码含 GUI

【图像识别】基于模板匹配之数字识别matlab源码

【图像识别】基于BP神经网络的手写字体识别matlab源码含GUI界面

【图像识别】基于ksvd字典学习之人脸表情识别matlab源码

【图像识别】基于ORL数据库的PCA人脸识别系统matlab源码

【图像检测】基于 gabor滤波器布匹瑕疵检测matlab源码

【图像识别】基于yolo v2深度学习检测识别车辆matlab源码

你可能感兴趣的:(matlab,图像处理)