# [face recognition] grayscale classroom population statistics based on matlab GUI [including Matlab source code 602]

Posted by paulrichards19 on Sat, 19 Feb 2022 06:56:26 +0100

## 1, Introduction

1 subject background
This topic is a population statistics system based on matlab. In recent years, many industries have great demand for people flow information, such as bus stops, subway stations, shopping malls, entrances and exits, etc. Through the population statistics system, the flow of people in various places can be counted conveniently, reliably and in real time without any impact on the public. Combined with other image analysis technologies, the system can clearly and quickly grasp the dynamics of passenger flow, provide data support, and enable decision-makers to make countermeasures in time. The main advantage of using image processing to complete the population statistics system is that the image signal is very intuitive and easy to understand. It can be seen that the image population statistics is of great significance in both commercial information collection and public security monitoring. The research on the image population statistics recognition algorithm has attractive development prospects both in theory and in practical application.
2 subject analysis
In the past, teachers basically counted students' attendance by manual roll call, but this method often wastes a lot of time and is inefficient, which is not a good choice. This topic, based on MATLAB classroom population statistics, with rich human-computer interaction GUI interface. Count and count the number of people in the classroom, and then count the attendance rate and the proportion of listening carefully in class. The original preset total number of people, no attendance or books covering the face, lying on the mobile phone, etc. will not be able to collect the face, so the corresponding number is missing, and the attendance rate or listening rate is obtained. The subject uses the principle of skin color for face location and face segmentation. In this topic, in order to make the GUI interface beautiful, the segmented face is deliberately displayed separately in the axes corresponding to the GUI.
3. Social demand analysis
(1) For students: they have separated from the devil like learning in high school and entered the palace of colleges and universities. Many college students have disordered work and rest time, and the situation of class arrival is not ideal. Absenteeism and absenteeism seriously affect academic performance. A few students went out to play during class and had accidents. Let students develop a good work and rest habit and standardize students' attendance is one of the things that many colleges and universities want to do most. Therefore, fast and effective attendance statistics are very important for college students' learning and learning.
For teachers, statistics of attendance is an effective way to record students' course learning process, provide the basis for usual performance evaluation, and reduce the risk of accidents. Most of the traditional methods of investigating attendance are time-consuming and laborious, which not only wastes valuable classroom time, but also adds a burden to teachers.
In order to illustrate the necessity of developing this project - classroom personnel statistics system, we analyze the traditional way of investigating attendance.
(a) Roster roll call
The teacher or teacher asks a student to use the roster to call the names in sequence.
Advantages: every student should answer that teachers can have more opportunities to know each student, which truly reflects the students' arrival in class.
Disadvantages: if the number of students is large, it will waste a lot of valuable time of students and teachers, and there are situations that other students can help answer.
(b) Roll call
During the first class, the teacher shall use the roster to call the names in sequence, and the students who do not arrive shall be marked. In the next class, first point the students who have not arrived several times before, and then point several students at random.
Advantages: the random roll call method saves a lot of time and exerts appropriate pressure on those students who fail to attend the roll call. The students who are absent from class are basically absent There are "old faces" in the classroom. This method can make those students dare not skip class again.
Disadvantages: the first roll call still takes a lot of time. There are many "luck" elements in the random roll call method. Some students may not come often Class, but not found.
Let all the students sit at the front and fix seats for each student in the class. After class, count the list of absentees.
Advantages: the teacher can clearly see the attendance of students in class. Students' seats close to the podium can improve students' attention in class.
Disadvantages: college students should often change classrooms in class. The practice of fixing seats will bring a lot of inconvenience with the change of classrooms.
(d) Grouping statistics
The students in the class are divided into several groups. Each group selects a group leader. The group leader determines the arrival of the group members. After class, the group leader gives the list to the teacher.
Advantages: it saves teachers' time and is convenient for discussion and learning in groups.
Disadvantages: there may be the situation that the group leader covers up the group members, and the teacher cannot determine the true attendance rate of students.
In order to understand college students' acceptance of this project - classroom personnel statistics system, we used questionnaire star to conduct a questionnaire survey on freshmen to seniors. The following is the analysis of the survey results:
The survey results show that the traditional roll call accounts for 72.13%, the software check-in accounts for 19.03 and the others account for 9.84%. It can be seen that the traditional roll call accounts for the majority of the investigation methods, and there is still no way to completely replace it.
In this project, only 9.67% of the participants would care about the problem of the right of portrait, while 49.34% didn't care at all. Most of them did not consider this issue, accounting for 40.98% of the total number. It can be seen that ignoring a few, it can be considered that counting the number of people by taking photos can be accepted by most people.
When asked about the advantages and disadvantages of this project, 57.38% of the participants thought that this method was fast, 30.17% convenient and 12.45% others. Among the problems they are worried about, they are worried that inaccurate statistics will lead to "being" absent from work, accounting for up to 83.61%.
In conclusion, we believe that a more efficient way than traditional roll call is needed. This project is intended to fill this gap. Improving system performance and reducing errors are the key to enhance the practicability of classroom personnel statistics system.
5 introduction to computer vision system toolbox
Computer Vision System Toolbox (CVST) is the toolbox of Matlab2012b version. The toolbox not only includes algorithms for feature extraction, motion detection, target detection, target tracking, stereo vision, video processing and video analysis, but also includes video file input and output, video display, drawing and synthesis. These functions are provided in the form of Matlab functions, Matlab system objects and Simulink blocks. For rapid prototyping and embedded system design, the toolbox supports fixed-point algorithm and C code generation.
The face detection algorithm of computer vision system toolbox is mainly based on Viola Jones's face detection, which can automatically detect faces, even nose, mouth and eyes through built-in classes and functions. Viola Jones face detection is a face detection algorithm jointly proposed by Paul viola and Michael J Jones. The algorithm has the advantages of simple principle and low resource consumption. After being proposed, it is widely used in face detection. Viola Jones face detection mainly includes Haar like feature, integral graph, AdaBoost iterative algorithm and cascade classifier. The main steps to realize face detection are: ① use Haar like rectangular feature to represent the face, and use "integral graph" to quickly calculate the rectangular feature in the image. ② AdaBoost algorithm is used to train the classifier needed for face detection from a large number of Haar like features. ③ The trained strong classifiers are cascaded, and the cascaded strong classifiers are used to form the final classifier.
The computer vision system toolbox only needs a simple command to realize face detection. Call vision. In the toolbox The cascadeobjectdetector is ready to run. Not only the running speed is fast, but also the accuracy of face detection is very high. After self improvement, batch processing can be carried out.

