scieee AI-readable full text Open interactive document viewer

Sistema de reconeixement d'objectes en una escena dinàmica en temps real

Vilaseca Corderroure, Jordi

Abstract

El projecte consisteix en fer un sistema de reconeixement d'objectes en format d'envàs per a una cuina domèstica utilitzant una Kinect 2. El sistema inclou les fases de segmentació, selecció dels descriptors i mètodes d'aprenentatge automàtic adients, i finalment el reconeixement d'aquests.

Full text

Sistema de reconeixement d’objectes en una escena din`amica en temps real Jordi Vilaseca Corderroure Director: Joan Aranda L´opez (ESAII) Codirector: Manuel Vinagre Ru´ız (ESAII) June 29th, 2016 Computer Engineering - Computation Barcelona School of Informatics (FIB) Polytechnic University of Catalonia (UPC BarcelonaTech) Resum Aquest projecte est`a orientat al camp de la visi´o per computador i aprenentatge autom`atic. Es tracta de un sistema encarregat del reconeixement d’objectes en una escena din`amica en temps real. L’escena en q¨uesti´o ´es una r`eplica d’una real i els objectes tractats s´on envasos. El sistema al complet utilitza el framework Robot Operation System per facilitar la feina d’integraci´o amb altres elements. Les dades s’obtenen mitjan¸cant una c`amera Kinect 2 que proporciona informaci´o RGBD, aquesta s’emmagatzema utilitzant un n´uvol de punts on s’apliquen la majoria dels algorismes utilitzats. El sistema comen¸ca amb una etapa de segmentaci´o basada en plans. El primer pas consisteix en trobar el plans de l’escena i els seus l´ımits, es consideren objectes els elements que estan sobre aquests plans i dins els l´ımits establerts. El seg¨uent pas consisteix en extreure la informaci´o de forma (CVFH ) i de color (Histograma de Color), i finalment, seguint una estrat`egia del tipus Bag of Features, obtenir el descriptor final. Aquesta informaci´o es passa a una Support Vector Machine per aconseguir l’identificador del objecte. Els resultats finals es mostren en un visualitzador rviz i es fan accessibles per tal de que altes programes hi puguin treballar. S’han proporcionat diferents eines per fer la vida m´es f`acil al usuari. Per exemple per capturar les imatges dels objectes i el posterior entrenament de la Support Vector Machine, a m´es a m´es de l’extracci´o de resultats per un conjunt d’objectes determinat. Tamb´e s’han proporcionat altres eines per a la integraci´o del sistema amb un robot. i Resumen Este proyecto est´a orientado en el campo de la visi´on por computador i aprendizaje autom´atico. Se trata de un sistema de reconocimiento de objetos en una escena din´amica en tiempo real. La escena consiste en la representaci´on de una cocina real y los objetos a reconocer envases. El sistema al completo esta construido utilizando el framework Robot Operating System para facilitar la tarea de integraci´on con otros sistemas. Los datos se obtienen mediante una camera Kinect 2 que proporciona informaci´on RBGD, esta se almacena una nube de puntos donde se aplican la mayor´ıa de algoritmos utilizados. El sistema empieza con una fase de segmentaci´on basada en planos. El primer paso consiste en encontrar los planos existentes en la escena y sus limites, se consideran envases los elementos que est´an encima de estos planos y dentro de los l´ımites definidos. El siguiente paso consiste en extraer la informaci´on de forma (CVFH ) y color (Histograma de Color) de los objetos antes mencionados, utitilizando una estrategia basada en un Bag of Features se obtiene el descriptor final. Esta informaci´on se pasa a una Support Vector Machine para obtener el identificador del objeto. Los resultados finales se muestran en el visualizador rviz y se hacen accesibles para que otros programas puedan trabajar con ellos. Se proporcionan diferentes herramientas que permiten hacer la vida m´as f´acil al usuario. Por ejemplo, para capturar im´agenes de objetos y el posterior entrenamiento de la Support Vector Machine, a parte de la extracci´on de resultados para un conjunto de objetos determinado. Se incluyen otras herramientas para la integraci´on del sistema con un robot. ii Abstract Project orientated to the field of the computer vision and machine learning. System in charge of recognising objects of a dynamic scene in real time. The scene is a representation of a real kitchen and the objects kitchen containers. The entire system is built upon Robot Operating System to make it easily integrable to other systems. The data is acquired using a Kinect 2 camera that provides with RGBD data that is stored in a point cloud structure in which is applied most part of the algorithms that the project uses. The system has different steps. The first one is the segmentation that is based on plane segmentation. It starts by finding the available planes in the scene and their limits, these planes are defined as the background and the elements above them the objects to be extracted. Shape (CVFH ) and colour (Colour Histogram) features are extracted from the objects, and using a Bag of Features scheme the object descriptor is computed. Then, this information is fed to a Support Vector Machine to obtain the identifier of the object. The resultant data is displayed into the rviz visualizer and made available for other programs to work with. Tools for capturing data and the posterior training of the Support vector machine are provided to ease the work to the user, including extraction the results for a determined set of objects point clouds. It also has some tools to integrate the system to a robot. iii Acknowledgements I wish to express my sincere thanks to Joan Aranda L´opez, the director of this project to give me the opportunity of doing it in this great workspace and being always available. I would like to thank the co-director Manuel Vinagre Ru´ız for answering my endless questions and together with the other people of the laboratory to easing the workday and making the stressful days something easy to go by. I take this opportunity to express also gratitude to my family, for the support they always showed, the discussions about this project and for the useful ideas they give me keeping in mind they nearly know nothing about the themes involved in it, but they make the effort to understand them, and a greater effort to try to help me. Finally, I would like to thank to my friends, university colleagues and everyone involved directly or indirectly with the development of the project. iv Contents 1 Introduction 1 2 Problem’s formulation 2 3 Background 3 3.1 Imageandpointcloud ........................... 3 3.2 WhyuseaKinect? ............................. 4 3.3 Usedlibraries ................................ 4 4 Temporal planning 6 4.1 Projectplanning .............................. 6 4.2 Design and implementation stage . . . . . . . . . . . . . . . . . . . . . 6 4.3 Finaltask .................................. 7 4.4 Stagesduration............................... 7 4.5 Planningdeviation ............................. 8 5 Scope 9 6 Budget 10 6.1 Humanresources .............................. 10 6.2 Directcosts ................................. 10 6.3 Indirectcosts ................................ 10 6.4 Totalbudget................................. 11 6.5 Deviation .................................. 11 7 Methodology 12 8 Social commitment 13 9 Sustainability 14 10 Implemented nodes 15 11 Camera calibration 16 11.1Intrinsiccalibration............................. 16 11.2 Extrinsic calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 12 Changing coordinate frame 17 13 Point cloud creation 18 14 Plane detection 19 15 Plane limitation 21 15.1Normalfiltering............................... 21 15.2 Project points to the plane . . . . . . . . . . . . . . . . . . . . . . . . . 22 15.3 Discarding unwanted clusters . . . . . . . . . . . . . . . . . . . . . . . 22 15.4 Finding plane limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 16 Segmentation 25 v 16.1Pointsonaplane.............................. 25 16.2 Points inside the limits of a plane . . . . . . . . . . . . . . . . . . . . . 25 16.3Definingobjects............................... 26 17 Object recognition 28 17.1Descriptors ................................. 28 17.2Objectssets................................. 30 17.2.1Trainingset............................. 31 17.2.2Testingset.............................. 31 17.2.3Validationset............................ 31 17.3Pipeline ................................... 32 17.3.1 Object decomposition . . . . . . . . . . . . . . . . . . . . . . . 32 17.3.2 Colour descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . 33 17.3.3 Shape descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . 35 17.3.4 Joining the two descriptors . . . . . . . . . . . . . . . . . . . . . 35 17.3.5BagofFeatures........................... 36 17.3.6 Descriptor matching . . . . . . . . . . . . . . . . . . . . . . . . 37 17.3.7Prediction.............................. 38 18 Results 39 18.1Validationtest ............................... 39 18.2Generalizationtest ............................. 39 18.3Occlusionstest ............................... 40 18.4Graspingtest ................................ 40 19 Future work 42 20 Conclusions 43 Annex A: Implementations 46 Planesegmentation................................ 46 Basicversion ................................ 46 Optimizations................................ 46 Makingitparallel.............................. 47 Results.................................... 47 PolygonSimplification .............................. 48 Annex B: Used objects 49 References 51 vi 1 Introduction It was some time ago that the first robots where introduced to the industry because it was a necessity, currently this urge is translated to other environments where robots could be of great use. I am talking about the house environment, where robots will be introduced developing multiple tasks, firstly with the idea of assisting people with their housework and afterwards trying to release they owners of doing these tasks. This future could be near that is expected, and its introduction will provoke a great change in the way the housework is done. My bachelor thesis is included in this context. Where the recognition of objects is highly used to provide the robots of eyes to understand what is surrounding them, knowing with what objects it can interact and possible obstacles to avoid while an object is moved from one place to another. To do this, the initial position, final position and bounding box of the object is needed, with the system suggested in this project these data could be obtained. In this case the scene involves a kitchen equipped with different cupboards, a cook-top, a sink and so on. A true scenario where sometimes the recognition of objects and its movement could be a truly nightmare. 1 2 Problem’s formulation The principal goal of this project is to do a real time system that could be able to detect and recognise objects that are placed on a table or any other rectangular surface. Its output will be the recognised objects identifier besides with its position and an oriented bounding box. The system will be capable to start with a scene that has objects already placed in it. Another important feature is to recognise objects partially hidden, either by other ones or by someone holding them. The system will continue recognising the visible elements although somebody is moving the objects from one place to another. The used objects will be kitchen containers, that is because they easy manipulable and with enough variability and characteristics to be able to recognise them. AKinect 2 camera will be used to acquire the images, this camera sends RGBD information, that apart from colour it also provides with the depth of the pixels (not from all of them, but using an interpolation method a depth for each pixel could be computed). This is a valuable information, because it will allow the system the know the position of an object and find the table planes. It must be easy for the user to use the system, for that reason different nodes are provided to ease the training stage and to know what is going on in the scene, one of them is a visualizer that shows the points of the segmented objects together with their bounding box and identifier. 2 5 Scope When project was started, all the hardware was already set up and working properly, the only problem was that the Kinect 2 cameras were not calibrated, so the first step was to calibrate them to guarantee that accurate images were acquired. This was done using the package iai-kinect2. The next step was to acquire images to start the data processing step. Two images containing the colour and depth data in OpenCV format were acquired using iai-kinect2 package, they need to be merged to a Point Cloud Libarary structure for their posterior processing. The initial idea was to make a small preprocessing of the data before starting manipulating it. It consisted in filtering the points to remove outliers, in order to have cleaner data, finally this step was removed because it was too slow and the results were not quite better. The next step was to segment images to obtain objects that afterwards will be recognised. Some functions for clustering and plane detection from Point Cloud Library were used to obtain the segmentation. Once the objects are obtained the recognition step starts. Feature descriptors from the objects must be extracted, It was used OpenCV for colour features and Point Cloud Library for shape ones. The machine learning algorithm used to make predictions were implemented in the OpenCV library as well, which has most possibilities and implemented methods that the machine learning library from Point Cloud Library. After all this steps, all the necessary data to create our desired output build with the identifier, its oriented bounding box and position of an object is already available. Data needs to be sent using a Robot Operating System message, this way a robot could use this information to manipulate objects from the scene, but this last part is not inside the project’s scope. 9 6 Budget 6.1 Human resources In this section it will be explained the people needed to develop the project. There are different roles that must be done, but in this case I will be in charge of all the positions because it is an individual project. These positions are software engineer, project manager and beta tester. A total of 101 working days are estimated to develop the whole project. Estimating an average of 6 hours of work every day, it makes a total of 606 hours. Role Hours Price per hour total price Project manager 125 50e/h 6250e Software engineer 400 30e/h 12000e Beta tester 81 25e/h 2025e Total 606 20275e 6.2 Direct costs In the project only has direct costs in concept of hardware because all the used software is open source. Product Price Units total price Service life Amortization Server 4000e1 4000e5 years 800e -Graphic card 2000e1 2000e5 years 400e -Processor 300e4 1200e5 years 240e -Other components 800e1 800e5 years 160 e Kinect 2 150 2 300e5 years 60e 6.3 Indirect costs In the project also appear some indirect costs deviated from the direct ones, a highperformance equipment with an important power consumption was provided. After looking at different companies, a price of 0.12e/kWh was decided to be a good approximation of the real price. To calculate the total consumption of the server it was used as a reference the consumption of a similar graphic card (300W), four Xeon processors (in total 200W) in addition to a approximation of 100W for all the other computer components. It makes a total of 600W (0.6 kW), that making the supposition that it will be always turned on while the project is being developed, it makes a total of 606 hours and a total energy consumption of 363.6 kWh. On the other hand, a Kinect 2 has an approximated consumption of 20W each one, that it makes a total of 2.424 kWh between two of them. 10 Product Price Units Total cost Server 0.12e/KWh 363.6 KWh 43.63e Kinect 2 0.12e/KWh 2.424 KWh 0.29e Total 366.024 KWh 43.92e 6.4 Total budget The only thing that remains to do is to add up all the previous values. It could be concluded that most part of the expenses were destined to human resources and direct costs. Concept Price Human Resources 20275e Direct Costs 4300e Indirect costs 43.92e Total 24618.92e 6.5 Deviation Things went smoothly in the chapter of expenses because there was not any unforeseen expense, the project was terminated on time and no hardware problems occurred, so there was no deviation in terms of costs. 11 7 Methodology A working zone with all the necessary equipment already operative was proportioned, this was very helpful during the first steps of the project. My routine consisted in going there every working day to develop the project. Weekly goals were proposed to make sure the project was advancing properly. The entire projects was developed using the already mentioned libraries and using C++ as a programming language. This last decision was made because the used libraries where natively written in this language and was thought that it was a good idea to use it because a lot of data is needed to be processed, around half a million points for point cloud in real time. In this context C++ is perfectly adapted, it provides speed, robustness and a lot of development tools to write code. The system was deployed to a server where existed multiple projects related to computer vision and robot management, and all the components were interconnected using Robot Operating System. One of the most important tools used in the project was Git to do the version control together with Github and Bitbucket to backup and share the work. For the part of plane limitation and segmentation a visualizer was used as a validation system. Real time output data showed in the visualizer was analysed to make sure that the results were good enough. It was really difficult to extract numerical results to make a posterior analysis for this part of the project because there is not an obvious way to compare two planes that are part of a bigger scene, and a most arduous task it to know what is the best one when there are a lot of different variables that take part in the results. The same happens in the segmentation step. On the other hand, in the recognition step was easier to obtain numerical results. The first step was to create a training and a testing set of objects. All the tests where made using the training set to train the machine learning method. Then, predictions using the testing set were made to extract conclusions using the accuracy, precision, recall and F-measure as metrics together with a confusion matrix that showed the principal prediction problems of the model. The tests started with easy goals, and its difficulty incremented progressively. First objects trained and tested in the same position were used, when good results were achieved, different positions for training and testing were tested. Finally, some tests involving changes in the illumination were made to make sure that very different illuminations do not produce awful results. When all the parameters were tuned, a test using a third set of data (the validation set) different from the previous ones was used to extract the final results. 12 8 Social commitment The constructed system do not have any impact in the social commitment, but tools that can be easily developed using its outputs as a source of information could have a lot of impact in the society. The system is dealing with kitchen containers as objects, so for example this system with a little extension that could manage a robot can ease the life of people with reduced mobility. If an user wants an object from the scene, it has only to indicate to the system its identifier, then it only needs to find the object between all the other ones and send the position to a robot manager to pick the object and give it to the user. This utility could have an important impact in the society making people with reduced mobility more self-sufficient. It could have other applications in the industry. Knowing the position of different elements is always a valuable information, for example it could be used to avoid issues in factories. You could have the case in which having two objects side by side is dangerous, using this system you could detect cases like that and warn someone or sending a robot to move one of the objects. In the same case than before, knowing the position of some objects could also be used to send commands to a robot to manipulate them, avoiding workers doing very repetitive tasks and obtaining a more competitive industry. 13 9 Sustainability The system makes use of a high-performance server and two Kinect 2 cameras that will be turned on every time someone want to use the it. In total it has a large power consumption, but this cannot be reduced because a massive quantity of data in real time must be processed. In the economic planning section the total energy used during the development of the project has been calculated, this amount of energy is equivalent to 0.295 tons of CO2. This system has a negative impact in the environment, and there are few things that could be done to reduce it. There are two principal options to obtain a server of these characteristics, reuse a old server and make few extensions to it or buy a new one. In the construction of a component for a computer a lot of energy and materials are consumed, but as advantage new computers tend to consume less energy with the same potency of calculus than older ones. It is in the hands of the user to choose the best option depending on the time that the system will be working. During the development of the project an old server was reused to make the tests, and it will be used afterwards in projects of other kinds. So the ecological impact in the project was only reduced to the energy consumption of the server and Kinect 2. 14 10 Implemented nodes All the implemented code is in format of ROS nodes, every one represents a process and the communication between them is made using messages. point cloud It receives two images at the same time from iai-kinect2 package, one containing the colour and the other the depth information. It creates a point cloud as it is explained in section 13. segment It extracts the objects from a point cloud following the steps of section 16. It also implements the plane detection and limitation (sections 14 and 15). The results contain the point cloud of the aisled object together with its position and oriented bounding box. recognise Implements the recognition pipeline introduced in section 17. It complements the segmentation output by adding the object identifier. objects training It contains different tools for adding training and testing data, training machine learning methods using different parameters and descriptors and finally extracting results. To capture new objects the only thing that it has to be done is to put the tag in a visible area, the node itself finds the tag position1and removes everything from the scene that is not above the tag. This functionality eases the step of adding new training, testing and validation data because a new picture is taken every time the user press enter. To obtain data from another position, the only thing to be done is start the node again to find the new position of the tag. It also provides a menu to change the parameters of the recognition step and a way to do online tests in the same way than the training. But the most useful possibility is to compute the metrics and confusion matrix for a specific testing set, most part of the results were extracted using this functionality of the tool. objects to rviz rviz cannot understand the system output directly, so in this node it is translated to elements that rviz could understand. To do this the objects are joined to make a point cloud that contains them all, the oriented bounding boxes are translated to primitives and the identifier of an object it is sent (if it exists). tf calibration As it is explained in section 12, a transformation between different frames is computed with the intention of integrating more elements in the system. tf publisher It is in charge of sending the transform between frames during the execution of the system. 1Using ar track alvar ROS node. 15 11 Camera calibration A chessboard has been used to calibrate the two cameras of the Kinect 2. Using it allows the calibration program to find out the distortion of a camera comparing the expected result with the obtained one. The same it is applied for the synchronization of the two images, positions could be compared one to one to know the correspondence between pixels. 11.1 Intrinsic calibration Digital cameras are not nearly perfect, the small lens that are used to acquire the images provoke distortions to them. This distortions are different from one camera to another, and as a results a calibration step is needed to quantify and counteract them. Figure 2: Two cases of radial distortion. Normally, a lent is affected by two types of distortion, tangential (provoked by a bad lent alignment) and radial (the size of the lent). The iai-kinect2 used 3 coefficients for the first one, and two for the second one. With them, the images could be rectified to obtain better accuracy. This step is needed for the colour and infrared cameras separately. 11.2 Extrinsic calibration The infrared and a colour camera are translated one from each other, and sometimes they could be rotated. As a consequence does not exist a direct mapping from a pixel of one camera to the other camera. The extrinsic calibration defines a rotation and a translation between the two cameras to obtain a direct correspondence between pixels. 16 12 Changing coordinate frame By default, received point clouds are in the camera coordinate frame. This is not the preferable frame to use if the system has to be integrated with other elements such as robots because they need to operate using the same coordinate frame. For this reason a ROS node was implemented2to easily interconnect the recognition system with other elements from the system. This uses the ar track alvar ROS package to obtain the position and the orientation of a tag. These information is stored and automatically published3when the system is used. There exist only one condition on where to put the tag, it has to lay in one of the planes that is wanted to be detected. The reason of this condition will be explained in section 14. 2tf calibration node in the source code 3tf publisher implemented node 17 13 Point cloud creation The received images are already synchronised and the depth information traduced to meters because iai-kinect2 package with a calibration already performed is being used. The camera also sends the camera matrix (Equation 1). This contains the field of view of the camera (vertical and horizontal angles) and the centre of the projection.   fx1x0 0fyy0 0 0 1  (1) The point in the 3D space must be calculated and combined with the colour from the RGB camera. Knowing that dxy is the depth of the point (x, y) in meters, the new coordinates are calculated as follows: x0=dxy ·(x−x0) fx y0=dxy ·(y−y0) fy z0=dxy r0=r g0=g b0=b 18 16 Segmentation In the segmentation step a point cloud is received and processed to extract the objects from it. The first step is to remove the points that are not inside a region of interest that is defined as follows: •It is placed above a plane. •It is inside the limits of the plane. •It is not the plane itself. 16.1 Points on a plane A way to know if a point is above or below a plane is to calculate the signed distance between the two and then discard the points that are below the plane (negative distance). A point is assumed to be in a plane if the absolute distance between them is less than 1.5 centimetres. Point to plane distance Starting from the point that the coefficients are in the Hessian Normal Form. The distance is given for the following formula: D= ˆn·x0+p Having the general equation of a plane ax +by +cz +d= 0, ˆnis the unit normal vector, p=d √a2+b2+c2and x0is the query point. 16.2 Points inside the limits of a plane It is more difficult to know if a point is inlier to the polygon built with the limits of a plane. An orientation test is used to achieve this. Orientation test The used method is defined in [1]. First of all, the function orien3d(a, b, c, d) is defined, it returns a positive (or a negative) value if dlies below (or above) the oriented plane passing through a,band c. In geometry, a parallelepiped is a three-dimensional figure formed by six parallelograms, and a parallelotope is called the generalization of a parallelepiped in higher dimensions. One way to compute the signed volume of a n-parallelotope Pin Rn, whose n+1 vertices are V0, V1, ... , Vnis the following: V ol(P) = det([V01] ; [V11] ; ... ; [Vn1]) (2) Where [Vi1] is the row vector formed by the concatenation of Viand 1, and ; separates each one of the rows of the matrix. 25 This is the same case that the one found in this project because it exists four points (three defining a plane and the point to be tested) in a three dimensional space, so by applying the equation 2 the following matrix is obtained. V ol(a, b, c, d) =         axayaz1 bxbybz1 cxcycz1 dxdydz1         =         ax−dxay−dyaz−dz0 bx−dxby−dybz−dz0 cx−dxcy−dycz−dz0 dxdydz1         (3) =      ax−dxay−dyaz−dz bx−dxby−dybz−dz cx−dxcy−dycz−dz       ·1 (4) =      ax−dxay−dyaz−dz bx−dxby−dybz−dz cx−dxcy−dycz−dz       The equation 3 is valid because adding a scalar multiple of one row to another row does not change the value of the determinant, and the equation 4 is expressed in terms of the Laplace expansion of a determinant. The sign of the obtained value provides the orientation of the point respect to the plane, and if the volume is zero, it means that the point lays on the plane. Using this method, an algorithm to determine if a point is inside a polygon can be implemented. A plane is defined with its coefficients ax +by +cz +d= 0 and normal ~n = (a, b, c) together with the limits of a plane as a polygon P= (p0, p1, ... , pm, p0), having mborders built with the pair of points (pi, pi+1) with i∈[0, m]. So, for each one of these borders the orientation of the point dmust be calculated, and if it is always the same, then dis inside P. Otherwise the point is in the boundary or outside, these two cases are considered as outliers. But there is a small detail that must be solved. The function orien3dtakes a,band c as the points that form a plane, and das a query point. A limit of the border is defined using two points, so it remains a third point to define the plane that is manually crafted with the formula c=~n+a. This way, the plane that defines the border is perpendicular to the original plane. 16.3 Defining objects These calculations provide a set of points that are above a table but that are not the table. By only doing this, as can be seen in Figure 8 the obtained set of points could be easily separated using a clustering algorithm. In this same figure it could be seen that with planes one above the other, if the plane below is a little bit translated or bigger than the above one, part of the surface of this last one is treated as object. 26 Figure 8: Example of how it is seen the point cloud after the segmentation step. As before, an Euclidean Clustering8is used to gather points in objects. After some tests, a limit of 3 centimetre is used to define a new cluster from another one. It has to be kept in mind that a very small value will produce several clusters for an object, fact that is not reasonable and that will produce difficulties in the next steps of the system. On the other hand, a bigger value can produce clusters that include more than one object, fact that is not reasonable either. A limit of 3 centimetres produce clusters containing an entire object, and an assumption of 3 centimetres between objects is good. The minimum number of points of the clustering was set two 200, smaller than before because now the system is dealing with separated objects with an average size of 2000 points approximately. The implementation of the segmentation step makes possible to have multiple planes that can be positioned in diverse ways. For instance, two planes one above the other represents no inconvenient to extract the points of the objects without repetition (for example green and blue planes in Figure 8). Another good feature proportioned by the use of the limits allows to have two planes side by side but with small deviation in the height (green and red planes in Figure 8)), if the limits had not been used, the most probable thing is that the elements in the smaller height plane were partially removed because some points of them intersect with the plane coefficient of the bigger height plane. The two cases are present in the scene where the tests have been made, and with the addition that one plane (green one in Figure 8) is affected for the two problems. 8Point Cloud Library. Euclidean Cluster Extraction class. 27 17 Object recognition 17.1 Descriptors At this point, the objects are described as a set of points with coordinates and a colour. They cannot be used directly to recognise an object because they represent an exact representation of it that hardly ever will be repeated (due to the imprecision in the depth of the point cloud and that they could be rotated), so it has a very small power of generalization. For these reason a descriptor for each object must be calculated. Descriptors encode interesting information into a series of numbers and act as a sort of numerical ”fingerprint” that can be used to differentiate one feature from another. They must have the following properties: •Robust. It must be a good generalization of the object. As a result, point clouds that describe the same object but with small variation must have a very similar descriptor. •Scale invariant. A very similar descriptor must be calculated for an object with two point clouds that have different size. •Translation invariant. A change in the position of an object cannot effect the result of its descriptor. •Illumination invariant. The descriptor has to hardly change regardless the illumination of the scene. Selecting a good descriptor is one of the milestones of this stage of the project because this will be the information that will be fed to the machine learning algorithm, so a bad source of information will produce bad results of the recognition stage regardless the machine learning method used. There are two types of descriptors, local and global ones, after a segmentation step, using global descriptors is the natural choose. The first descriptors appeared in computer vision made use of the colour information (for example the colour histogram, and more recently SIFT). But after the appearance of stereoscopic systems and the Kinect, point clouds become popular and descriptors extracting information about the shape of objects appeared, in this project the two types are used. In first place, the one capturing the colour information is explained. Colour Histogram As its name says, a colour histogram is a feature descriptor that only works with the colour of objects. It represents the distribution of colours of a image storing the number of pixels that have each specific colour. It can be built in any kind of colour space but the most commons are RGB and HSV. For example, in HSV a histogram is a three dimensional array containing the hue [0,180), saturation [0,256) and value of an specific colour (0,256). As it was said before, the descriptor must have to be invariant to the illumination. Using HSV this can be achieved, because the V channel encodes the brightness of a colour (that is precisely the information that must be avoid encoding). Using a histogram only with channels H and S a descriptor robust to illumination is obtained, this does not mean that is totally invariant to it. 28 An histogram using all the spectrum of colours provides with a high dimensionality descriptor (more exactly of 46.080 values in a HS histogram). For these reason most times a colour is divided in bins, each one containing and interval of an specific colour. This way the size of the descriptor can be reduced down to the point that is wanted depending on the precision it is needed. Reducing the precision of the descriptor also improve its illumination invariance and generalization power. It can be easily seen that the descriptor it is not invariant to the size of the object, the same image with different resolutions will have a different total number of points, and as a result the descriptor will be different. Using percentages instead of absolute values makes it scale invariant. The total number bins will be determined in the next section after performing some tests. Using only colour information when also positions are provided is a wasting of information. For that reason an additional descriptor is used to capture this type of information. CVFH It comes from Clustered Viewpoint Feature Histogram [2], it is based on the VFH [3] global descriptor, but instead of only using one descriptor for an entire object, it is segmented using a region growing algorithm based on normals to extract the different parts of it, and finally an extended VFH descriptor is computed for each one of the clusters. The clustering step also remove points with a very large curvature because these have a inclination to be more imprecise. Let pcand ncbe the centroid point and its normal of a part of an object. For each point piwith normal nithe Darboux coordinate frame is defined as follows. ui=nc vi=pi−pc kpi−pck wi=ui×vi All the next calculations are made using this frame to make the descriptor pose invariant. For each point of a part the following features are calculated. α=arcos(vi·ni) φ=arcos(ui·(pi−pc) kpi−pck) θ=atan2(wi·ni, ui·ni) SDC =(pc−pi)2 max((pc−pi)2) The final descriptor is made with 45 bin histogram for each one of the previous features plus a viewpoint component that is computed by collecting a 128 bin histogram of 29 Figure 9: CVFH descriptor for two similar images. the angles that the viewpoint direction makes with each normal, all these histograms appended one after another. The fact of dividing an object in parts makes the descriptor more robust to partially hidden object data (as could be seen in Figure 9). 17.2 Objects sets As it was said before, in the project is used three disjoint sets of objects. In Figure 10 it could be seen the position where the data was captured for each one of the sets. It was decided to use the most external positions for the training data with the intention of capturing the most extreme available cases in the scene. For the testing and validation sets was decided to use two trained positions and a non trained one to know the generalization power of the system. Figure 10: It shows the positions where the sets were trained. Training set (green), testing and validation sets (blue). All the objects were acquired using the implemented ROS node objects training. 30 17.2.1 Training set (a) High-angle shot (b) Frontal shot Figure 11: Two examples of object 13 with different pitch angles The final training set consisted on a total of 48 photos for each object distributed in three different places of the scene (Figure 10 colour green). The used descriptors are scale, position and illumination invariant, but not rotation invariant, that’s because an object viewed from two different rotations will have 2 different point cloud representations (Figure 11), and for instance some parts could disappear. It is important to reflect all these things to the training set to be able to predict different outcomes. In each position a set of sixteen photos were taken, each one in a different rotation of an object. This is important because the object must be predicted regardless the orientation of it, so images of all the visible parts are needed. Although having a colour descriptor invariant to illumination, It is not known up to each point it is invariant, for that reason a small test was made to find it out. Figure 12 show the results using two different training sets, one consisted on images with a lot of illumination (Figure 12a), and another one (Figure 12b) was built with images with little, normal and a lot of illumination. The results shown in Figure 12 seem to indicate that using more than one type of illumination could be even counter-productive. For this reason there was no special emphasis in training the models with different type of illuminations. 17.2.2 Testing set It consisted in a total of 30 images for each object divided in the three positions previously mentioned. The photos in each one of the positions were made with different levels of illumination. 17.2.3 Validation set As in the testing set, the photos were also taken using different levels of illumination, but with 15 images for each object divided in the thee positions. 31 Accuracy Precision Recall F-measure One illumination 0.972 0.851 0.81 0.813 Three illuminations 0.968 0.831 0.793 0.796 (a) Images with a lot of illumination. (b) Images with different illuminations. Figure 12: Results obtained training only with the colour descriptor, with 6 and 13 bins for S and H channel respectively. The training set consisted on 48 images. 17.3 Pipeline Object point cloud P art0 P artn ... Colour descriptor Shape descriptor Joined descriptor Matching Vocabulary F eature0 Colour descriptor Shape descriptor Joined descriptor Matching Vocabulary F eaturen Final descriptor SVM Object ID The recognition pipeline starts with a set of objects, each of one build using a set of points containing position and colour. After doing some computation on this data a model will be obtained, and this will be fed to a machine learning method to know what object it is. 17.3.1 Object decomposition There are different ways to recognise an object, for instance the most straightforward way is to compute a descriptor for an entire object. This option will work properly in most cases, but exists other strategies based on the way that a human being differentiate objects that provide some advantages. For example human beings know that something is a bicycle because it has two wheels, a handlebar, a chain, etc. but a bicycle with 32 only one wheel could be also recognised, that is because they base the recognition in the semantic analysis of an object based on the parts of it. This idea could be extrapolated to object recognition in computer vision, the different parts of an object will be defined using a Region Growing clustering9based on normals. The purpose of this algorithm is to merge the points that are close enough in terms of a smoothness constraint and removing from the object points with a curvature bigger than a threshold, that last step is necessary because this type of points usually have imperfections. An example of this type of clustering could be seen in Figure 13. Figure 13: Original figure (left) and its region growing segmentation (right) Following the previous description, an object Oiis seen as a list of Miparts (pi,0, pi,1, ... , pi,Mi). Having CHi,j and CV FHi,j with j∈[0, Mi] as the colour histogram10 and the CVFH11 descriptor respectively of a part pi,j of Oi. The descriptor of a part is defined as follows: dij =< CV FHij CHij > 17.3.2 Colour descriptor The first step is to study the behaviour of the colour histogram. Figure 14 shows the obtained results changing the number of elements per bin for the separated channels S and H. After analysing the plots, it could be concluded than channel H gives more information about an object than the S one. Two good possibilities of elements per bin in the H case are around log10(22) ≈1.34 and log10(13) ≈1.11. The result of the first one is a bit worse (around 1%) but it uses the around the half of the bins than the second, at a first sight it could seem a good option to to have a little worse results in exchange of a smaller dimensionality. For the S channel is easily seen that a good number of elements per bin could be log10(42) ≈1.62, in this case apart from being the best result it has smaller dimensionality. One of the possible reasons of why using a lot of bins give bad results is because a small training set with a small fixed number of clusters are being used, for this reason if the granularity of the colour is too small it produces an over-fitting of the model. After analysing the behaviour of each separated channel it is time to find out the performance using the two channels at the same time with the parameters selected in 9Point Cloud Library. RegionGrowing class 10OpenCV. calcHist function 11Point Cloud Library. CVFHEstimation class 33 (a) Only using S channel (b) Only using H channel Figure 14: Results obtained using only one channel of the colour histogram for the training and prediction, where the x axis represents the number of elements per bin. For each value of x the average of ten executions has been calculated. In the bag of features step, the number of clusters was fixed to ten per object. the previous step. Table 1 shows the comparative using only S channel or using the two channels at once. The best result is achieved using b256/42c= 6 bins for saturation channel and b180/13c= 13 for hue channel, so these are the selected parameters for the colour descriptor. The resulting colour histogram has 78 bins which is a small value taking into account the obtained results. The confusion matrix using the named parameters can be seen in 34 that the system has the ability to predict some objects correctly, but has an obvious tendency to predict them as object 4. This could be explained because an extra part pointing out that it is object 4 (the hand) is added the descriptor, and sometimes this impact is big enough to produce a bad prediction. Figure 23: Results obtained while the objects were grasped. It has been made three tests for object. 41 19 Future work Until now it was explained all the things done in this project, but there are some extensions that could be done to improve it and new functionalities to add, here some of them will be explained. Invariance to drawers position. The scene used for the project has different sliding drawers. During the project they were used as fixed ones, so after the plane detection and limitation step they could not be moved because it provoked problems to the system. An extension of this project is presented to solve this problem. With the current version of the project, the planes coefficients and their limits are calculated only once. Instead of doing this, the mask used for the calculation of the planes could be updated every time a new image arrives and limits calculated periodically. This could be done because the planes coefficients do not change, only the limits change. Provide drawers positions. An other extension based on the previously explained is to provide the system with the position of the drawers. A very valuable information for robot trajectory planning. If the previous extension is implemented, the only thing that has to be done is to calculate the centroid of a plane using its limits. The position of this centroid indicates the position of the drawer. Dynamic number of limits in a plane. The project has the na¨ıve assumption that the number of limits of a plane is always four. This could not give good results in the real world. The idea is to use a number of limits depending on the shape of the plane. One idea is to define a maximum error between the original plane and the simplified, and use the minimum number of limits that provides with an polygon with an error less than the threshold. It has to be kept in mind that the number of points of a limit effects directly the total time of the segmentation step, for that reason a small number of them should be used. It is recommended to set a maximum number of points. Integration with a robot. A robot could be provided with the information extracted from this system in order to manipulate objects from the scene. Ignoring not learned objects The system is not capable of discarding objects obtained during the segmentation step. Using a learning model with the ability to provide a level of confidence of a result could be used to refine the outputs of the system, and only return the ones that are really likely to be correct. 42 20 Conclusions Starting with the general conclusions about the field of computer vision and machine learning, they are fields with a wide range of possibilities and opportunities, thing that not always makes easy to know what methods to use. For example in the specific case of the descriptors, use only a colour one? a shape one? or both? and finally, how they are joined if more than one is used? All this decisions must be made to advance in the project, but not always is easy make up your mind, and neither clear why an option is better than another one. Another example is the path done during the segmentation step and the recognition one, the project was started with general idea of what and how to do the things, but it was impossible to predict the exact steps for these two processes. Some elements were added after seeing the weaknesses to end up with a robust system. Another thing related with this is that a lot of steps are needed to make a recognition system, some of them that are non trivial. It is also seen that a plenty of algorithms of different fields of study are needed to achieve this, including geometrical ones, algorithms based on treatment of images and point clouds and machine learning methods. All these things made the problem to be really hard to solve, there is no perfect solution to solve the segmentation and recognition step, for these reason some assumptions were needed, and sometimes the only thing that could be done was minimizing the probabilities of error. Talking about the project itself, the objectives of the project were achieved. The system is able to recognise objects placed on a table, the only thing that must be made is start the system and it alone is capable of detecting the available planes and segmenting the objects. Moreover, the initial idea of detecting the objects of only one plane was extended to more than one with the possibility of some of them being one above the other. Tools to ease the work of training and the visualization of the results were developed. The project was finished using the time initially planned, some delays were faced but could be overcome without major problems. The same has happened for the economical planning. The conclusions about sustainability and social commitment are that this system does not contributes directly to the society, but it makes available a tool that could be used to easily make applications with a big impact in the society, so in the future it could have social impact. About the sustainability, it makes use of a big amount of resources without having direct impact to the sustainability. So in this case it could be said that it is not sustainable. 43 List of Figures 1 Example of the background subtraction method. . . . . . . . . . . . . . 3 2 Two cases of radial distortion. . . . . . . . . . . . . . . . . . . . . . . . 16 3 Image showing that the obtained point cloud is not perfect, some parts that should be plane are not, for example the wall and the table. . . . . 19 4 Example looking for four planes, all the points that are inliers of one plane are coloured in the same way. . . . . . . . . . . . . . . . . . . . . 20 5 Obtained results using the mask with different levels of normal filtering. 21 6 Points after using the bigger cluster as a representative for a plane. . . 23 7 The spheres represent the points of the convex hull, and the lines the limits of the plane after the polygon simplification step. . . . . . . . . . 23 8 Example of how it is seen the point cloud after the segmentation step. . 27 9 CVFH descriptor for two similar images. . . . . . . . . . . . . . . . . . 30 10 It shows the positions where the sets were trained. Training set (green), testing and validation sets (blue). . . . . . . . . . . . . . . . . . . . . . 30 11 Two examples of object 13 with different pitch angles . . . . . . . . . . 31 12 Results obtained training only with the colour descriptor, with 6 and 13 bins for S and H channel respectively. The training set consisted on 48 images..................................... 32 13 Original figure (left) and its region growing segmentation (right) . . . . 33 14 Results obtained using only one channel of the colour histogram for the training and prediction, where the x axis represents the number of elements per bin. For each value of x the average of ten executions has been calculated. In the bag of features step, the number of clusters was fixedtotenperobject............................ 34 15 Confusion matrix obtained using a colour descriptor with 13 bins for hue channel and 6 for saturation one. . . . . . . . . . . . . . . . . . . . . . 35 16 It contains the confusion matrix and the results using different metrics for the shape descriptor. As before the metrics are the result of a ten times execution and a value of cluster was fixed to ten per object. . . . 36 17 Results obtained changing the total sum of the colour histogram. . . . 36 18 Confusion matrix and result metrics obtained after joining shape and colour descriptors using the same weight. . . . . . . . . . . . . . . . . . 37 19 Results obtained after the recognition. The numbers on the objects are the predictions made by the system. . . . . . . . . . . . . . . . . . . . . 38 20 pepe ..................................... 39 21 The left image shows the obtained results predicting a variation of the object2(rightimage). ........................... 39 22 Results obtained with objects partially occluded. It has been made three testsforobject................................ 40 23 Results obtained while the objects were grasped. It has been made three testsforobject................................ 41 44 List of Tables 1 It shows the comparison between the obtained results using the parameters defined as good ones. S and H is shown in elements per bin. . . . 35 2 Used parameter values in RBF kernel. . . . . . . . . . . . . . . . . . . 38 3 It contains the time results using different versions of the code. The average of 50 segmentations have been made to extract the results . . . 47 45 Annex A: Implementations Plane segmentation Basic version This is the implementation of the segmentation step of the section 16. cloud contains the point cloud structure, mask contains the accumulated mask of planes, where -1 means that a point is part of a plane, 0 that is background and 1 is part of an object. planeCoef contains the coefficients of the plane and planeLimits its limits. The mask is initialized with all values to 0. 1// For each point in the pointcloud 2for(size_t j= 0;j<cloud->points.size(); j++) { 3 4if(isnan(cloud->points[j].x) continue; 5 6if (isInlier(cloud, j , planeLimits, planeCoef)) { 7Eigen::Vector4f pt(cloud->points[j].x, cloud->points[j].y, cloud->points[j].z, 1); 8float distance =distance(planeCoef, pt); 9 10 if (fabsf(distance) <= 0.015) { 11 mask[j] = -1; 12 }else if (mask[j] ==0and distance < 0.0){ 13 mask[j] = 1; 14 } 15 } 16 } This code is sequentially executed for each one of the planes that must be segmented. Line 4 avoids processing points that are invalid (coordinates set to NaN). In line 6 it is checked if the the point is inside the limits of the plane, in this case if it is also part of the plane the mask is marked properly (lines 10 and 11). Otherwise it could be above or below the plane, if its above (distance < 0.0) and the mask is marked as a background, the mask is set to be a part of an object. By doing this planes that are above the currently treated are not selected as objects. Optimizations This is a critical part of the system, it is executed every time a new point cloud arrives, so it is important to optimize it. An easily seen optimization is to reorder the operators to firstly evaluate the quicker ones. The evaluation of if a point was previously marked as a plane could be moved to the start of the code, this way it is avoided doing a lot of computations for sometimes do nothing when it is tested if the point is above the plane or not. 46 Version Time (ms) Original 180 Optimized 173 Parallel (2 threads) 112 Parallel (4 threads) 68 Parallel (6 threads) 55 Table 3: It contains the time results using different versions of the code. The average of 50 segmentations have been made to extract the results It is computationally less expensive to calculate a distance between a plane and a point that knowing if it is inside the limits, remember that for this last calculation an orientation test for each two points that define the boundary must be calculated, so this operation is linear in terms of the boundary points, while the distance is constant. 1for(size_t j= 0;j<cloud->points.size(); j++) { 2 3if(isnan(cloud->points[j].x) or mask[j] == -1)continue; 4 5Eigen::Vector4f pt(cloud->points[j].x, cloud->points[j].y, cloud->points[j].z, 1); 6float distance =distance(planeCoef, pt); 7 8if (distance >= -0.02) { 9if (isInlier(cloud, j , planeLimits, coef)) { 10 if (distance <= 0.02) { 11 mask[j] = -1; 12 }else if (mask[j] == 0){ 13 mask[j] = 1; 14 } 15 } 16 } Making it parallel The operations made are not dependent on other positions of the point cloud, so its parallelization is straightforward. OpenMP was used to achieve this, the only thing that has to be made is putting the following line of code just before the for to execute it using 4 threads. #pragma omp parallel for firstprivate(planeCoef, planeLimits) shared(cloud, mask) num threads(4) Results Table 3 shows the times obtained. it must be taken into account that this segmentation step is executed one time for each plane to segment, that with the scene used in the project is fixed to four. Finally it was decided to use the parallel version with 4 threads because it gives a good performance with not a big number of threads. 47 Polygon Simplification The general idea of the algorithm is to start with the complete polygon and at each step remove a vertex from it. The variable cis defined as an aleatory point of the polygon, being pand nits previous and next neighbours in clockwise order, and the area of the point cas the area between p,cand n. The original algorithm removed the point with minor area of the polygon. With the na¨ıve assumption that the planes are rectangular, this did not give the expected results, the system is dealing with convex polygons and it is wanted to end up with points that are at the extremes (that have smaller angle between them and their neighbours), condition that could not be accomplished if the area is used because the distance between points obtains a lot of importance. So it was decided to remove the points with bigger angle instead of points with smaller area. The algorithm is built in a iterative pattern. At each step removed the point cwith bigger angle, after this step the angles and neighbours of pand nneeded to be updated and cadded to a stack to keep track the order of the extracted points. This was done until four points remain to the polygon, these are the simplification of the polygon. The original algorithm does not define a number of vertices, instead it continues iterating until an error threshold is hit. Thanks the assumption of dealing with rectangular planes, the total number of returned vertices could be fixed. 48 Annex B: Used objects 1 2 3 4 5 6 49 7 8 9 10 11 12 13 50