scieee AI-readable full text Open interactive document viewer

Implementation of computer vision algorithms for the CASPER Robot

Capelo Ramon, Daniel

Abstract

Se desea iniciar el trabajo y estudio de algoritmos de computer vision sobre la plataforma robótica CASPER. Estos algoritmos deben de aunarse con el resto de componentes de procesado del robot.

Full text

Final Master Thesis MASTER’S DEGREE IN AUTOMATIC CONTROL AND ROBOTICS Implementation of Computer Vision Algorithms for the CASPER Robot MEMORY Author: Daniel Capelo Advisor: Dr. Cecilio Angulo Date: September, 2017 Escuela Técnica Superior de Ingeniería Industrial de Barcelona 1 Abstract The present document takes as starting point the CASPER project which developed a social pet robot to help learn social skills children with Autism Spectrum Disorder. The previous status of the project allows adding computer vision functionality which can help to differentiate between children and adults or even between different children, as far as it can establish different modes of operation for the robot. Different function modes will have different tasks to execute and also different priorities for these. In consequence, it can optimize the use of the processor. Due to the system is based on a low cost processor, it is very important to test all the computer vision algorithms in order to find a good balance between efficiency and lightness, as well as the selection of a suitable camera for the good acquisition and management of images. In parallel, the system needs a tool for proper Robot-Human Interaction not only during its main function, but also to ease the maintenance, diagnostics or even for changes and further development over the unit. To achieve this result, it has been created a Human-Machine Interface which allows to make changes over the cognitive variables and monitoring the status of the sensors and the actuators of the robot. The present work is focused on obtaining an efficient implementation regarding the computer vision operation and also the addition of the Human-Machine Interface. Both goals are aligned with the previous objectives of the project, and the applications are developed as modules of the system and following the structure of the original design. 2 3 Contents P’agina Abstract........................................ 1 Indexoffigures.................................... 5 Indexoftables .................................... 7 Acronyms ....................................... 9 1 Introduction 11 1.1 Motivation.................................... 11 1.2 Objectives.................................... 11 1.3 Scope ...................................... 12 2 Background and State of the Art 15 2.1 SocialRobots .................................. 15 2.2 Human Robot Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 2.3 Human Machine Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.4 Benchmark ................................... 20 2.4.1 PLEOrb ................................ 20 3 Human Machine Interface 23 3.1 Introduction................................... 23 3.2 Softwaredeveloped ............................... 25 3.2.1 Organization into ROS . . . . . . . . . . . . . . . . . . . . . . . . . 26 3.2.2 Description of the Script through Pseudo-code . . . . . . . . . . . . 27 3.3 Hardwareinvolved ............................... 28 3.3.1 CPU................................... 28 3.3.2 Screen.................................. 29 3.3.3 SensingHardware............................ 29 3.3.4 MotionHardware............................ 31 4 Computer Vision System 37 4.1 Requirements .................................. 37 4.2 Motion Detection Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 38 4 4.2.1 LogicUsed................................ 38 4.3 Face Recognition Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . 40 4.3.1 FaceDetection ............................. 40 4.3.2 FaceRecognition ............................ 41 4.3.3 Training................................. 41 4.4 Facial Expressions Recognition . . . . . . . . . . . . . . . . . . . . . . . . . 42 5 Software Performance 49 5.1 ComputationalCosts.............................. 49 5.2 Vision Algorithms Accuracy . . . . . . . . . . . . . . . . . . . . . . . . . . 52 6 Costs 55 6.1 Time....................................... 55 6.2 Budget...................................... 56 6.2.1 MaterialCost.............................. 57 6.2.2 PersonalCost.............................. 57 Environmental impact 59 Conclusions 61 Acknowledgement 63 Bibliography 65 5 List of Figures 1.1 Previous ROS architecture. Figure extracted from the Master’s Thesis of ThomasHerpoel. ................................ 13 1.2 Proposed ROS architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.1 Examples of an industrial robot and a social robot. Image a) www.masteringros.com, Image b) www.wowwee.com . . . . . . . . . . . . . . . . . . . . . 15 2.2 Anthropomorphic mobile robots developed in UPC, www.upc.edu. . . . . . 17 2.3 Example of complex robot control panel, www.hotfrog.in. . . . . . . . . . . 18 2.4 Example of ‘command line’ interface, www.xmodulo.com. . . . . . . . . . . 19 2.5 Example of WIMP Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . 19 2.6 Example of Post-WIMP Interface, www.en.wikipedia.org . . . . . . . . . . 20 2.7 Pleo rb, www.pleoworld.com . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.1 Scheme of the HMI’s menus. . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.2 MainMenuwindow. .............................. 24 3.3 Log in and Cognitive Variables windows. . . . . . . . . . . . . . . . . . . . 25 3.4 TestProtocolWindow.............................. 26 3.5 GamingWindow................................. 26 3.6 Sensing Message structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.7 Considerations about screen. . . . . . . . . . . . . . . . . . . . . . . . . . . 29 3.8 Schematic connection between MPR-121 to Arduino UNO. . . . . . . . . . 30 3.9 Schematic connection between MPU-6050 to Arduino UNO. . . . . . . . . 30 3.10 Schematic connection of Arduino UNO and both sensors. . . . . . . . . . . 31 3.11 Tri-State buffer circuit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.12 SMPS2Dynamixel, stabilizer voltage device. . . . . . . . . . . . . . . . . . 32 3.13 Scheme of the complete motion circuit connection. . . . . . . . . . . . . . . 33 4.1 Results of the Movement_det.py. . . . . . . . . . . . . . . . . . . . . . . . 39 4.2 Results using Face_det.py . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.3 Results of the Face_recog.py. . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.4 20 samples taken during the training stage of the process. . . . . . . . . . . 44 4.5 Structure required by the application of face expressions recognition. . . . 44 6 5.1 Comparison of the resources occupied. . . . . . . . . . . . . . . . . . . . . 50 5.2 Comparison of the resources occupied by CV functions. . . . . . . . . . . . 51 5.3 Resources usage for the final CV application. It includes 3 functions. . . . 52 6.1 Ganttdiagram ................................. 56 7 List of Tables 2.1 Possible improvements for the social pet robot. . . . . . . . . . . . . . . . . 22 3.1 Common characteristics of GUI packages. . . . . . . . . . . . . . . . . . . 27 3.2 Variable name according with the measurement. . . . . . . . . . . . . . . . 27 3.3 Connection between screen and the CPU. . . . . . . . . . . . . . . . . . . . 35 3.4 Results of touching tests, information provided by Pablo Gallegos’s work. . 35 3.5 Sensors and variable management. . . . . . . . . . . . . . . . . . . . . . . . 35 5.1 RAM requirements of the CV Applications. . . . . . . . . . . . . . . . . . 52 6.1 Detailed material cost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 6.2 Detailedpersonalcost ............................. 58 14 After this expansion, Figure 1.2 illustrates the new proposed architecture for the system. All the new applications will be tested individually for checking its correct execution and also will be integrated into the whole software package for monitor the complete functionality of the system. The present project does not consider to change or generate any cognitive social model or to modify other functions of the robot like those related with the data transmission through the cloud or with cognitive variables analysis or with results of the gaming mode. Figure 1.2: Proposed ROS architecture. 15 Chapter 2 Background and State of the Art 2.1 Social Robots Typically, Automatics and Robotics came from the idea of replacing workers’ skills in manufacturing chains [2]. Mention than in the second half of the twentieth century, the research field was dedicated to the development of a great spectrum of industrial robots. Although have progressively improved, most of them were programmable articulated arms designed to perform repetitive tasks. In the early twenty-first century there is a growing need for labour in scopes completely different than the industrial one, such as health and services sector, which is motivating to the idea of the usage of the robots to perform new kinds of tasks. (a) Example of a robotic arm, from a simulator environment. (b) Example of a commercial pet robot. Figure 2.1: Examples of an industrial robot and a social robot. Image a) www.masteringros.com, Image b) www.wowwee.com The efficiency and effectiveness of an industrial robot can be evaluated strictly from a technical point of view, focused on measuring the results of the execution of a determined 16 task. According with [3] a social robot interacts and communicates with humans, in a simple way, following social behaviours and rules. In this context it can be said that social robots usually are not task oriented and its performance cannot be evaluated exclusively from technical analysis, thus quantitative conventional metrics are less relevant for the field. Supporting this criteria, [4] suggests as a more important aspect, the social robot’s ability to attract and keep the user attention, therefore to evaluate the quality of the interaction between social robots and humans should involve both approaches, everything related with the tasks (forces, speed, positions), but also subjective analysis (psychological and sociological). It is described in [8] the term Socially Intelligent Robot as an artificial entity which demonstrate human factors on its interaction and behaviours. It refers to the robot inclusion on social groups or “robot in society”, but considering the total or partial inclusion as a consequence of its own traits. One of this important features is the morphology, almost as a rule, this automatons tries to adopt an anthropomorphic shape or an animal shape or a biological based one, as it is mentioned on [7]. Hence their movements will also be as similar as possible, and only limited by its technological development or the specific objectives of the robot. Another important feature is the social model which will be applied for process all behaviors around the SR. According with [9] there are several sub-classes of SR depending on the social model and the environment in which it develops. It is proposed: 1. Socially Evocative – designed for encouraging people to give human attributes to technological agents, in order to motivate the interaction with them. 2. Social Interface – based on the usage of the human-like social cues and communication modes for to ease and to enrich the interaction. 3. Socially Receptive – this subclass take benefit from the interactions with people, commonly using some kind of learning to acquire gestures, poses and such. 4. Sociable – these are socially active, they have two types of goals, the first one is the human benefit which pursue to make easy the interaction with people, and the second one is the benefit for itself, through its learning from humans in order to enhance its own yield. In order to develop or improve a sociable robot performance, the efforts should be oriented: to achieve accuracy in their movements, to enhance how friendly its processes and interfaces are, also to increase their ability to being perceived as social actors by the users. The main goal would be catch the human interest on the interaction related with the robot. 17 Figure 2.2: Anthropomorphic mobile robots developed in UPC, www.upc.edu. 2.2 Human Robot Interaction In [10], HRI is described as a branch of robotics which is focused on the understanding, designing and evaluating valid systems for its usage by or with humans, but the interaction is taken as any exchange of information between the robot and any user. Keeping in mind the previous ideas of friendly appearance, the most important objective in HRI will be achieve the simplest communication between the robot and the user. Therefore, in [6] is suggested that the system must be prepared for some conditions and situations in order to be: •Easy to be programed by non-experts. •Intrinsically safe. •Tolerant to imprecise perceptions and actions. •Capable to adaptation of a non-predefined environments. Also from [10] it can be detached a classification criterion of the interactions, which is based on the proximity between the subject (human) and the robot. Then, there are two categories: •Remote HRI – when the subject and the robot are physically separated, in this category it can be found applications that involves teleoperation or supervisory control. •Proximate HRI – when the human and the robot share the same location, for instance robot services or robot assistance. 18 Figure 2.3: Example of complex robot control panel, www.hotfrog.in. According with the goals of the robot, HRI should consider the potential users and their capabilities. In consequence, taking into account the possible limitations that a too sophisticated control panel could face, it have to look upon the next features: •The way to enter the information or receive the results has not to be unnecessary sophisticated, due to a possible width spectrum of users. How easy or hard to handle the interface can affect their perception and consequently their emotional status. •The processing unit should be managed by the most intuitive ways available. It includes audiovisual resources and also the format of displaying the information. From the computational point of view, the selection of the processor considers limitations like speed, capacity of memory or provisions of communications or peripherals. •The interface will be the mediator between the system and the subject, then it should be oriented to cover the user needs. At the same time, it should exploit or block determined functionality of the system depending on the level of user who is involved into the interaction. 2.3 Human Machine Interface As a definition, the Human Machine Interface is the virtual space where the interactions between humans and the device are generated. In [11] it is mentioned three types of HMI: •Command Line Interfaces – This kind of interface is based on the usage of command line and is function oriented. The user should know the specif syntax for the action and the argument (object for the action). It can be quite versatile but the user needs a big background. 19 Figure 2.4: Example of ‘command line’ interface, www.xmodulo.com. •WIMP Interfaces – WIMP model works in graphical mode. It can contain Windows, Icons, Menus and Picking device. It is object oriented. More intuitive than the previous one, it works liking an object with an action, displayed together or apart. Figure 2.5: Example of WIMP Interface. •Post-WIMP – Graphically, the difference with the previous one is the inclusion of a selection device, like a mouse, and it is task oriented. The real difference is that the functions are not specified in the HMI, but are deducted from the tasks of the user and its behaviour. This interface, without commands, could be performed when the amount of tasks is quite reduced due to the features of the application. Post-WIMP can be developed from two different approaches: the first one involves Virtual Reality, which is described in [12] as the creation of a simulated interactive environment; the second one includes the concept of Augmented Reality, as defined in [13] is the creation of virtual objects located over the real world. 20 Figure 2.6: Example of Post-WIMP Interface, www.en.wikipedia.org 2.4 Benchmark In the present subsection it is proposed a review in order to remark the best features of a current commercial robot and try to establish some feasible and desirable new functions. The scope of the analysis is limited to the relevant properties, functions or behaviours of the pet-like robot, the most popular. Research robots are not included into the analysis because most of them are built in order to satisfy specific functions or configurations. Services robots will not be taken into account either, due to their diverse centralization in tasks. 2.4.1 PLEO rb Pleo is a pet-robot with a baby dinosaur appearance, with a developed capability to imitate natural motion and expressions. Some features has been extracted from the maker website regarding the current version of the robot, PLEO rb. The first approach refers to social behaviour patterns: •Born in Characteristics – These properties are given since the manufacturing: Gender, Courage, Temper, Activeness, and Obedience. •Life Stages – The progress of each stage depends on the level of interaction, Pleo has different expressions and needs linked to every stage: Newborn, Toddler, Teenager, and Adult. •After Born Attributes – The artificial intelligence (IA) builds this features from the robot environment and its experiences. The combination of them creates a unique personality: Feed, Mood, Emotion, Health, Physicality. 21 •Sensation of Time – It is based on its simulated biological clock. It can learn and to recognize: Day, Night, Time to sleep, Time to eat. •Autonomous Animations – Depending on the personality of the Pleo, the interaction and the environment, the IA can generate an animation, the possibilities are: Hungry Sequence (graze), Fatigue Sequence (nap), Crave for attention (honk or pesky tug), Dreaming Sequence, Other PLEO rb presence Sequences. Figure 2.7: Pleo rb, www.pleoworld.com The second approach analyses the functions regarding the sensor of the system: •Vision – Pleo rb has a camera in order to perform some computer vision functions such as: Color Recognition (limited to red, yellow and green), End of track detection, Special cards recognition. •Voice – The robot includes a microphone as a part of a sounds recognition system which can generate: Responses to a specific commands, Learning and remembering of its own name. •Motion – Through the acquisition of signal from accelerometers, Pleo rb can classify the type of movement that the user is applying over it. The possible classes are: Swing, shaking, Petting, Impact. •Touch sense – The robot uses a set of tactile sensors in order to achieve differentiation between petting and hitting. •Response to Temperature – From the temperature measurements it can choose and execute some sequence depending on the condition like Sneezing or shaking if it is cold and panting or getting dizzy when hot. •Food Recognition – Additional pieces are recognized, through RFID, as food, the reaction depends on the Pleo’s mood, needs and desires: Eat, Reject. 22 As it can be noticed the social functions of PLEO rb are diverse and quite developed. The set of actions, reactions, gestures and moods are plenty. Although the functions related with the robot’s eyesight are limited, a further image analysis may improve the social performance, as well as the usage of computational resources. In addition there is no graphical user interface for options like upgrading or another setting. As the conclusion of the benchmark analysis the Table 2.1 shows the desirable functions for the pet-robot. New Function Possible Improvement Related Device Human Machine Interface Access to the system without an external computer. Touch screen Motion Detection Change between modes in order to save resources when there is no presence. Camera Face Recognition Block some functions when there is no subject’s presence (Master). Camera Gesture Recognition Possible modifications of the social functions depending on the subject’s mood. Camera Table 2.1: Possible improvements for the social pet robot. 23 Chapter 3 Human Machine Interface 3.1 Introduction The idea of a widespread range of users makes necessary a good balance between a useful control panel and a friendly interface. Thus the evident option would be a WIMP interface due to the graphical mode can offers several advantages over the command line mode, and at the same time, does not demand too additional resources like the post-WIMP interface does. Figure 3.1: Scheme of the HMI’s menus. As it was described throughout the Chapter 2, the HMI is quite important for the human robot interaction. Besides, it has to consider not only the interactions with the subject, but also those generated during the maintenance or setting up, which means the interface must be completely functional but keeping the simplicity needed for the children 30 an I2C interface. The schematic connection between the sensor and the Arduino UNO board is presented inFigure 3.8. Figure 3.8: Schematic connection between MPR-121 to Arduino UNO. According with previous works, several tests were made using different sizes of pieces of copper as probes in order to obtain different sensitivities to touch (different levels of capacitance). Next is presented a table with some results obtained with different people. This information was used for establish the thresholds into the sensing node. •MPU-6050 The next diagram (Figure 3.9) shows the connection that corresponds to the sensor MPU-5060 which provides the measurements from a 3 - axis accelerometer and a 3 - axis gyroscope. As in the previous case the communication is performed by I2C protocol. Figure 3.9: Schematic connection between MPU-6050 to Arduino UNO. 31 As has been said, the communication from both sensors to the Arduino hardware is done through I2C (a Multipoint Communication) then to include both connections at the same time is not necessary to have additional pins on the Arduino (digital or analog lines). Figure 3.10 illustrates the resultant connection. Figure 3.10: Schematic connection of Arduino UNO and both sensors. The sensing node receives the information from the sensors and manages it as structures of information, some examples as showed in Table 3.5, in the column called Process Variable. The Sensing node publishes the measures in the ROS environment using a message built by variables included in Table 3.5 in the Published Variables column. In subsequent changes or extended develops is strongly recommended to keep the same policy for the variable names in order to maintain the coherency. 3.3.4 Motion Hardware •Tri-state Buffer The legs of the turtle are designed with base on a specific model of servo motor, Dynamixel AX-12, then in order to control its movements is necessary to use an Arduino Board to establish an exclusive serial communication channel. There are some developed libraries for interaction between Arduino Hardware and Dynamixel motors, but for correct performance of 4 motors (4 legs) it is mandatory to assembly a tri-state buffer circuit. Figure 3.11 shows the implemented scheme. •Dynamixel Power Source As it can be seen in the previous scheme, the connection has double power source, the first one is typical TTL power source, VCC=5 volts, the second one is the 32 Figure 3.11: Tri-State buffer circuit. recommended power source by the manufacturer of the servo motors, VDD=9.6 volts. Figure 3.12 illustrates the SMPS2Dynamixel controller which is a device to provide stabilized voltage.Figure 3.13 is a representation of the connection from the Arduino UNO until the motor. Figure 3.12: SMPS2Dynamixel, stabilizer voltage device. 33 Figure 3.13: Scheme of the complete motion circuit connection. 34 Algorithm 1: Main process, Pseudo-code Data: Non required Result: Graphical User Interface 1Initial Configuration Declaration of Functions; 2Screen Configuration; 3Generation of the main window; 4case Cognitive Variables do 5go to the Log In Window; 6if Cancel then 7Return to the Main Window; 8end 9if Correct Profile then 10 Go to the Internal Variables Window; 11 Start to publish message; 12 if Return then 13 Return to the Main Window; 14 end 15 else 16 Stay in the Log In Window; 17 end 18 case Test Protocol do 19 Start to publish the Motion message; 20 Start to read the Sensing message; 21 Go to the Monitoring Window; 22 if Activate Motion then 23 update the Motion message; 24 end 25 if Return then 26 Return to the Main Window; 27 end 28 case Gaming do 29 Present the Set of Games; 30 if Chose any game then 31 Starts the game; 32 if Quit the game then 33 Return to Set of Games; 34 end 35 end 36 if Return then 37 Return to the Main Window; 38 end 39 case Exit do 40 Close the application; 41 end 35 Raspberry # pin LCD Raspberry # pin LCD GPIO Connector GPIO Connector 3.3V 1 3.3V 5V 2 5v GPIO2 3 SDA 5V 4 5v GPIO3 5 SCL GND 6 GND GPIO4 7 P7 GPIO14 8 TX GND 9 GND GPIO15 10 RX GPIO17 11 P0 GPIO18 12 P1 GPIO27 13 P2 GND 14 GND GPIO22 15 P3 GPIO23 16 P4 3.3V 17 3.3V GPIO24 18 P5 GPIO10 19 MI GND 20 GND GPIO9 21 MO GPIO25 22 P6 GPIO11 23 SCK GPIO8 24 CEO GND 25 GND GPIO7 26 CE1 Table 3.3: Connection between screen and the CPU. 2cm 1cm 0.5cm 0.25cm Fast Slow Fast Slow Fast Slow Fast Slow Subject 1 132 768 146 290 38 65 19 29 Subject 2 215 638 161 282 75 130 35 52 Subject 3 154 219 70 99 11 20 11 24 Subject 4 110 502 101 227 82 136 30 101 Subject 5 157 501 121 192 31 89 15 23 ° Table 3.4: Results of touching tests, information provided by Pablo Gallegos’s work. Sensor Variable Message Type Device Process Variable Published Var Size Touch Sensor MPR-121 sensing_msg.mpr121 mpr121 unit16 Gyroscope MPU-6050 sensing_msg.mpuGyro_X mpuGyro_X unit16 Gyroscope MPU-6050 sensing_msg.mpuGyro_Y mpuGyro_Y unit16 Gyroscope MPU-6050 sensing_msg.mpuGyro_Z mpuGyro_Z unit16 Accelerometer MPU-6050 sensing_msg.mpuAcc_X mpuAcc_X unit16 Accelerometer MPU-6050 sensing_msg.mpuAcc_Y mpuAcc_Y unit16 Accelerometer MPU-6050 sensing_msg.mpuAcc_Z mpuAcc_Z unit16 Table 3.5: Sensors and variable management. 36 37 Chapter 4 Computer Vision System The present chapter describes individual scripts and their sub processes, the tests and results of every one are part of a subsequent analysis. The CV algorithms are developed taking into account the next important notions: •Lighting changes - Since the firsts stages of the project, CASPER was thought to perform its activities in hospital environments, typically those places have uniform illumination. A similar type of lamps (color and intensity of light) in all rooms means that the possible variation generated by the natural light will no be considered. •Boundaries of distance - Indoor places almost ensure limited distances between the robot and the subject, which decreases the requirements of the camera. 4.1 Requirements In order to reduce the time implementation, it is imperative the usage of a toolkit or library to develop the computer vision applications. OpenCV is an open source computer vision library, it is multi platform (available for various operating systems) and there are different compatible versions with python distributions. According with [15] the python official website, this library was designed with an strong focus on real time applications. The last stable version is OpenCV 3.2 released in 2016. It is the proposed edition, since it works well with the current python version installed in the CASPER system (2.7.13). In addition, there exists a complement for the library, “Opencv_contrib” [16], which contains around 31 extra modules. This package is plenty important because it contains functions like: Vision Based Object Tracking or Face Recognition. Both algorithms are essential for most of proposed CV applications. Some of these additions provide several techniques and different approaches to perform their tasks. In consequence, for the project, the power of the usage of the library is on the combination of two components. 38 4.2 Motion Detection Algorithm In order to simplify the contents, the analysis of the algorithms does not include details or parameters about basic image processing like binarization thresholds, dilations, scaling, or files manipulation. This section is focused on the techniques, methods and functions relevant for the main goal of every routine. 4.2.1 Logic Used The used algorithm is based on the background subtraction technique, which consists on: (i) taking an initial frame as reference, (ii) after a delay, the obtained new frames are compared with the reference. Besides, there are some necessary steps for the method, the structure of the process is presented in Algorithm 2: Algorithm 2: Motion detection, Pseudo-code. Data: Image Frames Result: Detected motion 1Import libraries; 2Acquire Video; 3while is not the last frame do 4Get a frame; 5Convert to grey scale of the image; 6Eliminate noise; 7if there is not the background frame then 8background= grey scale; 9end 10 Comparison between background and grey scale; 11 Binarization of the result of comparison; 12 Dilation of the result; 13 Find contours on the result; 14 if contour is too small then 15 Eliminate contour; 16 end 17 Obtain size and location of the contours Display motions areas; 18 Show the frame; 19 Delay; 20 if key of exit then 21 Exit; 22 end 23 end Following are the selected parameters for special functions: •Eliminate noise - This operation is performed by a Gaussian filter, in order to eliminate higher levels of noise the kernel coefficients are also high for example 20 or bigger. 39 •Binarization - The binarization values are 25 for white and 255 for black, they are not dynamically computed through adaptive threshold, because all images have to be processed by the same conditions, even when some parts of the images are lost. •Time delay - This parameter was chosen in order to get good video playback for the demonstration (delay = 0.015 seconds). This consideration is present only during the test stage because in the final application there is no display for video results. (a) Results of the Movement detection in absence of motion. (b) Results of the Movement detection in presence of motion. Figure 4.1: Results of the Movement_det.py. Figure 4.1 shows the results in two different scenarios. In the sub figure a) there is no movement at all, in consequence the rest between the analyzed image and the reference image results a complete set of black pixels (right display) . The sub-figure b) contains movement, so the comparison of images generates white pixels that identifies moving objects, this can be seen on the right screen. The left display present the real image with a green rectangle surrounding such objects. 46 Algorithm 5: Training algorithm, Pseudo-code. Data: Image Frames Result: Resultant image with the face target 1Import libraries; 2Set path to save the face target; 3Set the path for library models; 4Enter the identity of the target; 5Set the final size of the face image; 6Initialize the Haar classifier; 7Initialize the video acquisition; 8while images < 20 do 9Get one frame; 10 Get the image size; 11 Flip frame; 12 Convert to grey scale of the image; 13 Scale down the image; 14 Detect faces; 15 Sort found faces by size; 16 if the size face fits then 17 Obtain the segment image with the face; 18 Resize the face using to the final values; 19 Draw a rectangle around the detected face; 20 Label the corresponding name; 21 if the size face is too small then 22 Remove face; 23 else 24 Delay; 25 end 26 end 27 end 28 Show the frame; 29 end 47 Algorithm 6: Face expressions recognition algorithm, Pseudo-code. Data: Image Frames, Dataset Result: Emotion recognized if there is any 1Import libraries; 2Create an array with emotions labels; 3Initialize the Fisher classifier; 4Initialize the video acquisition; 5while True do 6Get one frame; 7Convert to grey scale of the image; 8Scale down the image; 9Detect faces; 10 if there is a face then 11 Convert to grey scale of the sample images; 12 Scale down the sample images; 13 Organize the files; 14 Train the model with samples; 15 Predict the expression; 16 Resize the face using to the final values; 17 Draw a rectangle around the detected face; 18 Label the corresponding emotion; 19 end 20 Show the frame; 21 if Key of exit then 22 Exit; 23 end 24 end 48 49 Chapter 5 Software Performance 5.1 Computational Costs In order to determine the performance of the applications, a new script has been developed which only executes diagnostics for every critical part of the CPU. Before acquire all measurements, the diagnostics application is evaluated itself to check if it can significantly affect the rest of processes. The first test was performed including only the main functions of the process: sensing, motion and HMI nodes. It can provide a reference to compare the computational cost, before and after the vision applications, and evaluate each one separately. The valuation consist on run a launch file, which contains the nodes under test, and in parallel obtain the next information from the CPU: •Load of Processor •Free RAM •CPU Temperature •Graphical processing Unit (GPU) temperature The diagnostics is generated several times in order to get a profile of the system behavior, but especially to obtain the most demanding values for every computer vision script. Figure 5.1a) shows the curves that corresponds to the system without any ROS process running, which means the only process executed is diagnostics. Figure 5.1b) represents the behavior of the system when it is running Sensing, Motion and HMI functions. The blue line depicts the load of the processor. The gray curve indicates the CPU temperature and the yellow one is the GPU temperature. This arrangement will be the same for all the next figures of the same type. 50 (a) Diagnostics while evaluating the test application. (b) Resources used running Sensing, Motion and HMI. Figure 5.1: Comparison of the resources occupied. As it can be seen in Figure 5.1a) the maximum consumption of the CPU is bellow 8%, but almost always is less than 1%. Both temperatures, CPU and GPU, are similar and bellow 45◦C. It should be mentioned that currently the Raspberry has no any heat dissipating element. These measures suggest that the test does not affect to the demands of the ROS package. In the other hand, Figure 5.1b) presents a load process more variant than before, with a maximum peak on 47%, and also the temperatures rises to 50.9◦C as a top value. The last figure is taken as a reference of a regular behavior because it includes essential functions of the robot. The temperature results shown in Figure 5.2 imply, in the most demanding case, temperature does not exceed 57◦C, which is not a critical condition, but it is recommended a CPU heat dissipation element for avoiding some consequence due to continuous work. As it can observed in Figure 5.2, each CV algorithm adds load to the processor in the next amounts: motion detection approximately 25.2%, face detection approximately 48.2%, face recognition approximately 47.3% and facial expression recognition approximately 33.5%. The statistics designate that all functions executed simultaneously can over load the processor, so there should be an script which join all applications, taking into account some time boundaries and conditions to relieve the usage of the CPU. 51 (a) Resources used running Sensing, Motion, HMI and Motion Detection. (b) Resources used running Sensing, Motion, HMI and Face Detection. (c) Resources used running Sensing, Motion, HMI and Face Recognition. (d) Resources used running Sensing, Motion, HMI and Face expression Recognition. Figure 5.2: Comparison of the resources occupied by CV functions. Another important parameter to take into account is the RAM usage. Table 5.1 52 shows the diagnostics about it. As it can be noticed, almost none of the functions is so demanding, but the expressions recognition, which while is working at the same time with the essential functions leave only around 15%, of the total memory, available for different operation. On the other hand, the rest of the CV routines simultaneously operating with essential functions leave approximately 64% of the RAM free in the worst scenario. RAM Availability Functions Running No functions Essential F. E.F. + Motion Detection RAM Available 757Mb 694Mb 671Mb Functions Running E.F. + Face D. E.F. + Face R. Face expressions R. RAM Available 667Mb 645Mb 148Mb Table 5.1: RAM requirements of the CV Applications. Following the same steps described in the previous chapter, the complete CV algorithm (3 functions) has been built and yield the results showed in Figure 5.3. As a result of the fusion of the applications, the usage of the CPU is equivalent to one of them, the most demanding. Even tough, the hardware is capable to work with all functions. The decision to avoid the face expression application was taken after joined it with other functions and experiment the collapse of the system several times, a possible explanation of it is the high requirements of the RAM. Figure 5.3: Resources usage for the final CV application. It includes 3 functions. 5.2 Vision Algorithms Accuracy During the development of [18], its authors generated a database and put it available for research in automatic facial image analysis. It includes 354 images from 97 different subjects. The data-set was used in order to know the accuracy of the face recognition and face expression recognition algorithms, for the test, it was necessary to do a loop to compare the results of the algorithm (classification process) and each image label (a 53 known label associate to a person and an emotion). A 80% of the database was separated as training set in order to teach the system to recognize the faces and emotions, the other 20% was taken as a classification set and used to estimate the performance of the algorithms. As the images are randomly separated in both sets the process was repeated several times, the accuracy results are: 63%, 65%, 71%, 65%, 67%, 81%, 69%, 67%, 77%, 70%. The final result is obtained from the average of the iterations which means that the total accuracy of the algorithm is 69.5%. [19] suggests that the current dataset does include 3 emotions with significantly less samples than the other 5, so if those 3 classes are eliminated or full, the accuracy can rise to 80% approximately. It means that there are two important aspects in order to determine the performance of the computer vision functions. The first one is the training set, there would be enough amount of images with quality, either with generated images or with loaded images. The second one is the classification set, which refers to the quality of the acquisition once the system is already trained. 54 55 Chapter 6 Costs 6.1 Time The present development of the CASPER project has been completed in a period of 21 weeks. Several parts depend on a previous stage, but there exist parts completely autonomous, in consequence there should be some overlapped time lapses. For instance, it can be more evident taking into account the printing tasks and HMI creation, which were done simultaneously. But almost all sub-parts of the project is a result of a progressive process. Figure 6.1 shows the Gantt diagram which presents the whole project schedule divided in several tasks, the experimental section is divided into 4 parts: •Previous Work analysis (green period, 4 weeks). It includes the study of all the algorithms made during early stages of the project, and to establish some modifications that allows integrate the new functions to the main process. •HMI Creation (red period, 7 weeks) as it has been mentioned it has two autonomous parts: the assembly of the robot and the creation of the HMI. The assembly included some dead time like delivery time (sensors shipping) and 3D printing time, due to this tasks required less attention or none, the assembly of electronic circuits and HMI were done in parallel. •Machine Vision System (blue period, 8 weeks) it also includes the preparation of the hardware which is the installation of the libraries and further tests with cameras and different conditions of illumination. •Tests (yellow period, 2 weeks) during this period the accuracy of the algorithms was analyzed and also all statistics were done and registered. Simultaneously to the experimental work, the generation of the Memory was made (brown period 21 weeks) is the longest development of the project due to it is completely dependent to the results of the experiments and statistic analysis. 62 not enough and it can generate a collapse of the system. The solution is the usage of the application to manage the different tasks of CV, or it has to be another logic that decide when and which one CV task has to be executed. The performance of the CV functions were verified, it achieved approximately a 70% which gives to the system a good balance among flexibility and accuracy. After all measurements the application that joins all CV functions were monitored, it is stable and it works in a good manner. Is strongly recommended try to expand the storage of the system and rise its class, in order to have the games ready to use at the same time that the CV functions are working. Currently the system has a 10th class 16GB SD memory, the class can also improve the performance of the CPU related with the image processing. The mentioned storage limitation required remove the games set in order to execute the final tests. Is evident that some further development of the robot will need more capacity. 63 Acknowledgement The consecution of a project depends not only the author but also the people that surround him, providing knowledge, information, advises, help or their support. I hope do not forget nobody who has collaborated to achieve this dream. Thanks to Dr. Cecilio Angulo who leaded the project, providing guidelines and support for every task, and his trust on me and my capacities, he was an advisor during the project but also a professor and a friend during the master program. Also thanks to Pablo Gallegos who provided background, details and tips about previous stages of the project. My friends and colleagues whom always tried to enrich all tasks developed, an special thanks to: José Luis Pesántez, Diana Trifon, Natali Almeida, Elwin Alvarado, Homero Cadena, Aleix Figuerez, Julio Alvarez, Pamela Jara, María Caridad López and Andrea Narvaez. Finally, my complete gratitude to my beloved family, my parents: Rodrigo and Magali who always believed on me, my brothers: Gustavo, Hernán and Marco for their constant support and affection. 64 65 Bibliography [1] Thomas Herpoel,CASPER social assistive robotics platform: top down system design and intracommunication protocol. Haute École Louvain en Hainaut, 2016. [2] Carme Torras,Social robots: a meeting point between science and fiction. ISSN:1133-3987, 2015. [3] Social Robot,WIKIPEDIA, The Free Encyclopedia. https://en.wikipedia.org/wiki/Social_robot [4] Amara Andrés, Diego E. Pardo, Marta Díaz and Cecilio Angulo,New instrumentation for human robot interaction assessment based on observational methods. Universitat Politècnica de Catalunya - BarcelonaTech. ISSN:1876-1364, July 2015 [5] Pere Ponsa Asensio, Marta Díaz Boladeras, Cristina Manresa-Yee, Beatriz Amante García,Diseño ergonómico de interfaz gráfica y uso de interfaz de manos libres en simulación de tareas domóticas. 2010. [6] Carme Torras,Social Robots a meeting point between science and fiction. University of Valencia ISSN:1133-3987, May 2015 [7] Eduardo Benítez Sandoval,InteracciÃşn Humano Robot y sus aplicaciones educativas. Universidad Autńoma de México, 2012. [8] Kerstin Dauthenhahn, Aude Billard,Bringing up Robots or - The Psychology of Socially Intelligent Robots: From Theory to Implementation. University of Edinburgh, UK, 1999 [9] Cynthia Breazeal,Toward sociable robots. Robotics and Autonomous Systems 42, 2003 [10] Michael A. Goodrich, Alan C. Schultz,Human-Robot Interaction: A Survey. Brigham Young University, US Naval Research Laboratory, 2007 [11] Roger Trias Comas, Dani Tost,Navegación Virtual por un escenario teatral. Universitat Politècnica de Catalunya - BarcelonaTech, 2005 66 [12] Paul Derek,Unas palabras sobre Realidad Virtual. ISSN: 2013-9713, 1994 [13] Mark Billinghurst, Hirokazu Kato,Collaborative Augmented Reality. Communications of the ACM, 2002 [14] Tkinter - Python interface to Tcl/Tk,Python Software Foundation. https://docs.python.org/2/library/tkinter.html [15] OpenCV presentation,OpenCV team http://opencv.org/about.html [16] Repository for OpenCV’s extra modules, The world’s leading software development platform GitHub. https://github.com/opencv/opencv_contrib [17] Joseph Howse, Steven Puttemans, Quan Hua, Utkarsh Sinha,Expand your knowledge of computer vision by building amazing projects with OpenCV 3. Packt Publishing. [18] Takeo Kanade, Jeffrey F. Cohn, Yingli Tian,Comprehensive Database for Facial Expression Analysis. 2000. [19] Paul van Gent,Emotion Recognition With Python, OpenCV and a Face Dataset. 2016. [20] Catriona MacAlister, Jonathan Wood,The potential of 3D printing to reduce the environmental impacts of production. 2014 [21] DENG, Yelin,The impact of manufacturing parameters on submicron particle emissions from a desktop 3D printer in the perspective of emission reduction. Building and Environment, 2016.