6 scheme design
6.1 frame design
The function of the project is to realize automatic face detection and population statistics according to the given pictures. It is required to include GUI interface, and the algorithm can accurately realize population statistics. It has fast operation speed and good real-time performance.

6.2 interface design
First, set the page background to gray white, and set two coordinate systems axes1 and axes2 in the center and left page to display the later selected pictures and the pictures with faces framed after face recognition. Drag and drop pushbutton1, pushbutton2, edit1, text1 and pushbutton2 from top to bottom on the right side of the coordinate system. Among them, the words "open classroom picture" are edited on pushbutton1 to complete the function of opening picture; Edit the words' statistical results' on edit1; The results of 'statistical results' are displayed in text4; Edit 'statistics' on pushbutton2, and click this button to realize the function of statistics; Edit the word "finish" on the last pushbutton3 to complete the closing function. A text2 is also set above the coordinate axis to edit 'welcome to the classroom population statistics system' as the title. So far, the interface design of the page is completed.

6.3 function design
For the pushbutton1 button, click "open classroom picture" to open the file selection dialog box by using uigetfile function standardization. At this time, the file interface of this computer will pop up. After selecting a picture with people, click OK to display the selected picture on axes1, and set the title "classroom picture" above this picture to complete the function of selecting pictures. Secondly, click the "count the number of people" button, get the relevant data of the open picture in the code, convert the color image into gray image, etc., set the path and display the converted image in axes2. In addition, you can find the face in the picture, draw the frame and circle it, and count the number of frames and reflect it in text1, The title 'frame face area' is set above this image. So far, all functions of this design are completed. The following figure shows the functional flow chart of the project:

Figure 1 function flow chart

## 2, Source code

```function varargout = face_collection(varargin)
% FACE_COLLECTION MATLAB code for face_collection.fig
%      FACE_COLLECTION, by itself, creates a new FACE_COLLECTION or raises the existing
%      singleton*.
%
%      H = FACE_COLLECTION returns the handle to a new FACE_COLLECTION or the handle to
%      the existing singleton*.
%
%      FACE_COLLECTION('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FACE_COLLECTION.M with the given input arguments.
%
%      FACE_COLLECTION('Property','Value',...) creates a new FACE_COLLECTION or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before face_collection_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to face_collection_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%

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

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

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

% Update handles structure
guidata(hObject, handles);

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

% --- Outputs from this function are returned to the command line.
function varargout = face_collection_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 edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double

% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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 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 I
[x,y,c]=ginput(2);
if c==1
BB=imcrop(I,[min(x(1),x(2)),min(y(1),y(2)),abs(x(2)-x(1)),abs(y(2)-y(1))]);
BB=imresize(BB,[252 202]);
axes(handles.axes2); % The processed image is placed in axes2 in
imshow(BB)
end

function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 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)
[filename, pathname] = uigetfile( ...
{'*.jpg;*.png;*.jpeg', 'Image Files (*.bmp;*.jpg;*.png;*.jpeg)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick an image');
if isequal(filename,0) || isequal(pathname,0),
return;
end
```

## 4, Remarks

Complete code or add QQ 1564658423

Topics: MATLAB image processing