Friday, 5 February 2016

Philip O Connor Sprint 1 Face detection with threading:

Team Pi Over Four :

The section of the design which I was involved in was the initial testing of the lampbotics project face detection using threads. I was tasked with generated the python script with detects a persons face. Then based on these values which need to be global variables when using threading so that these values can be passed between different threads. In my example I use three separate threads which are on for detecting faces, second for controlling the servos and the last for generating the sounds.
Shown below are the results obtained from testing:

There are three key points of interest which can be observed from this test which are:
  1. To minimize processing requirements instead of displaying the image the image is constantly saved when the face detection thread gets executed. 
  2. The main while loop operates by first initializing the the three threads which specifies at what stage each thread will be executed for example if one threads was set to 1 and another set to 3 then this would mean that the second thread will get execute upon the 3 cycle of the while loop. Next these threads need to be started and are allocated a time slot in which to execute its process. Note that these times are quit important as they set the time to execute a process and if their has not been enough time allocated and will not allow sections of the process to be completed.
  3. Due to the fact that the camera display isn't being displayed print statements are used to visually observe that an action has been taken for example when the sound gets played for a specific position a sound test if if statement number gets printed out. 
The prints statements would be excluded for a finale design and are only included to test the different sections of the code. The execution of the spidev which is used to execute the movement of the servos can be installed in the virtual environment by entering the following commands:

source ~/.profile
workon cv 
pip install
Problems found:
A problem which I encountered while using threads was when the face tracking thread was getting executed it would print up the following error message:

 This problem was due to the fact that the pi camera initialization command (camera=PiCamera()) would get executed each time the thread was called and is only required to be initialized once upon execution of the python script. So then by placing this command at the start of the script where the variables initialized resoled this issue. 

Another problem which was was encountered was running time of the program which is initially slow because of the fact print statements are used to specified when a section of code is executed but is only required for initial testing and further work would remove these to speed up the system.  

Team Pi Over Four 
Philip O Connor entry 3, 

No comments:

Post a Comment