Authors: Normal Team - Dmytro Koziy, Inesa Hermaniuk, Nazar Mamchur
Published: May 2018
Applies to: Normal Smart Device
Summary: This paper provides an overview of how Normal Smart Device users can set up the person identification smart system based on a Raspberry Pi 3, using this API.
This section provides an information to help you succesfully set up Raspberry Pi to get a powerful portable camera.
- Raspberry Pi 3
- MicroSD card with cappacity 8GB or more
- USB webcam
- Set up your Raspberry Pi 3 - install OS by following this guide
- Install Python 3.6
$ sudo apt-get install python-dev
$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
- Install numpy
$ pip install numpy
-
Install OpenCV by following this guide
-
Install subversion
$ sudo apt-get install subversion
- Download Device folder with code from Github repository.
$ cd
$ svn checkout https://github.com/Dmytruto/NormalSmartDevice/trunk/Device
- Make program run at a startup:
- Open rc.local file:
$ sudo nano /etc/rc.local
- Add the following line there
sudo python /home/Device/detection.py &
You need to import module in a file you want to use it in
import Device.detection as FDR
FDR.detect(img)
Parameter: img - image, where you want to detect a face and crop it out.
Return type - numpy.array
The function detect(img) detects face on an image and returns a croped and grayScaled image of a face if it was detected, or a numpy.array([0]) if not.
FDR.process()
Parameter: void
Return type - void
The function process() contains a while True loop which takes 2 photos on webcam per second, converts an image to the base64 String.
FDR.request(str)
Parameter: str - String, you want to send to the server
The function request(str) sends request with the str String to the server and returns its response.
This section provides an information to help you succesfully set up a server, which can recognize a human face and determine if this person is in the data base.
-
Install python 3.6.
-
Install, create and activate your virtual environment in the Recognition folder by following this guide:
-
Install the required modules:
$ pip install django==2.0.5
$ pip install djangorestframework==3.8.2
$ pip install opencv-python==3.4.0.12
$ pip install opencv-contrib-python==3.4.0.12
$ sudo apt-get install subversion
- Download Recognition folder with code from Github repository.
$ cd path/to/your/dir
$ svn checkout https://github.com/Dmytruto/NormalSmartDevice/trunk/Recognition
First of all you need to import our module in file where you want to use it.
import Recognition.FacialRecognition.CreateTrainingDataAndTrainModel as CTD
This function creates a directory named faces which will be contain a sub folders with photo set. In input this function takes the directory name and creates the subfolder with inputted name.
CTD.create_directory(sub_directory_name)
In input this function has the image. if this image contains faces, function will returns grayscaling cropped face from this image.else it will return emty list.
CTD.face_extractor(img)
This function reads images from your web cam and if face is on image it saves the image in subfolder that you have already created. In input this function takes number of photo which you want to be in your data set.
CTD.start_creating_data_set(quantity)
This function create histograms from all images in subfolder and save this histogram in json file. In input this method has name of trained model. In order to program work successfully file_name must be the same as sub_directory_name.
CTD.trainModel(file_name)
!To create data set and trained model on this data you have to execute this functions in the same order that It had been written on this article!
Import reconizer which have already trained on the Data Set.
import Recognition.FacialRecognition.FaceRecognition as FR
In input this function takes human face image and compare it with faces which had been used to create DataSet. If face on the input image is similar to one of the faces in data set, function will return true, else false.
FR.face_recognizer(face_image)
In order to use face recognizer firstly you need create data set and train model
There are two possible ways how to run server in your computer:- Using terminal
- Activate your virtual environment.
- Move to the server folder and run the following command:
$ python manage.py runserver
- Using PyCharm
- Open project, that you cloned.
- Go to File - Settings - Project - Project Interpreter and add local interpretener, choosing path to Scripts/python.exe in the folder with your virtual environment.
- Go to Run - Edit Configurations and add new configuration:
Name: Django Run Server
(If there is already configuration with name 'Django Run Server', edit only 'Python interpreter')
Script path: \your\path\to\Recognition\server\manage.py
Parameters: runserver
Python interpreter: *choose that, what you have created*
- Run 'Django Run Server'.
Server is mapping a POST request with a text file, in which there is an encoded photo, by the method post.
def photo(request):
if request.method == 'POST' and request.FILES['file']:
Request shoud be sent to http://{host}:{port}/mapping/photo. If server is run on the local machine, this url looks like http://localhost:8000/mapping/photo.
Server sends back one of the String responses, which are provided by the recognition algorithm:
*name* allowed
Not allowed
The image, which was got during the last request mapping, is saved to the uploaded_image folder.
!Check if everything is installed in the correct folders and all paths are proper!