scieee AI-readable full text Open interactive document viewer

Recognition of Visual Objects Using Mobile Devices

Hugo Filipe Coelho Duarte Teixeira

Full text

FACULDADE DE ENGENHARIA DA UNIVERSIDADE DO PORTO Recognition of Visual Objects Using Mobile Devices Hugo Filipe Coelho Duarte Teixeira Mestrado Integrado em Engenharia Eletrotécnica e de Computadores Supervisor: Luís Filipe Pinto de Almeida Teixeira March 22, 2013 c Hugo Filipe Coelho Duarte Teixeira, 2013 ii Resumo A proliferação de smartphones abre a oportunidade a aplicações de visão de computador que interagem com o mundo real de tornarem-se acessíveis. O objetivo deste projeto é desenvolver uma aplicação Android que funcione em tempo-real e seja capaz de reconhecer cartazes de filmes, e como consequência, descobrir o filme correspondente. Uma imagem é capturada pela câmera do dispositivo e uma descrição desta é extraída. Esta Dissertação considera duas abordagens: numa a imagem é processada no dispositivo e na outra é o servidor que está encarregue dessa tarefa. O servidor compara então a imagem do dispositivo com os cartazes existentes na base de dados. Vários detetores de pontos de interesse e descritores desses mesmos pontos são testados de forma a avaliar quais os viáveis de serem utilizados em tempo-real. Concluímos que ainda é cedo para tentar realizar estas operações que são computacionalmente exigentes no smartphone atual com os detetores de pontos disponíveis de forma livre, logo, a abordagem utilizada é a que envolve o servidor processar a imagem. iii iv Abstract The proliferation of smartphones has given the opportunity for applications that aim to interact with the real world to become accessible. The aim of this project is to develop a real-time Android application that is capable of recognizing a movie poster and, thus, the identity of the corresponding movie. An image is captured through the device’s camera and a compact description of this image is extracted. This Master Thesis considers two approaches. In the first approach the image is processed in the device and in the other the server performs those tasks. The server then cross-matches the image using a database of known movies. Various feature detection and description extraction algorithms were tested in terms of speed and recognition performance to determine which are suitable for a real-time scenario. We concluded it is still too early to attempt to execute these computationally expensive tasks in the modern smartphone with the free licensed available feature detectors, so the second approach is the one we implement. v vi Acknowledgements To Prof. Luís Filipe Teixeira, for his orientation during this semester. His patience and uncanny ability to teach and motivate me were crucial factors in this phase of my academic life. To all my friends, who have accompanied me these years. You make my life brighter. A special appreciation must be left here to my parents and the rest of my family. I know you made many sacrifices for me to have this opportunity, even though I wasted it in the beginning. To the reader, whoever you might be, I hope you enjoy reading this thesis as much as I enjoyed writing it. Hugo Filipe Teixeira vii xiv LIST OF FIGURES List of Tables 2.1 Test Results for Android NDK . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.1 Image dimension reduction tests performed on the mobile device. Time is in ms . 28 4.2 Feature detectors tests performed on the mobile device. Time is in ms and N is numberofkeypoints. ................................ 29 4.3 Feature detectors tests on the server. Time is in ms. . . . . . . . . . . . . . . . . 30 4.4 Description extractors tests performed on the mobile device. Time is in ms and does not include feature detection time . . . . . . . . . . . . . . . . . . . . . . . 31 4.5 Overview of the test results for the mobile device. Time is in ms . . . . . . . . . 32 4.6 Description extractors tests performed on the server. Time is in ms and does not include feature detection time . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 4.7 Overview of the test results for the server. Time is in ms . . . . . . . . . . . . . 33 4.8 Image matching tests with the FREAK OpenCV demo configuration . . . . . . . 34 4.9 Image matching tests with the FREAK OpenCV demo configuration to ideal test images........................................ 34 4.10 Performance of the remaining algorithms in contention for approach 1 . . . . . . 35 xv xvi LIST OF TABLES Abreviaturas e Símbolos BRIEF Binary Robust Independent Elementary Features BRISK Binary Robust Invariant Scalable Keypoints FAST Features from Accelerated Segment Test FLANN Fast Library for Approximate Nearest Neighbors FREAK Fast Retina Keypoint GFTT Good Features To Track GPS Global Positioning System OCR Optical Character Recognition ORB Oriented FAST and Rotated BRIEF RANSAC RANdom SAmple Consensus RFID Radio-Frequency Identification SIFT Scale-Invariant Feature Transform SURF Speeded Up Robust Features TCP Transmission Control Protocol xvii Chapter 1 Introduction This chapter presents the motivation of this Master Thesis, explains its objectives and concludes describing the structure of this document. 1.1 Motivation For the last few years, smartphones have been replacing feature phones, as shown in Figure 1.1. These mobile devices possess much greater and diverse computational capabilities and have integrated additional hardware such as high-quality video cameras, GPS, touch-screen, network capabilities and accelerometers, among others. The combination of these factors provides an excellent opportunity for the development of applications that can interact with the environment the user resides, since it is the first time devices with these characteristics are widely available and cost accessible. Computer vision is a field of technology that generates a lot of interest since it is a requirement for the use of augmented reality (AR). AR opens the possibility for many potential ways of revolutionizing everyday tasks, given that it can have useful applications in so many fields such as medicine, architecture, commerce, military, educational, etc. The problem is that it requires computationally tasks to be performed and either have a pre-defined environment or small devices with great processing capabilities. Devices like these have existed and been used for some time but never to such a mass market. Now, with the factors previously mentioned and the announcement by Google of their new product Google Glass, a head-mounted display, the global conjuncture is very favorable for the type of application we propose to develop. 1.2 Objectives The application must be capable of recognizing movie posters present in the video feed provided by a mobile device’s digital camera. After matching the poster with its respective movie, the user is shown related information: the movie title, who is the director and protagonists. From this 1 2Introduction Figure 1.1: Evolution and comparison of smartphones and feature phones point the user can access more information, such as watch the trailer, synopsis, the director’s or the cast’s detailed information, movie theatres and available sessions, etc. To provide access to the data required for these functionalities, this project is developed in cooperation with SAPO Cinema, an online service dedicated to movies. It must function in real-time, which means one of the challenges is to process images in a short amount of time. There are very restrictive limits to internet traffic in the available cost plans so we intend to reduce the amount of data transferred in the network to the possible minimum. Another important consideration is the size of the application, given current memory constraints in these devices. It is important to mention this Master Thesis is integrated in AROS - Análise e Reconhecimento de Objetos, meaning analyses and recognition of objects, in cooperation with SAPO Laboratórios. AROS is a project with the duration of one year so some objectives were not implemented during this dissertation, which focuses on the aspect of computer vision, meaning the movie poster analysis and recognition. However, all elements of the system were taken in consideration and planned, although further changes may be necessary since the system as a whole was not tested. 1.3 Document Structure This document is composed of five chapters. Chapter 1, Introduction, contains the motivation for the development of this project and explains its objectives. 1.3 Document Structure 3 Chapter 2, Literature Review, contains the state of the art of the technologies and applications that concern computer vision and the theme of the project. Chapter 3, Application Development, explains the process of development of the entire system. Chapter 4, Tests, shows the tests and results obtained during this Master Thesis. Finally, Chapter 5, Conclusions and Future Work, presents the conclusions derived from this project and discusses future work required for the completion of the system. All chapters, except the current one, start with a brief introduction to the topics in it discussed and end with a summary of the chapter’s content. 4Introduction Chapter 2 Literature Review This chapter aims to present a literature review concerning the implementation of computer vision in an Android mobile device application with a small AR component. Various different approaches and techniques are analyzed in order to determine their usefulness in the context of the desired application, as well as their limitations. AR can be defined as the insertion of virtual objects in a representation of the real world that aims to stimulate the human senses, especially sight and hearing. This type of application is conventionally used in real-time and in context with the environment surrounding the user. Its display can be achieved by a variety of devices. Headmounted displays, like glasses, are a common choice, since it allows the user to have both hands free and the system is subjected to the physical viewpoint of the user, providing an immersive experience. There is also the possibility of using projection devices to display virtual objects onto the surface of real objects, which would free the user of the need to carry with him any kind of device. Finally, the display can also be achieved by handheld devices such as smartphones. This thesis will infer on this type of display. Since the appearance of operating systems like Android, iOS and Symbian, mobile devices have achieved a computational power that allows them to have access to high definition cameras, which in turn can be used by computer vision and AR applications. Therefore, mobile device applications that use this technology are fairly recent. Despite this, there is already a considerable amount of published material concerning both the technologies and the applications of object recognition, though not necessarily movie poster recognition. 2.1 Tracking Techniques One of the main problems to be considered when developing this type of application is which tracking technique [1] to implement. Modern mobile systems generally have one or more of the following devices: digital cameras, optical sensors, accelerometers, Global positioning system (GPS), gyroscopes, solid state compasses, radio-frequency identification (RFID) and wireless sensors. This section’s goal is to review the various tracking techniques. 5 12 Literature Review display of information relative to the identified object to the user, an AR component like we have in our system. It also provides a mechanism of avoiding processing low quality images by analyzing the mobile device’s motion. Like our system, it was implemented on an Android smartphone and managed to reach a latency of 1 second. Ultimately, the big difference is the fact that all the image processing is done in a server, which is not our main objective. This forces the application to send the whole picture, which is not compatible with our aim of being mindful of existing wireless bandwidth limitations. Figure 2.4 provides an example of the application functioning. Figure 2.4: Example of Chen et al. application of recognizing book spines. Image source is the respective article Takacs et al. [12] developed an application that recognizes locations. They perform all processing stages in the mobile device. This is possible because they send their GPS coordinates to a server, which, based on those reading, only returns highly relevant features to the device. Thus, the amount of image matching necessary to encounter the right match is significantly decreased. The algorithm used is a modified version of SURF developed by them to achieve greater speed, and thus, be viable to use in a mobile device. Also, network latency is avoided since client-server communication is only required once per location. The relevant information is then displayed on the screen for the user to see, an AR component similar to the one our project requires. Figure 2.5 shows an example of the application working. Xiong et al. [13] work is also based on a client-server architecture that allows the identification and recognition of traffic signals from a picture taken with a mobile device. All the image processing, which is based on color features, is performed on the server, unlike in our application. LTU Technologies have created an application that is also based in movie poster recognition named Trailr [14]. However, it does not function in real-time, but rather requires a picture and 2.6 Summary 13 Figure 2.5: Example of Takacs et al. application of recognizing outdoor locations. Image source is the respective article the only information it presents the user is the trailer. This is achieved by the LTU Engine, a licensed software they have developed. Although this application already performs movie poster recognition, given that it is not free, does not function in real-time and only returns one type of information, the trailer, about the respective movie, our project still has a great value. 2.6 Summary Object recognition can be divided in two types: maker-based and not mark-based. The use of markers simplifies the complexity of the application, given that the creator chooses its marker’s form and designs to better and easier be recognized by the system but requires a change in the environment which, besides diminishing the realism of the experience, becomes impossible in our case given we cannot control every environment with a movie poster. Considering this, our application is necessarily not marker-based. This kind of object recognition is performed in stages: detect points in the image that are of interest, describe those areas and try to match these points between two images. There are various algorithms that perform these tasks. Given this constraint greatly increases the complexity and the computational cost of the project, most systems similar to ours include a server component that aid in the most taxing tasks. The mobile device used is a smartphone with the Android operating system. As for the computer vision library used, OpenCV is the only free available one for Android. No similar applications that recognize movie posters were found during our research but there are a variety of object recognition programs which share many of the same objectives, attributes and limitations that our system has. 14 Literature Review Chapter 3 Application Development This chapter aims to present the different stages of planning and development throughout the duration of this Master Thesis. It is divided in three sections. The first one gives an overview perspective of the whole system and explains the choices taken in its design. The next section provides a guided sequential explanation of the tasks performed by the client and the server application, in greater depth than the first section, as well as general ideas for the interaction of the online service with the rest of the system. To conclude the chapter, a summary is presented. 3.1 System Architecture As mentioned in Chapter 3, the main objective is to identify movie posters by interacting with the online service SAPO Cinema. The main component of the system is the mobile device. The chosen operating system is Android, which uses Java as the main programming language, inheriting basic classes from conventional Java and adding new classes specific to the needs involving the development of a mobile device’s application. The Android SDK provides the option, when creating a new Android project, of choosing a target API and a minimum required API. For this project we chose the latest Android API, API 17 and as a minimum API 8: Android 2.2, also known as Froyo, which is estimated to reach around 95% of the market. If a user with API 8 runs the application certain details may be different, such as font or other minor differences, but the main tasks will still function. To provide the movie information required, the online service SAPO Cinema is used. Since this Master Thesis is part of a SAPO project, as described in Chapter 1, we will be provided access to it. After some consideration, we concluded it would be very beneficial to add a server to the system. This inclusion brings a variety of advantages. The server is equipped with a much higher computational power than the mobile device so it provides the option of performing computationally expensive tasks in a more adequate machine. Another advantage is that improvements done to the server instantly benefit the application performance without the need for the user to update the application. The server possesses a database, built using the online service, that contains the 15 16 Application Development Figure 3.1: System architecture; left: mobile device, top right: server for image matching and basic information, bottom right: online service SAPO Cinema most commonly needed information for the user, such as movie title, director, protagonists, among others. This information is delivered to the device and displayed in the screen. If the user requires more information he can request it by pressing the already displayed information. For example, if a movie is recognized its director is displayed on the screen and the user can click on his name. Then the device will communicate with the online service and provide more detailed information about him, such as his filmography. This is also true for the movie title, main actors, and other information we choose to display in this initial stage. Since the user may be satisfied with the movie’s basic information, the online service may not be solicited, saving resources and traffic bandwidth. The usual disadvantage in a cloud computing configuration is the dependency on the network. If a user has no internet connection or if the connection is slow, the functioning of the application is impaired. However, since the online service is an inevitable component of our system then the insertion of a server should not harmfully influence the efficiency of the system. It creates, however, the need of regular supervision and maintenance since the server has to be operational at all times. In Figure 3.1, a simplified description of the system can be seen. The server is very useful since we have no guarantee the device can perform the required tasks with satisfying results fast enough to be considered real-time. Therefore, two different approaches can be considered: either perform the feature detection and extraction in the mobile device, which we refer to as approach 1, and the server concludes with the image matching or send to the whole image to the server, which then performs all stages of the poster recognition, which is approach 2. The first one is the preferred approach but given that there is no guarantee it is possible to successfully develop it in a real-time context we find it useful to consider the second approach as a backup solution, given we already require a server. Both have their benefits and limitations. The first approach, since it performs feature detection and description in the device, executes these tasks slower than in the other approach, in which they are responsibility of the server. However, the second approach requires the device to send the whole image to the server, instead of just its keypoints and descriptors, which are a much smaller 3.2 System Dynamics 17 size compared to the image, meaning this configuration consumes significantly more bandwidth traffic, an important factor given the limitations discussed in Chapter 1, and a larger communication time. A representation of this system using the first approach can be seen in Figure 3.2 and a similar representation of the second approach in Figure 3.3. The tasks depicted in the figures are explained in greater detail in the next section. 3.1.1 Database of the Server Since the added server is supposed to provide basic movie information, it needs to have its own database. With that in mind, and after considering which is the most fundamental information about a movie, we designed the entity-relationship model present in Figure 3.4. The entities are the four informations the user is shown in the initial stage: movie title, director, main protagonists and genre. Therefore, their attributes are mainly the name and respective code identification. The only entity that is different is Movie, because it needs two extra attributes to perform image matching: the poster, which is the image that is compared to the frame from the device and the movie’s release date, to determine the order the image matching is supposed to follow. This last reason is explained in Section 3.2. 3.1.2 Class Diagram In order to support the development of the application, the class diagram in Figure 3.5 was devised. The MainActivity class is the default launcher class of the application and it has methods to determine if the pre-requisites for the good functioning of the application are present and activated in the device. The CameraHandler class, as the name suggests, manages the use of the application while the camera is functioning. Communication is tasked with managing all communication device-server and device-online service. The other four classes are designed to support the data storing of the information meant to be displayed to the user. The server also possesses these last four classes since their member’s values are calculated from the database results. 3.2 System Dynamics In this section the sequential steps performed by each component of the system are divided in stages and explained in detail. 3.2.1 Mobile Device The application in the client runs on Android operating system and was developed in Java with the functions provided by Android SDK and the OpenCV library. 18 Application Development Figure 3.2: System design using the first approach 3.2 System Dynamics 19 Figure 3.3: System design using the second approach 20 Application Development Figure 3.4: Database of the server that contains basic movie information and the data required for image matching Initialization The application was developed using OpenCV’s latest version, which is 2.4.3. As mentioned in Chapter 2, Section 2.4, this version possesses the Android service OpenCV Manager, which we implemented in this project. Therefore, the first task the application performs is to check if the device has the service installed and, in case it is not, to allow the user be automatically directed to Google Play Store, an online service that provides Android applications. Next the application checks if the device can provide access to a digital camera and if it is connected to a network. In case one or both of these requirements are not satisfied the application does not allow the user to proceed since it would not by able to function in any capacity. Otherwise it advances be starting the camera. Image Capture In this stage, the application regularly saves a frame of the video to be processed. The frequency in which this is performed depends on the execution time we manage to achieve for the image processing stage. To avoid wasting resources in images that are blurred or of no interest, the frame is only taken if certain conditions are satisfied. If the device has a gyroscope and an accelerometer those components are used to determine if the camera is steady. In case the device does not possess such hardware the difference between two consecutive frames is used to determine the stability of the video. This is done because if the camera moves too fast the frame is 3.2 System Dynamics 21 Figure 3.5: Class diagram devised to support the development of the aplication blurred and so it is not suitable to be analyzed and it would be a waste of resources. Even if the image is not blurred too much movement would mean the user is still pointing the camera at the desired object and it is not yet necessary to process the frame. When a frame is indeed captured, the next stage begins. Figure 3.6 shows two pictures of the same movie poster but only one is a good candidate to perform image match while the other is blurred and most likely would not result in a successful match. Figure 3.6: Examples of two video frame: left is a good quality image and should be processed; right: a motion blurred image that should not be processed Image Pre-Processing It starts by scaling the image so neither its width or height surpasses 300 pixels. Due to the limiting computational power of mobile phones, trying to process an image with the default size taken by the camera is not possible in a real-time context. After the image’s size is reduced it is 28 Tests have only a partial part of the poster, some are of illuminated posters and some are frontal ideal pictures. Figure 4.1 presents a few examples. Figure 4.1: Examples from the dataset. It is important to note that the initial tests are all performed with OpenCV’s default parameters. 4.2 Pre-Processing Efficiency Android programming presents various different methods of achieving the same result. Given the importance of the time factor, one of the tasks continuously performed during the application development was measuring the time of execution for these different methods that resulted in the same output to determine which to use. This resulted in the implementation of the OpenCV class that handles the digital camera instead of the Android default class that handles that functionality. Another occasion this proved valuable was in the transformation of the image to greyscale space color. In the first approach, in which the device performs feature detection, due to its limiting computational power the image needs to be reduced in size before initiating this stage. This should not pose a problem since most feature detectors are scale-invariant. Therefore, all images are reduced to a dimension in which neither its height or width surpasses 300 pixels, maintaining the same width:height ratio. This is the dimension by which the feature detection and description extraction did not consume too much time. For the second approach, since the machine that performs the tasks has a considerably higher computational power, no reduction is necessary. For the purpose of these tests five different images are used, with the size of 1500x2000 pixels. Table 4.1: Image dimension reduction tests performed on the mobile device. Time is in ms Image time skyfall3 25 skyfall4 31 skyfall5 22 hobbit1 44 balas1 23 4.3 Features Detection 29 As Table 4.1 shows, the process of modifying an image’s size and transforming its space color is considerably fast and, therefore, adequate for a real-time context. These tests also include the conversion of the Bitmap object to a Mat, preparing the test image for its next stage. An entire image’s size, after its reduction and space color transformation, is around 60 kbytes. This size varies little between images. The features and descriptors size is variable, depending on the used algorithms. However, we can be sure they are considerably smaller than the complete image. The parameters of these algorithms, both detectors and descriptors, are as follows: •FastFeatureDetector(threshold=1, nonmaxSuppression=true, type=2); •GoodFeaturesToTrackDetector(maxCorners=1000, qualityLevel=0.01, minDistance=1, block- Size=3, useHarrisDetector=false, k=0.04); •Harris is like GoodFeaturesToTrackDetector with useHarrisDetector=true; •StarFeatureDetector( maxSize=16, responseThreshold=30, lineThresholdProjected = 10, lineThresholdBinarized=8, suppressNonmaxSize=5 ); •ORB(nfeatures=500, scaleFactor=1.2f, nlevels=8, edgeThreshold=31, firstLevel=0, WTA- K=2, scoreType=HARRIS-SCORE, patchSize=31) The default HARRIS-SCORE means that Harris algorithm is used to rank features; •SIFT(nfeatures=0, nOctaveLayers=3, contrastThreshold=0.04, edgeThreshold=10, sigma=1.6); •SURF(hessianThreshold, nOctaves=4, nOctaveLayers=2, extended=true, upright=false); •FREAK(orientationNormalized=true, scaleNormalized=true, patternScale=22.0f, nOctaves=4); •BriefDescriptorExtractor(bytes=32); 4.3 Features Detection For this stage the transformed image is analyzed for points of interest using a specified feature detector and the results are saved in a MatOfKeyPoint object. Table 4.2 shows the results concerning the execution time and number of keypoints detected using the available feature detectors for each of the test images. Table 4.2: Feature detectors tests performed on the mobile device. Time is in ms and N is number of keypoints. Image FAST GFTT HARRIS ORB STAR time N time N time N time N time N skyfall3 26 1479 385 774 362 328 108 451 117 57 skyfall4 27 1444 384 838 359 294 93 450 118 39 skyfall5 33 1733 382 942 359 391 113 454 120 95 hobbit1 24 1263 374 612 354 120 79 432 117 27 balas1 29 1438 408 825 362 219 97 428 116 32 30 Tests As mentioned in the previous chapter, SIFT and SURF were not included in these tests since they are not available in the latest version of OpenCV for Android. Given that speed is not a characteristic of these algorithms this should not influence the final application. Considering the real-time requisite, GFTT and HARRIS are excluded from consideration, given their relatively high execution time. Also, they are simple corner detectors and, consequently, are not scale invariant. Other algorithms tested included BRISK, which required several seconds to initialize the FeatureDetector object and MSER, which continuously crashed the application, for unknown reasons. Taking into account all this data, the only algorithms in consideration for the first approach were FAST, ORB and STAR. FAST is clearly the fastest feature detector but it also is the one that detects more keypoints by a large margin. This will certainly impair the next stage, since more points will require description. ORB and STAR have similar execution times but ORB detects a much greater number of points of interest, although considerably less than FAST. The same test was performed in the server, since, in case of implementing approach 2, it is this system component that is tasked with this processing stage. In this instance the SIFT and SURF algorithms are still available, even for the same OpenCV version, and therefore are considered as possible feature detectors. The results can be seen in Table 4.3. Table 4.3: Feature detectors tests on the server. Time is in ms. Image FAST GFTT HARRIS ORB STAR SIFT SURF time time time time time time N time N skyfall3 12 228 236 48 218 423 116 945 330 skyfall4 11 229 233 46 216 437 104 927 325 skyfall5 13 233 230 50 219 415 127 1009 536 hobbit1 8 234 242 41 214 381 366 822 97 balas1 6 158 158 32 116 243 125 520 421 We can see the results are consistent with the ones obtained previously although with the expected shorter execution time given the greater computational power of the server relatively to the device. The number of keypoints is the same so there is no need to show them except for SIFT and SURF since they could not be tested before. Even though the execution time of these two algorithms are high, given their known success over the years in other applications, they may be considered in the future, if the other algorithms do not provide adequate results. It should also be possible to diminish these execution times considerably by reducing the image’s dimension and configuring the parameters by which they operate. 4.4 Descriptors Extraction 31 4.4 Descriptors Extraction After the image’s points of interest have been detected the next stage consists of extracting information that characterizes each keypoint, so they can be compared. Like in feature detection, there are several algorithms provided by the library to perform this task. The feature detectors that were excluded in the previous section will not be tested. The available description extractors are BRIEF, FREAK and ORB. All three are tested with each feature detector. Table 4.4 shows the results on the device. Table 4.4: Description extractors tests performed on the mobile device. Time is in ms and does not include feature detection time Image Detector BRIEF FREAK ORB FAST 210 230 704 skyfall3 ORB 104 7 440 STAR 22 13 72 FAST 183 194 744 skyfall4 ORB 107 8 455 STAR 17 9 51 FAST 244 270 870 skyfall5 ORB 98 8 457 STAR 39 20 96 FAST 200 234 843 hobbit1 ORB 102 5 425 STAR 15 7 45 FAST 169 175 623 balas1 ORB 93 8 419 STAR 15 6 57 An important observation is that FREAK tests, in reality, always surpassed 6500ms. These results did not match our expectations since it was one of the more promising algorithms, being the most recent and developed with the requirements and limitations of a mobile device in mind. Upon further research and tests, we concluded the memory allocation performed for this descriptor extractor is what caused the delay. Considering this we performed tests where the descriptors are extracted twice to the same FREAK object and the results are the ones shown in Table 4.4. With all these factors in mind, the algorithm is still a contender, although it would force the application to possess a 6 second initialization every time the user initiates the application. There may also be other solutions for this problem so, for now, we will ignore this limitation. Table 4.5 shows the overall results for all combinations of feature detectors and description extractors. ORB as a descriptor extractor is clearly the most taxing on the application so it is out of consideration. FREAK is the fastest but BRIEF also performs in an adequate time. Like in the previous stage, the same tests were performed in the server, to consider for the second approach. The results are in Table 4.6. 32 Tests Table 4.5: Overview of the test results for the mobile device. Time is in ms BRIEF FREAK ORB FAST 229 249 785 ORB 199 105 537 STAR 140 129 182 Table 4.7 presents the overall results for the server concerning the execution times of the feature detection and description extraction stages. All algorithms proved to be adequate for realtime application. 4.5 Pattern Matching Figure 4.2: Example of a successful image match This stage is exclusive to the server, since the movie poster database is required to perform the comparison between the test image and the train images. The results obtained in the previous section show that FREAK is the fastest description extractor in using two of the three feature detectors, narrowly losing to BRIEF when FAST is used, so our efforts will be focused on using it. OpenCV provides the sample code of a FREAK demonstration that uses SURF as a feature detector with configured parameters. SURF as a feature detector allows the customization of the Hessian threshold, by which only features above that value are retained by the detector, the number of the Gaussian pyramid octaves that it uses and the number of images within each octave of a Gaussian pyramid. OpenCV documentation does not specify the default value for the threshold but it suggests reasonable values a number between 300 e 500 and the number of octaves by default is 4. The FREAK demonstration uses a threshold of 2000, which diminishes the number of points of interest, and uses the default number of octaves. The use of this configuration reduced SURF feature detection to about half its value with the default parameters and produced the results present in Table 4.8, with an example of a successful match in Figure 4.2. 4.5 Pattern Matching 33 Table 4.6: Description extractors tests performed on the server. Time is in ms and does not include feature detection time Image Detector BRIEF FREAK ORB FAST 55 102 57 skyfall3 ORB 9 60 64 STAR 12 65 19 FAST 52 98 56 skyfall4 ORB 9 60 66 STAR 11 60 19 FAST 57 106 59 skyfall5 ORB 9 58 64 STAR 12 77 18 FAST 38 91 46 hobbit1 ORB 9 59 62 STAR 9 58 16 FAST 26 76 30 balas1 ORB 6 56 40 STAR 6 55 11 The absolute value mentioned in the previous chapter that is used to evaluate to narrow the number of matches is 50. This value should be dependent on the size of the descriptor. In the case of FREAK, which has 64 binary strings in each descriptor, the ratio between threshold and descriptor size is of around 0.78. Various rations were tested, since we did not find a more scientifically good method to determine it. However, we can consider our dataset, given its diversity, to be a good example to real world application. Considering this, there should be no problem in its application. If needed, we can reduce the image’s size before detection, which is not very computationally expensive and allows a considerable reduction in feature detection time. Other solution would be to improve the server’s computational power. Known movies are movies that are in the database and being incorrectly identified means the match found was incorrect or that there was no match found. Unknown movies are not in the database and correct identification means no match was found. The success rate of the application was of 71% and the average time each picture needed to be matched with all train images was 32 ms. These can be considered good results given the dataset is composed of several images that provide certain problems such as difficult angles, images taken from a far distance and illuminated movie posters. It is also interesting to test the system in the case of ideal conditions. These Table 4.7: Overview of the test results for the server. Time is in ms BRIEF FREAK ORB FAST 56 105 60 ORB 51 102 102 STAR 208 63 214 34 Tests Table 4.8: Image matching tests with the FREAK OpenCV demo configuration # correctly # incorrectly identified identified Known movies 35 13 Unknown movies 2 2 circumstances are the ones we expect the users will mostly use the application so it is important to measure its efficiency in such situation. Table 4.9: Image matching tests with the FREAK OpenCV demo configuration to ideal test images # correctly # incorrectly identified identified Known movies 20 2 Unknown movies 2 1 Table 4.9 presents the results for the ideal pictures dataset, achieving 80% of matching success, a good improvement from the original dataset. A further increase of the Hessian threshold to 3000 provoked an improvement. While one of the posters correctly matched to its database counterpart now did not match, two of the false matches were now correctly categorized. However, the new parameter value greatly reduced the efficiency of non-ideal images. Perhaps the most impressive is the fact that practically no false keypoint matches occur. As previously explained the system attempts to match keypoints from the test image with keypoints from the train image. The train image that results in more matches is the one chosen to be considered a successful match, if a minimum number of matches is achieved. In this configuration, comparison between the test image with train images that were not the correspondent one mostly resulted in 0 matches. Our tests also recorded the number of feature matches every successful image match. None of them performed less than 4 matches. In fact, more than half of them were exactly 4 matches. This is the minimum value of matches it will require for the server to provide the client with a response. This rate of successful matches is a good result but SURF cannot be used in the first approach, since its module is not included in the latest OpenCV for Android. Even if it was, given the results for the server, it would most likely have a long execution time and, therefore, not possible to be viable choice. This is an adequate solution in case of the implementation of the second approach but for the first approach we need to consider other alternatives. The execution times obtained in the previous section, although a requirement to the whole image processing phase is not a guarantee of a short execution time for matching. The higher the number of keypoints the more strain it causes the algorithm. The quality of the descriptors is also crucial to ensure the a match between keypoints is indeed a true match. In order to decrease the number of possible configurations, they were all tested, using a small part of the dataset and the algorithm’s default parameters. The percentage of successful matches and the time required 4.6 Summary 35 Table 4.10: Performance of the remaining algorithms in contention for approach 1 BRIEF FREAK ORB % time % time % time FAST - - - - - - ORB 19 104 25 1 28 39 STAR 16 136 22 91 6 95 to match two images will be analysed and, hopefully, present a configuration that is superior to others. The results can be seen in Table 4.10. FAST results were not computed since its execution time is too elevated, achieving values from 1s to 20s, with any descriptor. This happened due to the fact that FAST generates too many keypoints, greatly increasing the computational cost of the image matching stage. The other results were not good either. Although the speed of the system is more adequate to real-time use, the rate of successful matches is very low compared to the SURF-FREAK configuration. Furthermore, they all generated many false matches, varying immensely from match to match, proving it would be difficult to determine a good minimum number of matches in order to respond to the client before completing the image matching stage with all database images. 4.6 Summary The tests consisted of comparing 75 images, from 27 different movies, of three different quality smarphones, to 352 train images. The test dataset consisted of images of different angles, distance and lightning conditions. The first stage was to perform tests with only speed in consideration and exclude the feature detectors and the description extractors that could not be applied in a real-time context. In the end the remaining detectors were FAST, ORB and STAR, with SIFT and SURF still an option in case of implementing the second approach to the system. As for the extractors, BRIEF, FREAK and ORB, ORB was the only the worse execution times but could still be considered if its performance was good. The feature detector FAST, that generated too many keypoints, resulted in the worst execution times because of having too many interest points described and matched. The only configuration that proved to be a viable candidate to implement was SURF-FREAK. 36 Tests Chapter 5 Conclusions and Future Work This chapter’s intent is to infer on the work’s achieved objectives. It will also open new paths for the work developed. In the case of this project, since it is a one year work, it also comments on the components that still requires implementation. 5.1 Conclusions When assessing the work carried out during this Master Thesis it is important to mention it is part of a project with the duration of one year, this being the beginning of said project. This means various parts of the project were left in the planning stage and still have not been implemented. We focus on the computer vision part of the system, meaning the recognition of movie posters through a smartphone digital camera. Our goal was always to attempt to process the image in the device, but given that there were no guarantees this would be possible we devised a contingency plan in which our server would perform those tasks. The main problem is that these stages can only be performed by computationally expensive functions, proving difficult its adaptation to a real-time system. With that in mind we performed tests in both situations. The configuration that performed the best results, satisfying both main factors of measure, speed of execution and rate of successful matches, used SURF as a feature detector, with personalized parameters: an increase of the Hessian threshold to 2000. FREAK is the description extractor and this pair obtained rate of successful matches of 80% only consuming an average of 32 ms for each match. Feature detection required about 500 ms to be performed but can be considerably decreased by reducing the image’s size and FREAK provided the descriptors in about 12 ms. Unfortunately the available algorithms to OpenCV’s Android version could not provide a satisfying result and so we must concentrate further developments with the first approach excluded. Considering the required communication, which we could not test to evaluate latency in a proper environment, we expect the application can perform a full analysis of a video frame somewhere between 0.5 s to 1 s. 37