您现在的位置:首页 >> 机器学习 >> 内容

m基于CNN卷积神经网络的口罩识别系统matlab仿真,带GUI操作界面,可以检测图片和视频,统计人

时间:2023/8/25 15:59:15 点击:

  核心提示:0Y_001m,包括程序操作录像...

1.完整项目描述和程序获取

>面包多安全交易平台:https://mbd.pub/o/bread/ZJ2WmJ1r

>如果链接失效,可以直接打开本站店铺搜索相关店铺:

点击店铺

>如果链接失效,程序调试报错或者项目合作可以加微信或者QQ联系。

2.部分仿真图预览


3.算法概述

       基于卷积神经网络(CNN)的口罩识别系统是一种用于自动检测人们是否佩戴口罩的技术。在COVID-19疫情爆发以来,这样的系统变得尤为重要,因为佩戴口罩已成为一种重要的健康防护措施。

4.部分源码

function varargout = tops(varargin)

% TOPS MATLAB code for tops.fig

%      TOPS, by itself, creates a new TOPS or raises the existing

%      singleton*.

%

%      H = TOPS returns the handle to a new TOPS or the handle to

%      the existing singleton*.

%

%      TOPS('CALLBACK',hObject,eventData,handles,...) calls the local

%      function named CALLBACK in TOPS.M with the given input arguments.

%

%      TOPS('Property','Value',...) creates a new TOPS or raises the

%      existing singleton*.  Starting from the left, property value pairs are

%      applied to the GUI before tops_OpeningFcn gets called.  An

%      unrecognized property name or invalid value makes property application

%      stop.  All inputs are passed to tops_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 tops

 

% Last Modified by GUIDE v2.5 23-Aug-2023 23:37:39

 

 

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name',       mfilename, ...

                   'gui_Singleton',  gui_Singleton, ...

                   'gui_OpeningFcn', @tops_OpeningFcn, ...

                   'gui_OutputFcn',  @tops_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 tops is made visible.

function tops_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 tops (see VARARGIN)

 

% Choose default command line output for tops

handles.output = hObject;

 

% Update handles structure

guidata(hObject, handles);

 

% UIWAIT makes tops wait for user response (see UIRESUME)

% uiwait(handles.figure1);

 

 

% --- Outputs from this function are returned to the command line.

function varargout = tops_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 button press in pushbutton1.

function pushbutton1_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton1 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

global im;

cla (handles.axes1,'reset')

cla (handles.axes2,'reset')

set(handles.edit1,'string',num2str(0));

set(handles.edit2,'string',num2str(0));

set(handles.edit3,'string',num2str(0));

load CNNmask.mat

axes(handles.axes1);

[filename,pathname]=uigetfile({'*.bmp;*.jpg;*.png;*.jpeg;*.tif'},'选择一个图片','F:\test');

str=[pathname filename];

% 判断文件是否为空,也可以不用这个操作!直接读入图片也可以的

% im = imread(str);

% imshow(im)

if isequal(filename,0)||isequal(pathname,0)

    warndlg('please select a picture first!','warning');

    return;

else

    im = imread(str);

    imshow(im);

end

 

 

% --- 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)

global im;

load CNNmask.mat

 

img_size     = [227,227];

frameCount   = 0;

FDetect      = vision.CascadeObjectDetector;

picture      = im;

orig_picture = picture;

BB           = step(FDetect, picture);

frameCount   = frameCount+1;

axes(handles.axes2);

 

cnt0=0;

cnt1=0;

if size(BB,1) >= 1 

    for faces_iter = 1:size(BB,1)  

        picture_cropped = imcrop(orig_picture,BB(faces_iter,:));

        picture_resized = imresize(picture_cropped,img_size);

        label = classify(net, picture_resized); 

        label_text = char(label);

 

 

        if strcmp(label_text, 'no_mask')

            text_color = 'red';

            line_color{faces_iter} = 'r';

            cnt0=cnt0+1;

        end

        if strcmp(label_text, 'mask')

           text_color = 'green';

           line_color{faces_iter} = 'g';

            cnt1=cnt1+1;

        end

         label_text

         line_color

         image(picture); 

         axis off;

    end

    for faces_iter = 1:size(BB,1)  

        rectangle('Position', BB(faces_iter,:), 'Linewidth',2,'LineStyle','-','EdgeColor',line_color{faces_iter});

        hold on

    end

else 

    image(picture);

    picture = imresize(picture,img_size);  

    axis off

end

 

 

set(handles.edit1,'string',num2str(size(BB,1)));

set(handles.edit2,'string',num2str(cnt1));

set(handles.edit3,'string',num2str(cnt0));

% --- Executes on button press in pushbutton3.

function pushbutton3_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton3 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

global vid;

global numFrames;

cla (handles.axes1,'reset')

cla (handles.axes2,'reset')

load CNNmask.mat

set(handles.edit1,'string',num2str(0));

set(handles.edit2,'string',num2str(0));

set(handles.edit3,'string',num2str(0));

 

 

axes(handles.axes1);

[filename,pathname]=uigetfile({'*.mp4'},'选择一个视频','F:\test');

str=[pathname filename];

% 判断文件是否为空,也可以不用这个操作!直接读入图片也可以的

% im = imread(str);

% imshow(im)

if isequal(filename,0)||isequal(pathname,0)

    warndlg('please select a picture first!','warning');

    return;

else

    vid = VideoReader(str);

    numFrames = vid.NumFrames;

    for i = 1:1:numFrames

        picture = read(vid,i);

        image(picture); 

        drawnow;

    end

end

 

 

 

 

 

% --- Executes on button press in pushbutton4.

function pushbutton4_Callback(hObject, eventdata, handles)

% hObject    handle to pushbutton4 (see GCBO)

% eventdata  reserved - to be defined in a future version of MATLAB

% handles    structure with handles and user data (see GUIDATA)

global vid;

global numFrames;

load CNNmask.mat

    img_size = [227,227];

    frameCount = 0;

FDetect = vision.CascadeObjectDetector;

axes(handles.axes2);

....................................................................................

0Y_001m

---

作者:我爱C编程 来源:我爱C编程
本站最新成功开发工程项目案例
相关评论
发表我的评论
  • 大名:
  • 内容:
本类固顶
  • 没有
  • FPGA/MATLAB商业/科研类项目合作(www.store718.com) © 2025 版权所有 All Rights Reserved.
  • Email:1480526168@qq.com 站长QQ: 1480526168