International Journal of Electrical and Computer Engineering (IJECE) Vol. No. February 2017, pp. ISSN: 2088-8708. DOI: 10. 11591/ijece. An Accurate Scheme for Distance Measurement using an Ordinary Webcam Hossein Zivarian. Mohammad Hossein Doost Mohammadi Department of Electrical Engineering. Hamedan University of Technology Article Info ABSTRACT Article history: Nowadays, image processing has become one of the widely used computer aided science. Two major branches of this scientific field are image enhancement and machine vision. Machine vision has many applications and demands in robotic and defense industries. Detecting distance of objects is one of the extensive research in the defense industry and robotic industries that a lot of annual projects have been involved in this issue both inside and outside the country. So, in this paper, an accurate algorithm is presented for measuring the distance of the objects from a camera. In this method, a laser transmitter is used alongside a regular webcam. The laser light is transmitted to the desired object and then the distance of the object is calculated using image processing methods and mathematical and geometric relations. The performance of the proposed algorithm was evaluated using MATLAB The accuracy rate of distance detection is up to 99. The results also has shown that the presented algorithms make the obstacle distance measurement more reliable. Finally, the performance of the proposed algorithm was compared with other methods from different literatures. Received Aug 6, 2016 Revised Oct 28, 2016 Accepted Nov 13, 2016 Keyword: Distance measurement Image processing Laser canon Machine vision Copyright A 2017 Institute of Advanced Engineering and Science. All rights reserved. Corresponding Author: Mohammad Hossein Doost Mohammadi. Department of Electrical Engineering. Hamedan University of Technology. Mardom St. Shahid Fahmideh Blv. Hamedan. Iran. Email: doost. mohammadi@hut. INTRODUCTION Assistive technology has always been demanded for machines and robots in industry and basic One of the most important demands is to enhance the intelligent vision of these systems. However, with the advancement of technology, the development of such devices has been possible. Also in this field, the real-time imaging under dynamic conditions is very important. Given this scenario, the smart vision of mechanized robots is one of the most important factors to consider in today's industry. For example, this is very important to know the distance of the obstacles around the robot in a chemical plant or a sensitive production line of a factory. Some efforts have been made to develop these devices, to equip these robots with virtual vision, and making them awared of more environmental information. Most of these new tools to achieve this goal are based on ultrasound technology. Wu et al. used sonar system together with some filtering method to detect objects on seafloor with appropriate resolution . Fei-yu also used sonar system to measure obstacle distance . Unfortunately in most cases, the distance measured by these devices and their response time in some applications, is not accurate and fast enough. Improvement of these systems with the high measurement accuracy and the appropriate accountability, entails costly measures. Chang et al. presented an ultrasonic devices for distance measurement which was fabricated and test to improve the distance measurement limitation . Kim et al. presented a new distance measurement method with the use of a single camera and a rotating mirror. A camera in front of a rotating mirror acquires a sequence of reflected images, from which distance information is extracted . Rahman et al. proposed a novel distance Journal homepage: http://iaesjournal. com/online/index. php/IJECE A ISSN: 2088-8708 measuring system based on eye-distance. The distance between centers of two eyes is used for measuring the person to camera distance . Mohammad used the infrared (IR) together with ultrasonic (US) sensors to improve the overall vision systems of mobile robots . Xiaoming et al. proposed a real-time method which can measure distance using a modified camera. This method can only be performed within 3. 21ms to achieve acceptable accuracy . Shrivastava et al. presented a distance measurement of an obstacle using separate ultrasonic transmitter, receiver and a P89C51RD2 microcontroller . Jinjin et al. introduced a single bit cross correlation method to improve the range resolution of the ultrasonic distance measurement . In this paper, we are looking for more advanced features and optimized basic design to achieve the eligible design criteria. Nowadays, advanced portable cameras are widely used for the development of assistive technologies based on image processing to achieve systems with high computational performance. The main objective of this study is to present and evaluate the performance of the image processing algorithm using a CMOS camera and a laser transmitter to measure the obstacle distance. If the desired performance is achieved, this technique could be used for robot and machine vision applications and also, for a variety of applications that require a virtual smart vision. For this reason, in this work we have tried to approach progress comparison with other studies on the robots vision. In most of these studies, ultrasound sensors are used to measure distance. The rest of the paper is organized as follows. Section 2 describes our experimental setup for image acquisition and also related problems and their solutions. Section 3 gives simulation and experimental results. Section 4 draws conclusions. METHODOLOGY There are various methods to measure the distance of objects using camera. In this work, a laser transmitter alongside a camera have been used. Laser transmitter and camera have been located in a same horizontal direction. Laser light is emitted to the desired object. Due to the distance of the desired object from camera, the horizontal location of the laser light in the image is different. Thus, the distance to the subject can be easily calculated by laser light processing and extraction of its horizontal location in the image and using a simple mathematical model based on the displacement of the laser light. Algorithm Design Process The design process is illustrated in Figure 1. It describes the details of the upcoming progress steps. Moreover, the design process includes some sub process which will be described later. Start Characteristics to measure the Hardware Assembly Assessing the validity of image Solutions to problem of laser light in the picture Assessing the validity of image Mathematical model of laser Validity Test Figure 1. Design Process Laser Beam Detection in an Image In order to validate image processing strategy for detection of laser light onto an image, first, a device consisting of a webcam and a laser was used. With the help of the ideas presented in . , the initial processing was done in MATLAB. In Figure 2, the laser beam is projected almost to the bottom of the As seen in this area, there is another red. It is possible that in this region, the laser dot appears as a white dot that indicates the camera sensor is saturated. Thus, detecting White Laser Center from other parts of the image is difficult and this is not possible unless using the RGB color value and the recognition of laser light as a reference to the image processing system. The result of an attempt to detect the laser light from pixels with the laser fringe color, is shown in Figure 3. At this stage, process is only taken on the R part of each pixel of the image. In this case, some spots are reported incorrectly as a pixel of laser boundary after processing of image. These false points leads the IJECE Vol. No. February 2017 : 209 Ae 215 IJECE ISSN: 2088-8708 system to incorrectly reports the distance to the subject, which of course can cause a great loss to a system which uses this report as its vision. Figure 2. Laser light where there is a Possibility of error Figure 3. Result of Image Processing based on a color Pixel Solution of Light Saturation in the Image To solve this problem, we should also consider the possibility of synthesis and implementation of desired plan on FPGA. So, two simple solutions were implemented simultaneously to solve these problems. RGB filtering according to specifications of laser light which is somewhat obtained by experimental and repeated tests in MATLAB to separate the light with profile similar to that specifications. Define an object with dimensions of laser light in the system and then filter the output of RGB filter according to the dimensions of the object in order to exact separation of laser light in the picture. By applying the provided solution to Figure 2, it is expected that the laser light in the image be correctly detected. As seen in Figure 4, the laser is properly detected and shown as a white object. The rest of pixels are converted to black, which reduces their impact on the next computation. seen in the Figures 2 and 3, with the fact that the center for laser and camera lens are in a direction, the location of the laser light in the vertical direction of image has been estimated. Then, this section has been cut off from main picture, so, less pixels of image will be sent to software for processing. Moreover, random objects that are the same color as laser may be separated from the image. Also, for more accuracy of laser light in the picture and to unit it as a standalone object, a series of filters have been used even to fill the cavity inside the object. The result is shown on Figure 4. Figure 4. Result of Applying RGB and other Filters An Accurate Scheme for Distance Measurement Using an Ordinary Webcam (Hossein Zivaria. A ISSN: 2088-8708 The laser Detection Algorithm A simple laser detection algorithm should be optimized to be implemented using the performance of an embedded system which is limited compared to a personal computer. What a laser light detection algorithm does in action is to scan image on the area where the laser light might be in order to find is laser If the pixel color is in the range of the laser, it is converted to white, otherwise to black. Then, the white pixels density is compared with each other and between them . f an. some range is reported as the laser light which has the same density and size of laser beam . few pixels that are located next to each other in a circle Laser Displacement Model. Based on the Barrier Distance Up here, the laser light detection algorithm and its separation from image was provided. Now, a solution should be presented to detect the distance to the object in front of the equipment. It is possible when a mathematical model is presented to show the relation of the laser position on screen and real distance of desired object to the equipment. This model is presented in Figure 5. To determine the distance, 5 following parameters are introduced which are the main parameters of this connection. dA: The minimum distance to an obstacle that can be detected by the camera. It can be calculated by the following equation. ( ) ( ) dB: The maximum distance to an obstacle that can be detected by the camera. It can be calculated by the following equation. ( ) ( ) D: Determine the distance between the obstacle and the camera. This value can be calculated from the following equation. ( ) ( )) ( ( )) Figure 5. The mathematical model for calculating the distance between the object and the camera P: An auxiliary variable to show the ratio of the laser light in the image to the horizontal length of whole image. It can be calculated from the following equation. IJECE Vol. No. February 2017 : 209 Ae 215 IJECE ISSN: 2088-8708 L: A variable that indicates the actual length of the image at a distance d. It can be calculated from the following equation. ( ) In these equations, l, represents the actual distance between the laser and the left boundary of the image at a distance d, in fact, the same number that pops out of the image processing. Also, in this model, the following equation should also be considered: Finally, the value of X represents the distance between the center of the laser and the camera. The results based on the mentioned parameters are presented in Figure 6. The results are presented in Figure 6 along with the corresponding parameters. Using these parameters, the values of the dA and dB were obtained The value of x is achieved by measuring the distance between the camera and the laser. c is also obtained by experimental simulation in MATLAB and is presented to limit the maximum calculated In Figure 6, the x-axis is the number of pixels that the laser beam is located in and the y axis indicates the distance to the desired object for each pixel of the image. Figure 6. Comparison between the Actual distance and the Calculated distance in MATLAB. The Parameters used are: RESULTS AND ANALYSIS The Performance of the MATLAB Simulator The time consumption for processing a frame in MATLAB is about 80ms as shown in Figure 7. Though this time seems to be sufficient to implement a real-time design, but for better real-time performance, it is suggested to implement the proposed algorithm on some processors such as ARM. DSP or FPGA . However, for assessing the validity of image processing algorithms. MATLAB is an optimal Finally, the performance of the proposed algorithm is compared with other methods in different The result of this comparison is presented in Table 1. As can be seen, the proposed algorithm has better distance measuring performance and accuracy versus other methods from different literatures. It should be considered that some of these methods have also acceptable distance measuring performance such as . An Accurate Scheme for Distance Measurement Using an Ordinary Webcam (Hossein Zivaria. A ISSN: 2088-8708 Figure 7. The processing time of an image frame in MATLAB Table 1. Comparison of Distance Measuring Performance of Various Methods from Different Literatures . Accuracy rate of distance measurement Up to Proposed methods References Method or device used Ultrasound device Rotating mirror eye-distance IR & Ultrasonic sensor Modified Camera Ultrasound sensor cross correlation ultrasound Laser transmitter & CMOS The Performance of Camera and Laser This device has good performance for indoor environments, factories, workshops, etc. which are benefitting from favorable light. However, it should be said that the glass and mirror surfaces are known as the system limits. In these cases, depending on how the laser light reflection occurs, the system may inform the wrong distance or laser detection, which, as stated above, causes damage to the system used. In the case of the environment with the light more than usual, it is difficult for the camera to detect the laser light and it may reduce the maximum distance of obstacle detection which also means reducing the performance of the CONCLUSION In this paper, an accurate and fast scheme for distance measurement based on laser optic was The proposed algorithm was presented to measure the distance from the object back to the camera. The design can be implemented relatively simple, fast and inexpensive on various chips such as ARM or FPGA. The run-time of one frame of the image was approximately 82 milliseconds. As shown, the accuracy rate of distance measurement was up to 99. Finally, comparing the proposed algorithm with some other methods from different literatures proved the improved detection accuracy of the new scheme. This technique can be used as robot vision to detect front objects and their distances for better react. REFERENCES