thesis report

101
POLITECNICO DI TORINO Department of CONTROL AND COMPUTER ENGINEERING (DAUIN) Master of Science in Mechatronics Engineering Master Degree Thesis Laser Sensor RS485 Interface Design and Tire DOT Code Scanner Software Development Supervisor Prof. Paolo PRINETTO Candidate Iman AMIRTAHERI Internship Tutors Dr. Giulio GAMBARDELLA Dr. Francesca BALESTRA July 2016

Upload: iman-amirtaheri

Post on 13-Apr-2017

51 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Thesis Report

POLITECNICO DI TORINO

Department of CONTROL AND COMPUTERENGINEERING (DAUIN)

Master of Science in Mechatronics Engineering

Master Degree Thesis

Laser Sensor RS485 Interface Design andTire DOT Code Scanner Software

Development

SupervisorProf. Paolo PRINETTO

CandidateIman AMIRTAHERI

Internship TutorsDr. Giulio GAMBARDELLADr. Francesca BALESTRA

July 2016

Page 2: Thesis Report

Abstract

Tire industries have an annual total sale of approximately $32.1 billion. This numberitself shows how big is this market. Costumers usually buy car tires directly from autorepair centers. So a tool that helps auto repairmen to sell their tires more effectively isextremely valuable. Tire Profiles Italy company has designed two different solutions forthis purpose. Both of these devices detect the necessity of tire replacement by meansof scanning tire thread depth. Another important item that should be paid attentionto, is the expiry date of tire. This date is usually calculated based on production date.According to the department of transportation regulations, tire producers are obliged toemboss or engrave the production week and year in a structured code on the tire sidewall.This code is also called as DOT code. So Tire Profiles Italy company introduced a newproject to design a device for DOT code scanning. There were several options about howthis device should scan the code technically. Among possible choices, the solution with 3Dlaser sensor was selected. In this approach the laser sensor measures distances between allpoints of a line and laser sensor itself. By moving sensor in a trajectory perpendicular toits laser beam axis, it can scan the whole portion of tire. This thesis is mainly focused ondesign and build a communication interface for this laser sensor in order to provide theinfrastructure for PC and laser sensor to communicate. At the next step, thanks to thiscommunication channel, a software for DOT code scanning is developed which performsacquisitions and stores the corresponding data in a host PC. As a complementary study,image pre-processing techniques are implemented in MATLAB and Qt plus Open-CVframework.

ii

Page 3: Thesis Report

Contents

Abstract ii

List of Tables v

List of Figures vi

1 Introduction 11.1 General Tire Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.1.1 Tire Specification Code . . . . . . . . . . . . . . . . . . . . . . . . . 11.1.2 Department of Transportation (DOT) Safety Code . . . . . . . . . . 21.1.3 Uniform Tire Quality Grading (UTQG) Code . . . . . . . . . . . . . 2

1.2 Tire Replacement Symptoms . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2.1 Tire Treads Depth . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.2.2 Tire Expiry Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2 DOT Code Scanning 72.1 Camera Scanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.2 Laser Scanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

3 Laser Sensor 113.1 Functional Criterion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3.3.1 Distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.3.2 Height . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.3.3 Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

3.4 Communication Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.5 Time Flows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.6 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4 Communication Interface 214.1 Micro-Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4.1.1 General Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.1.2 Pin Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.1.3 Universal Synchronous Asynchronous Receiver Transmitter (USART) 23

iii

Page 4: Thesis Report

4.2 RS485 Transceiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.3 USB to Serial Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.4 Hardware Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.5 Software Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.6 PC-Sensor Communication Test . . . . . . . . . . . . . . . . . . . . . . . . . 30

5 Acquisition Software 335.1 LaserSensor Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345.2 MainWindow Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

6 Image Pre-Processing 436.1 MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436.2 Qt and Open-CV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

7 Conclusion 63

Bibliography 65

Appendices 66

A Micro-controller C Code 67

B Laser Sensor Header Code 72

C Laser Sensor C++ Code 75

D Profile Processer MATLAB Code 83

E Profile Processor Header Code 88

F Profile Processor C++ Code 90

iv

Page 5: Thesis Report

List of Tables

1.1 Tire DOT code information content . . . . . . . . . . . . . . . . . . . . . . 22.1 Laser Scanning Technical Analysis . . . . . . . . . . . . . . . . . . . . . . . 93.1 Laser Sensor Functional Criterion . . . . . . . . . . . . . . . . . . . . . . . . 113.2 Laser Sensor Profile Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.3 Laser Sensor Timing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.4 Acquisition Timing Calculations . . . . . . . . . . . . . . . . . . . . . . . . 183.5 Relevant Laser Sensor Commands . . . . . . . . . . . . . . . . . . . . . . . 204.1 USART Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234.2 USB to Serial Module Connections . . . . . . . . . . . . . . . . . . . . . . . 264.3 Micro-controller ATMega16 Connections . . . . . . . . . . . . . . . . . . . . 264.4 Max485 Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.5 Laser Sensor Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.6 UBRRL Values for available baud rates . . . . . . . . . . . . . . . . . . . . 28

v

Page 6: Thesis Report

List of Figures

1.1 Tire Specification Code Sample: This code contains tire technical information. 11.2 DOT Code Sample: All safety information is gathered inside this universal

code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 UTQG Code Sample: This code contains tire grades in three different subjects. 31.4 Tire Tread Depth: Tire producers recommend to replace tires with less than

10% life time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.5 Groove Glove Scanner: Handheld device to measure tire tread depth and

identify car’s license plate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.6 TreadSpec (PRT Scanner): Tread depth scanner which has to be installed

on the ground. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.1 Fixed Illumination: Naive approach to illuminate tire surface and capture

DOT code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.2 Variable Illumination: Camera captures every time that illumination changes. 82.3 Laser Sensor: Creates a distance profile line by line. . . . . . . . . . . . . . 93.1 Sensor Installation Methods: a) Standard Installation b) Angled Installation 123.2 Sensor Distance Measurements: Average, Maximum and Minimum . . . . . 133.3 Sensor Height Measurements: Average, Maximum, Minimum and Delta . . 133.4 Laser Sensor Coordinates: It creates a matrix of x and z elements for every

acquisition. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.5 RS485 Connection Diagram: This protocol can connect 15 sensors to a

master. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.6 RS485 Pin Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.7 Laser Sensor Timing (Time Flows) . . . . . . . . . . . . . . . . . . . . . . . 174.1 General Connection Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.2 ATMega16 Pin Configurations . . . . . . . . . . . . . . . . . . . . . . . . . 234.3 MAX485 Pin Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.4 USB to Serial Converter Module . . . . . . . . . . . . . . . . . . . . . . . . 254.5 Communication Interface Connection Scheme . . . . . . . . . . . . . . . . . 254.6 TeraTerm Terminal Emulator Serial Settings . . . . . . . . . . . . . . . . . 304.7 PC-Sensor Communication Test . . . . . . . . . . . . . . . . . . . . . . . . . 304.8 RS485 Communication Interface . . . . . . . . . . . . . . . . . . . . . . . . 315.1 DOT Code Recognition Software (DCR) v1 . . . . . . . . . . . . . . . . . . 335.2 Signal Slots Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356.1 MATLAB Loading Raw Data File . . . . . . . . . . . . . . . . . . . . . . . 45

vi

Page 7: Thesis Report

6.2 MATLAB 3D Surface Representation . . . . . . . . . . . . . . . . . . . . . . 466.3 Leveled Surface Representation . . . . . . . . . . . . . . . . . . . . . . . . . 476.4 MATLAB 3D Model Abrupt Changes . . . . . . . . . . . . . . . . . . . . . 486.5 MATLAB 3D Model Added Neighbors . . . . . . . . . . . . . . . . . . . . . 496.6 MATLAB 3D Model Removed Min Value . . . . . . . . . . . . . . . . . . . 506.7 Segmented Black & White Image . . . . . . . . . . . . . . . . . . . . . . . . 526.8 Segmented Grayscale Image . . . . . . . . . . . . . . . . . . . . . . . . . . . 526.9 Contrast Stretched Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536.10 Negative Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536.11 Open-CV Loaded File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586.12 Open-CV Orientation Corrected . . . . . . . . . . . . . . . . . . . . . . . . 596.13 Open-CV Colors Inverted . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596.14 Open-CV Edges Sharpened . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

vii

Page 8: Thesis Report
Page 9: Thesis Report

Chapter 1

Introduction

This thesis report documents general information about vehicle tire codes, specifically tireDOT code and its importance. Then different approaches for DOT code scanning areanalyzed and one of them is chosen. In the rest of this report, the selected approach isdocumented, a communication interface is designed and built, a C++ software is developedfor data acquisition and at the end, some image pre-processing methods are performed.

1.1 General Tire CodesIn general, there are three unique codes embossed or engraved on the tire sidewalls.

1.1.1 Tire Specification Code

This code contains information about tire type,tire width, aspect ratio between its heightand width,construction type, wheel diameter, load index and speed rating. Figure 1.1shows an example of this code on tire sidewall. Note that this code in a real tire is coloredblack but in this image for better legibility it is highlighted with white color. [1]

Figure 1.1. Tire Specification Code Sample: This code contains tire technical information.

1

Page 10: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

1.1.2 Department of Transportation (DOT) Safety Code

Federal laws have obliged tire producer companies to determine the safety related infor-mation of their tires on its sidewall. This code is named department of transportationsafety code and from now on it is referred to as DOT code. Figure 1.2 shows a sample ofthis code.[1]

Figure 1.2. DOT Code Sample: All safety information is gathered inside this universal code.

DOT codes may consist of 8 upto 13 characters. Depending on the coding that manufac-turer uses, the embedded information varies but in any case some important data has tobe documented. Some of these information fields are gathered in table 1.1.

Table 1.1. Tire DOT code information content

CharactersIndex

ExampleCharacters

Definition

1-3 DOT DOT code identifier4-5 B9 Tire’s Manufacturer and plant code6-7 YR Tire size8-11 UJNX Optional characters usually to determine brand and

other characteristics12-13 50 Week of the year the tire was produced14-15 08 Year the tire was produced (starts from year 2000)

1.1.3 Uniform Tire Quality Grading (UTQG) Code

This code was proposed by the national highway traffic safety administration to gradetires based on their threadwear, traction and temperature. Figure 1.3 depicts a sample of

2

Page 11: Thesis Report

1 – Introduction

this code.[1]

Figure 1.3. UTQG Code Sample: This code contains tire grades in three different subjects.

These grading subjects focus on quality figure of merits as described below.

• ThreadwearThis grade determines how much this tire will last with comparison to the othertires of this producer. Baseline grade is 100, and theoretically a tire with grade of200 should last twice as long as tire with baseline grade.

• TractionTraction grade is based on the tire ability to stop on a wet road. There is a standardroad which is used to perform this test on tires. Acceptable grades from high to loware AA,A,B and C. Tires with traction grade of less than C are not qualified to beused for road travels.

• TemperatureOne of the most important items in tires world is the ability of tire to dissipate heat.There is a standard controlled indoor test which benchmarks tires heat dissipationand grade them starting from A for the best ones. Tires with the grade of D andbelow are considered unacceptable.

1.2 Tire Replacement SymptomsCar tires are not designed to last forever and the they have to be changed on a regularbasis. There are two important items on tire checklist which recommend the car owner toreplace tires when at least one of them is checked.

1.2.1 Tire Treads Depth

Tire treads are designed to maintain sufficient interaction between tire and road surface.After a period of time, tires begin to wear out and lose their treads depth. Most of tire

3

Page 12: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

producers recommend costumers to change tires as soon as the tire treads depth fall lessthan 2/32-inch (1.6mm). Figure 1.4 shows corresponding life time for each level of tread’sdepth. [2]

Figure 1.4. Tire Tread Depth: Tire producers recommend to replace tireswith less than 10% life time.

From longtime ago tread depth measurement was performed by means of length measure-ment devices such as calipers. Even many of auto repairmen use a small coin to measuredepth. Although this kind of approach is not wrong and use the same principle but it isnot accurate enough because it is necessary to measure and check precisely not only for asingle spot of tire but also for all of it’s surface. So the accurate procedure is very timeconsuming for an auto repairman to follow.Tire Profiles Italy Srl. company has designed two different solutions to measure tread’sdepth.

• Groove Glove ScannerThis handheld device is designed to measure tire depth and also identify car licenseplate by means of laser triangulation and camera OCR respectively. Tire surfaceis scanned by moving the device over it. Scanned data gets transferred to a cloudserver and required processes are performed inside there. Figure 1.5 shows a GrooveGlove Scanner device.[4]

• TreadSpecTreadSpec also known as PRT Scanner is a device which requires a solid structure tomount on the ground surface. This solution is usually used on the entry point of autoservice centers and allows the driver to drive over it. In many cases people pay servicecenters a visit just to change oil or diagnose an error, with this scanner installed inthe entrance, service centers generate a full report about tire tread depth and itsalignment. Hence, this device can boost their sale effectively. Figure 1.6 shows two

4

Page 13: Thesis Report

1 – Introduction

Figure 1.5. Groove Glove Scanner: Handheld device to measure tire tread depthand identify car’s license plate.

pictures of this device combined. [3]

Figure 1.6. TreadSpec (PRT Scanner): Tread depth scanner which has to beinstalled on the ground.

1.2.2 Tire Expiry Date

Despite from level of tire thread depth, it is crucial to replace the tire on a regular basis.Most of tire producers guarantee their product for five years from the week that it wasproduced.[5] So another interesting area for auto service centers is to have a device likeGroove Glove Scanner which determines the tire age. As mentioned in 1.1 on page 2, theDOT code printed on the tire sidewall has the valuable information which indicates theproduction week and year.

5

Page 14: Thesis Report

6

Page 15: Thesis Report

Chapter 2

DOT Code Scanning

So far, the reasoning behind necessity to design and make a device to scan DOT codehas been documented. From now on, two different approaches are analyzed and then infollowing chapters, preferred approach is designed from hardware and software point ofviews.In order to have a complete vision of whole design process, primarily design requirementsare gathered in this way.

• Have reasonable dimensions for a handheld device.

• Have touch screen for user interaction.

• Connect to cloud for storing raw scanned data and fetch processed data after com-pletely processed.

• Be capable of scanning DOT code completely, independent from the characterscount. Note that DOT code may consists of 8 upto 13 characters including theDOT identifier initials.

According to this general design requirements many approaches came into mind. Themost important matter that affects the whole design process is that with which technologythis device has to perform scanning process. Two different solutions were proposed.

2.1 Camera Scanning

This idea makes use of a camera to take a photo from the portion of sidewall which DOTcode is located. The device should be designed such a way that it touches the tire surface,so ambient light could not affect the photo quality. Then captured photos will be sent tocloud server and get processed there. Figure 2.1 depicts working principle of fixed illumi-nation method. A prototype of this approach has been already built in the company butit has a critical problem.

7

Page 16: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

Figure 2.1. Fixed Illumination: Naive approach to illuminate tire surface andcapture DOT code.

This prototype masks the ambient light thanks to its method of usage which is touchingtire surface. Instead, it has many infrared diodes to illuminate the DOT code when itcaptures the photo. Since these illumination lamps are turned on and off simultaneouslyand the camera axis is perpendicular to tire surface, it is not possible to distinguishcharacters since tire codes are embossed or raised on the body of tire and it is a black onblack pattern.

In order to overcome this problem variable illumination technique (structured lighting)has proposed[14]. Since the DOT code is only detectable due to its altitude difference,variable illumination technique can eliminate background and just maintain the raisedcode. This technique turns on then lights one by one and captures a photo each time,because of altitude difference in tire surface each time the resulting shadow will be different.Then a sophisticated algorithm gathers all of these photos and combine them togetherbased on the shadows. At the end, the obtained final photo shows only DOT code andeliminates its background. Figure 2.2 shows a simplified version of this approach. Usuallythere are at least 8 lights to illuminate tire surface and they are placed on a circular base.This method is also called as structured lighting.

Figure 2.2. Variable Illumination: Camera captures every time that illumination changes.

8

Page 17: Thesis Report

2 – DOT Code Scanning

2.2 Laser ScanningAnother possible approach is to use laser sensor to measure the distance between a numberof points belonging to a line. By movement of laser sensor, it is possible to gather thesedistances line by line and then generate a 3D model of the scanned tire surface. In this waythere is no need to take care about illumination because the laser sensor measures directlythe distance so there is no need to distinguish DOT code height from scanned image.Figure 2.3 depicts the new configuration in the same framework of previous approaches.

Figure 2.3. Laser Sensor: Creates a distance profile line by line.

In order to make a comparison between new approach and the previous one, table 2.1 iscreated with pros and cons of this new approach. By considering this comparison table,

Table 2.1. Laser Scanning Technical AnalysisPros Cons

Independent from illumination Scans whole DOT code graduallyWorks better in dusty environment Need to move over tire with constant speedMore accurate scanning Sensitive to sensor tilt or rotationLess data for transmitting to cloud Slower scanning

the best approach is to use camera scanning with variable illumination but because theengineering part of Tire Profiles Italy company has already defined the project with lasersensor, this thesis focused on laser scanning. Following chapters are dedicated to introducethe laser sensor and its features, design an interface for communication with it, design anuser interface to connect to the sensor and perform acquisition, design a protocol to savemeasurement data, and try to perform some simple image processing techniques to improvethe scanned data.

9

Page 18: Thesis Report

10

Page 19: Thesis Report

Chapter 3

Laser Sensor

So far, the desired design approach is selected. In this chapter, the laser sensor is in-troduced, its features are documented and an appropriate communication interface is de-signed. Sensor selection is another decision which was imposed by the Tire Profiles Italycompany. For administrative and economical reasons, this sensor was already selected andpurchased for this project.

3.1 Functional Criterion

The selected sensor is produced by Baumer company and its from MESAX multi -distance-measuring sensors family. It measures distances and heights of objects and was speciallydeveloped for easy handling. Also it makes use of a red beam to help sensor alignment.Table 3.1 denotes functioning criteria for the sensor OM70B-15LB-11125351.[6]

Table 3.1. Laser Sensor Functional CriterionFunction Valid Criteria

Start of measuring range 100mmEnd of measuring range 150mmMeasuring field width left 36mmMeasuring field width right 36mm

3.2 Installation

According to sensor’s datasheet provided by Baumer company [6], it can be installed intwo different methods.

• Standard InstallationIn this configuration sensor is mounted at a right angle with respect to the surface.

11

Page 20: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

This method of installation is recommended since there is no need to estimate per-spective effect. Figure 3.1 (a) shows a typical standard installation. This is veryimportant that the object is located in the functional range (10cm ∼ 15cm).

• Angled InstallationWhen space condition does not allow to install sensor in standard configuration itis possible to tilt sensor upto 30° from the perpendicular reference line. In this casealso, object has to lie within the functional criteria. Note that in this configurationdistance function of sensor does not work and only height function is accessible.

Figure 3.1. Sensor Installation Methods: a) Standard Installation b) Angled Installation

For the purpose of DOT code scanning it is the best to use standard installation sincealways there is enough space for auto repairman to hold the scanner device perpendicularto the tire sidewall surface. Final design should consider a method to satisfy functionrange of 10 upto 15 cm of device for all scanning process. There are two different solutionto ensure this device always lie in the correct range.

• Warn auto repairman when the device is approaching to its functional range limits.For example two LEDs or a single buzzer may be considered as the method ofnotification.

• Device housing can be designed such a way that when it touches tire sidewall there isa distance of 12.5cm between laser sensor and DOT code. In this way auto repairmanshould ensure that there is a contact between device and tire during the scan process.

Since this decision is not a matter of current thesis, it is left for other engineers to decide.

3.3 FunctionsThis sensor supports three different functions.

12

Page 21: Thesis Report

3 – Laser Sensor

3.3.1 Distance

To perform distance measurement it is required to send corresponding command andchoose the desired option. Sensor basically measures the distance between itself and allpoints lying in the scanned line. Then it finds the minimum, maximum and also theaverage of these measured distances. According to the sent command it responds with oneof these three values. Figure 3.2 depicts these three different measurements on a samplesurface.

Figure 3.2. Sensor Distance Measurements: Average, Maximum and Minimum

3.3.2 Height

Similar to the Distance function, Height function can be selected by sending appropriatecommand and attaching desired measurement type. Same as the previous case, sensor firstmeasures all points to sensor distances and then perform selected operation. Specifically forHeight function all measurements are taken with respect to a hypothetically defined planecalled reference. This plane must be taught to sensor through a certain procedure. Heightcommand can return minimum, maximum or average distance between line points andreference plane. There is also another option called delta height which returns maximumdifference between points altitude. Figure 3.3 depicts the purpose of each described option.

Figure 3.3. Sensor Height Measurements: Average, Maximum, Minimum and Delta

13

Page 22: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

3.3.3 Profile

As described in the two previous functions, this laser sensor always measures the distancebetween itself and all points in the scanned line. These measurements are stored in amatrix format. Figure 3.4 depicts these coordinates on a sample object and table 3.2denotes a blank profile matrix.

Figure 3.4. Laser Sensor Coordinates: It creates a matrix of x and z elementsfor every acquisition.

Table 3.2. Laser Sensor Profile Matrixx(1/100mm) z(1/100mm)

This function is only accessible when device is in diagnose mode. Since for a 4cm fieldof view, it is necessary to transmit about 400 (x,z) pairs, this mode is dramatically slowerthan previous modes.

Although this mode of function is slower than the others, but this is the only way tocapture all measurements and build the tire altitude profile. So this mode of operationis selected and since it only works in diagnose mode, almost all other functions are notaccessible at the same time.

3.4 Communication Protocol

This sensor uses RS485 protocol for communication. RS485 protocol is designed to trans-mit data in differential mode. In 1962, single-ended data transmission was introduced.A few years later differential data transmission introduced to overcome single-ended datatransmission losses in noisy environments. RS485 can work in half duplex or full duplexmodes. Half duplex is referred to a connection with possibility of sending and receiving but

14

Page 23: Thesis Report

3 – Laser Sensor

not at the same time. Full duplex mode defines a similar connection but with capabilityto send and receive simultaneously. This protocol requires two wires for half duplex modeand four wires for full duplex transmission. According to Baumer sensors datasheet, fig-ure 3.5 shows required configuration in order to connect upto fifteen sensors to a master.[7]

Figure 3.5. RS485 Connection Diagram: This protocol can connect 15 sensors to a master.

The most important features of this topology are listed in this way.

• Master is the only member of this configuration which can initiate a request. Sensorsare slaves, so they do no transmit anything unless master asks for it.

• This configuration can support a baud rate of 115kbit/s at max.

• Maximum possible length of cable is 10m.

• RS485 cables must be shielded.

• There are two failsafe resistors called RB to define the resistance level when notransmitter is active.

Since there is only one sensor to work with, first topology is selected for communication.This sensor came with a default shielded cable. Figure 3.6 denotes corresponding pindiagram for this cable.The suggested voltage supply for this sensor is 24v. Also it is recommended to connect

15

Page 24: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

Figure 3.6. RS485 Pin Diagram

all other not connected pins to ground to help noise cancellation.

16

Page 25: Thesis Report

3 – Laser Sensor

3.5 Time Flows

RS485 commands must be sent through a certain structure so the sensor can interpretand response appropriately. Before listing the possible commands, it is better to dedicatea few sentences about communication speed. It is preferred to describe this matter incurrent section rather than previous one because it is actually possible to modify thecommunication speed via commands.This laser sensor can work with three different baud rates.[7]

1. 38400 bits/s

2. 57600 bits/s

3. 115200 bits/s

The default configuration for baud rate is 57600 bits/sec. It means that every time thatsensor is powered on, it automatically interprets incoming requests with baud rate of57600. Also it is possible to change this value with corresponding command and save itto configuration flash.Since the application goal is to make acquisition with the highest possible rate, the sensortiming to response the request is very crucial. Figure 3.7 denotes various timing variablesand table 3.3 determines their values.

Figure 3.7. Laser Sensor Timing (Time Flows)

Since the application must use the sensor in diagnose mode, the maximum time re-quired by sensor to process the request and prepare appropriate response can be derivedas follows.

(tsmax)noerror = tanswerdiagmode = 200ms(tsmax)error = tbreak = 500ms

To make a rough calculation about order of acquisition rate, lets assume that field ofview attribute is set to 4cm. In other words, laser sensor is scanning only line with widthof 4cm per each acquisition iteration. According to table 3.2 on page 14, laser sensorreturns a pair of x and z elements for each 0.5mm of field of view.Total number of pairs = 4cm

0.5mm = 80

17

Page 26: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

Table 3.3. Laser Sensor Timing Valuest_answer Time from reception of the last character of request to

sending the first character of the answer.X 2.5ms

t_answer_diagmode

Time from reception of last character of request to sendingthe first character of the answer if the sensor is indiagnosing mode.

X 200ms

t_idle Time from reception of last character of answer to sendingthe first character of the next request

0.1msX

t_break If a request or an answer is not completed during t_break,the message is rejected.

X 500ms

Number of characters per each (x,z) pair = 4 ∗ 2 = 8Total number of characters to send for each acquisition = 80 ∗ 8 = 640Total number of bits to send = 640 ∗ 8 = 5120Time required to transfer bits with the highest baud rate 5120

115200 = 44ms

By combining information from this calculation and previous one, table 3.4 denotes timingvalues for an acquisition with field of view equal to 4cm.

Table 3.4. Acquisition Timing CalculationsTiming Reference Period FrequencyFastest acquisition 44.5ms 22.47Hz

Slowest acquisition (without error) 244.5ms 4.09HzTimeout Error 500ms X

To have a rough calculation, it is assumed that laser sensor requires 100 ms (half ofmaximum value) to perform measurement and prepare appropriate data. Acquisition pe-riod = 100 + 44.4 + 0.1 = 144.5msFinal acquisition rate = 1

144.5m = 6.92Hz

With this calculation its quite clear that this acquisition rate is low, for better under-standing this matter here is an example. Lets assume it is required to make acquisitionevery time that red line moves 1mm (half precision with respect to x axis). According tothe calculated acquisition rate, it is possible to derive,

Movement speed of laser sensor = MovementDistanceMovementT ime = 1mm

144.5m = 6.92mm/sec

In other words, if sensor is moved with speed of 7mm/sec (less than 1cm/sec), the acquireddata precision in y axis will be half of x axis precision. Now it is more observable that

18

Page 27: Thesis Report

3 – Laser Sensor

this laser sensor is not suitable for the real action, but since this sensor has been alreadypurchased, the prototype designing was based on this sensor.

3.6 CommandsIn previous sections, all important features of laser sensor and its communication ruleswere analyzed. In this section, relevant commands are listed and described. Every singlecommand has to have a predefined structure in order to be decode-able for laser sensor.[7]Command structure consists of following ordered items:

• Start identifier: A simple colon character ":" is used to acknowledge beginning of acommand.

• Device address: Two digits have the responsibility to determine target device ID.All sensors have address equal to 01 at power on instant. In order to have more thanone sensor in a network, sensors ID must be configured one by one such a way thatthere will be no conflict among them.

• Payload: This part of command can have different number of characters dependingon the command format. Payload itself consists of:

– Type: It can be "W" or "R" to determine the command is to write or read acontent respectively.

– Index: This item has three characters and form a number. Every single com-mand which is supported by laser sensor has an ID called index. To perform adesired operation, command must specify the corresponding index. Note thatit is possible for a single index to support both write and read operations.

– Separator: A semicolon character ";" is used before and after of each payloadelement to clarify elements from each other.

– Payload element: If the desired command requires a payload element (data) toperform operation, desired data should be placed in payload element. Note that,it is possible to have many payload elements separated by semicolon separator.

• CHECKSUM: This code is generated by CRC-16 algorithm in order to avoid cor-rupted command execution. CHECKSUM code is generated by the master and willbe controlled by slave upon message receipt. This code can be overridden by using"****" code instead.

• Termination characters: A combination of carriage return "\r" and line feed "\n"characters is used to determine the command’s end. The same characters are usedto represent a new line in Microsoft Windows operating systems.

Most of laser sensors in the category of "MESAX multi-distance measuring" have abuilt in display and user input. This specific sensor does not have this feature becausethere is no intention to interact with the laser sensor directly. With this introduction, all

19

Page 28: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

of these sensors are locked in the sense that it is not possible to communicate with themvia RS485 protocol unless they receive a specific command to unlock themselves.Command to unlock RS485 communication port: ":01W010;0;E9C3\r\n"Note that this command should be sent by baud rate equal to 57600 bits/sec.

Table 3.5 has summarized relevant laser sensor commands.

Table 3.5. Relevant Laser Sensor Commands

CommandName

In-dex

Read-/Write

Description

Baud Rate 006 RW Selects baud rate. (0:38400 1:57600 2:115200)Diagnose

Mode050 RW Activates/deactivates diagnose mode.

(0:Deactivate 1:Activate)Profile 052 R Returns (x,z) pairs

20

Page 29: Thesis Report

Chapter 4

Communication Interface

So far, laser sensor characteristics and its features have been analyzed. In order to performthe communication with this device, first it is necessary to define what is the final devicewhich requires to communicate with laser sensor. Since data acquisition should be madeby a computer, the final device is computer. But according to the design requirementslisted on page 7, this communication should be wireless. So its a wise choice to add amicro-controller between this connection to regulate the connection and also to create theinfrastructure for further wireless module addition. Note that adding wireless module wasnot a part of this thesis and it is left for further improvements. Figure 4.1 depicts thegeneral connection diagram considered so far. More detailes will be added during thischapter.

Figure 4.1. General Connection Scheme

4.1 Micro-Controller

There were different choices for micro-controller device. From a simple Arduino boardtill more complicated boards like Raspberry pi series, all of them could satisfy devicerequirements but with a glance to the mass production requirements, it was more rationalto use a micro-controller integrated circuit instead of working with a board. One of themost famous and easy to use family of micro-controllers are AVR produced by Atmalcompany. To choose between micro-controllers residing in this family, there were a few

21

Page 30: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

points to consider:

• Output levels of micro-controller must use TTL logic, because RS485 uses TTL logicfor each wire otherwise there is a need for level shifter.

• It must have dedicated ports for UART/USART communication.

• It is recommended to have SPI port for further wireless module or gyroscope addition.

• In order to work with the highest possible baud rate, micro-controller has to be ableto work with 11.0592MHz clock. This clock assures that UART/USART communi-cation error will be less than 0.0%.

According to these requirements, ATMega16 micro-controller was the selected choiceamong AVR micro-controllers. In the rest of this chapter, technical relevant characteristicsof this device are documented.[9]

4.1.1 General Overview

This little and cheap micro-controller has many features, here are the most importantones.

• Operating Voltage: 2.7V - 5.5V

• Speed Grade: 0 - 8 MHz

• I/O and Packages

– 32 Programmable I/O Lines– 40-pin DIP, 44-lead TQFP and 44-pad QFN/MLF

• Peripheral features

– Programmable Serial USART– Master/Slave SPI Serial Interface– Byte-Oriented Two-wire Serial Interface– Four Timer/Counters– Four PWM Channels

• 32*8 General Purpose Working Registers

• Non-volatile Memory Segments

– 16Kbytes of fIn-System Self-programmable Flash program memory– 512 Bytes EEPROM– 1 Kbyte Internal SRAM

The micro-controller used for this project was packaged in DIP format because in this wayit is much easier to use it on bread board.

22

Page 31: Thesis Report

4 – Communication Interface

4.1.2 Pin Configurations

Figure 4.2 denotes pin configurations for ATMega16 micro-controller. Some of pins havedual functions and they can be selected by software. For example pin #14 is the IO #0of port D in normal condition. It can be configured to function as serial receiver also.

Figure 4.2. ATMega16 Pin Configurations

4.1.3 Universal Synchronous Asynchronous Receiver Transmitter (US-ART)

In order to manage the RS485 connection between PC and the laser sensor, micro-controller has to work with its USART block. According to the pin configurations onfigure 4.2, table 4.1 denotes all USART related pins.[9]

Table 4.1. USART PinsPin# Normal

FunctionUSARTFunction

Description

14 PD0 RXD USART receiver input.15 PD1 TXD USART transmitter output.11 GND GND Should be connected to the PC and laser sensor

grounds to share the same voltage levels.

23

Page 32: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

4.2 RS485 TransceiverUsing micro-controller as the medium does not mean that USART output can be con-nected to RS485 wires. As previously mentioned RS485 can use two or four wires forcommunication in half duplex or full duplex mode respectively. This laser sensor supportsonly the half duplex mode, That’s why its designers have considered only two wires forcommunication in RS485 shielded cable. In order to plug USART output to RS485 con-nection a transceiver is required. One of the most common solutions for this problem isMAX485 integrated circuit.[10]Figure 4.3 shows MAX485 transceiver pin configuration. As it is possible to observe inthe figure, this IC is composed of two tri-state buffers. RE and DE has the responsibilityto control these buffers. RS485 uses two wires to transmit one bit in differential format.For example in order to represent a "0" logic A has "0" value and B has "1" value. The dif-ference between these two levels which for this case is -5V, determines that the sender hassent "0". Its exactly vice versa when sender is transmitting "1". So two control signals, REand DE select that master is going to send a command or receive a response respectively.During command sending DE is set to "1" and RE is set to "0". It is opposite when lasersensor is transmitting response. DI connects to TXD of micro-controller and RO shouldbe connected to PC. More information will be provided during this chapter.

Figure 4.3. MAX485 Pin Configuration

4.3 USB to Serial ConverterA few years ago, it was very common for personal computers and laptops to have portfor serial connection. Nowadays it is completely rare to have this kind of port for normalcomputers and there are only USB ports that can do the same thing. In order to sendand receive in a serial connection, operating system needs to open a COM port. USB toSerial converters create a virtual COM port so PC can threat with it like a normal one.At the other side there is a small circuit to convert USB data signals (D+ and D−) to Rxand Tx signals. Figure 4.4 depicts a USB to Serial converter module. It has a USB port

24

Page 33: Thesis Report

4 – Communication Interface

so a USB cable can connect it to PC. There are also five pins which three of them deliverGND, 3.3V and 5V and the two remaining form the serial connection wires (Rx and Tx).This is not a complicated module, most of USB to Serial converters make use of PL2303chip for data conversions.[11]

Figure 4.4. USB to Serial Converter Module

4.4 Hardware Connections

So far, required elements have been introduced. In this section, connections between theseelements are described. Figure 4.5 depicts all required connections between previouslydescribed elements.

Figure 4.5. Communication Interface Connection Scheme

In this scheme, PC which is the final device to send commands to laser sensor andreceive response from it, is connected to USB to Serial converter via a simple USB cable. Soin the PC, by installing appropriate driver, it is possible to open a COM port and transmitserial data. Commands sent by PC are delivered to micro-controller. Micro-controller hasthe responsibility to control RS485 connection. This control means that, if there is acommand to be delivered to laser sensor, micro-controller prepares the line by setting DEto "1" and RE to "0". In this way line is ready to accept value from micro-controller. Whilethis situation exists, the command is sent to laser sensor. Micro-controller will change theline situation immediately after sending is finished. In this way the command is sent andline is ready to receive answer from laser sensor. After computation time required by

25

Page 34: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

laser sensor, response will be sent back and since the line is tuned to deliver data fromlaser sensor to PC, the response propagates through MAX485 and directly reaches USB toserial and then PC. According to this scheme, tables 4.2,table 4.3,4.4 and 4.5 summarizedare required connections for USB to Serial module, micro-controller ATMega16, MAX485transceiver and laser sensor respectively.

Table 4.2. USB to Serial Module ConnectionsPin# Pin Name Connects to

1 5v Not Connected2 GND Circuit’s GND3 3.3v Not Connected4 NC Not Connected5 Tx ATMega16 Pin #14 RXD6 Rx Max485 Pin #1 RO

Table 4.3. Micro-controller ATMega16 ConnectionsPin# Pin Name Connects to

10 VCC Circuit’s 5V11 GND Circuit’s GND12 XTAL1 Crystal 11.0592MHz Pin #113 XTAL2 Crystal 11.0592MHz Pin #214 RXD USB to Serial Pin #5 Tx15 TXD MAX485 Pin #4 DI20 PD6 MAX485 Pin #2 RE and Pin #3 DE31 GND Circuit’s GND

Other Pins Not Connected

26

Page 35: Thesis Report

4 – Communication Interface

Table 4.4. Max485 ConnectionsPin# Pin Name Connects to

1 RO USB to Serial Pin #6 Rx2 RE ATMega16 Pin #20 PD63 DE ATMega16 Pin #20 PD64 DI ATMega16 Pin #15 TXD5 GND Circuit’s GND6 A Laser Sensor Pin #6 PINK7 B Laser Sensor Pin #1 WHITE8 VCC Circuit’s 5V

Table 4.5. Laser Sensor ConnectionsPin# Pin Name Connects to

1 WHITE MAX485 Pin #7 B2 BROWN Circuit’s 24V6 PINK MAX485 Pin #6 A7 BLUE Circuit’s GND

Other Pins Circuit’s GND

4.5 Software Design

So far, hardware design part of communication interface has been completed. Now it is thetime to go into details and create a software for micro-controller to act as a medium andregulate the connection. This kind of micro-controller is produced by Atmel company.Atmel suggests an IDE called Atmel studio to program and also simulate this micro-controller. This can be done by programming using Assembly or C language. Sinceusing assembly language is very time consuming, C language was preferred. There is alsoanother IDE called Code Vision AVR which is produced by a third party company calledHP InfoTech. Since this IDE can produce a lot of code automatically by means of selectingrequired resources in a graphical user interface, it was the selected IDE to work with.

As previously mentioned, all initialization is made automatically according to pro-grammer inputs. Here are some important portions of code to initialize various variables.Listing 4.1 denotes variable initialization for PORT A of micro-controller. In this case;all pins of PORT A are selected for input and they are working in tri-state mode. It ispossible to select inputs with pulled-up mode to avoid floating signals, but since there isno need to work with PORT A in current configuration the default configuration remainsuntouched. Other ports are initialized in the same way.

1 DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) |(0<<DDA1) | (0<<DDA0) ;

27

Page 36: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) |(0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0) ;

Listing 4.1. Port Initialization

Next item to initialize is USART interface. Listing 4.2 contains all required codes toinitialize USART with following details.

• Baud rate: 57600 bits/sec

• Databits: 8

• Startbit: 1

• Stopbit: 1

• Parity: Even

• Sender/Receiver Interrupt: No

UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (0<<U2X) | (0<<MPCM) ;

2 UCSRB=(0<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (1<<RXEN) | (1<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8) ;

UCSRC=(1<<URSEL) | (0<<UMSEL) | (1<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL) ;

4 UBRRH=0x00 ;UBRRL=0x0B ;

Listing 4.2. USART Initialization

Variables like UCSRA are micro-controller control registers and variables like TXCare pre-defined masks in order to use in such cases for appropriately modifying controlregisters. Control register UBRRL, selects the transmission baud rate based on systemclock frequency. Table 4.6 denotes corresponding values and their transmission errorpercentage for three available laser sensor commands.

Table 4.6. UBRRL Values for available baud ratesBitrate (bits/sec) UBRRL (hex) Error Percentage

38400 0x011 0.0%57600 0x00B 0.0%115200 0x005 0.0%

Now that the micro-controller is all set, it is necessary to discuss about its duty.As it has been said earlier, micro-controller should define line’s situation by constantlymonitoring the PC output. If the output has the character ":", micro-controller sets itspin #6 of port D to "1" and then puts the same character on its serial output which isconnected to laser sensor through MAX485. Also a local protocol is considered that PCshould send a special character with ascii code of 0x0B to micro-controller to acknowledge

28

Page 37: Thesis Report

4 – Communication Interface

command termination. So each command starts with ":" and ends with 0x0B character.After receiving ":" character, micro-controller outputs the received data till terminationcharacter (0x0B) receipt. At this point, micro-controller toggles line situation by settingport D pin #6 to "0". In this way, after enough processing time, laser sensor sends thecorresponding response back to the PC without micro-controller interference. Listing 4.3contains above explained code. Since micro-controller should constantly run this program,this code portion is placed in an always true loop.

1 whi le (1 ){

3 ch=getchar ( ) ;i f ( ch==’ : ’ )

5 {PORTD.6=1;

7 putchar ( ch ) ;}

9 e l s e i f ( ch==0x0B){

11 f o r ( i =0; i <100; i++) ;PORTD.6=0;

13 }e l s e

15 putchar ( ch ) ;}

Listing 4.3. Main Program

As previously mentioned, laser sensor can operate with three different baud rates andthe default one is not the fastest one. Although it is possible to change the baud rate andstore it in the configuration flash of laser sensor, for the sake of maintenance and plug andplay integrity, the micro-controller code is designed to change baud rate to the fastest oneupon system power up. With this option, PC program always send required commandswith baud rate equal to 115200 bits/sec and micro-controller has the duty to change lasersensor and also its own baud rate at first place.

PORTD.6=1;2 cr=0x0D ;

cn=0x0A ;4 delay_ms (2000) ;

p r i n t f ( " : 01W010 ; 0 ; ∗∗∗∗%c%c " , cr , cn ) ;6 delay_ms (100) ;

p r i n t f ( " : 01W006 ; 2 ; ∗∗∗∗%c%c " , cr , cn ) ;8 delay_ms (100) ;

UBRRL=0x05 ;

Listing 4.4. Baud Rate Adjust

In this code portion, first, communication line gets ready for command transfer, thenafter a delay of 2 seconds, micro-controller unlocks the RS485 lock, changes laser sensorbaud rate and then changes its own baud rate to 115200 bits/sec. Delays are considereddue to laser sensor power up latency and MAX485 propagation time.

29

Page 38: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

4.6 PC-Sensor Communication Test

At this point, communication interface setup is complete. By providing required voltagesources (5V and 24V) to the circuit, laser sensor turns on and emits a red beam, thenmicro-controller configures laser sensor to use baud rate equal to 115200 bits/sec. Nextstep is to connect USB cable to PC and circuit. Windows will automatically install theappropriate driver. Now everything is ready and it is possible to communicate with lasersensor. In order to just test the connection a terminal emulator was necessary. There aremany free solutions like TeraTerm and Putty. Figure 4.6 shows TeraTerm’s serial settingsdialogue filled with communication interface configuration data.

Figure 4.6. TeraTerm Terminal Emulator Serial Settings

By hitting OK, COM port opens and now everything is ready to send a commandto laser sensor and wait for response without having concerns about RS485 protocol oranything else. Figure shows a sample command and its corresponding response communi-cated between PC and Laser Sensor. In this communication, PC sent a request to unlockRS485 lock.

Figure 4.7. PC-Sensor Communication Test

Figure 4.8 shows the final version of RS485 communication interface functioning. On

30

Page 39: Thesis Report

4 – Communication Interface

the left side, there is the power supply which has 5V and 24V voltage sources. On theright side there are microcontroller, MAX485 and USB to serial converter.

Figure 4.8. RS485 Communication Interface

31

Page 40: Thesis Report

32

Page 41: Thesis Report

Chapter 5

Acquisition Software

In previous chapter, a communication interface was designed and built to make PC-Sensorcommunications possible. A sample command sent by means of TeraTerm terminal emula-tor and corresponding responses received. In this chapter, the goal is to design a softwareto automate this process. So the software should be able to initiate a connection to thelaser sensor, send requests, receive responses, display them in a graphical way and storethem in a file for further usage.In order to have possibility to compile the program for different operating systems andalso for accessing to simpler features, Qt IDE has been used for software development.Qt IDE is developed and supported by Nokia company. Nowadays many programmersand developers use Qt for software development. Figure 5.1 depicts the first version ofacquisition program designed. During rest of this chapter different program sections willbe analyzed.[12]

Figure 5.1. DOT Code Recognition Software (DCR) v1

Qt IDE supports signals and slots methodology for objects communication. During

33

Page 42: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

software design process, it was decided to create a class for laser sensor communication,so this class could be imported to any other applications for development. In this case,the object created of this type can use signals and slots for communication or it can beused in an ordinary way. To proceed with thesis report, two different classes are analyzedindependently. One class called "LaserSensor" is dedicated to sensor communications andanother class called "MainWindow" is for user interface.

5.1 LaserSensor Class

This class is dedicated to handle sensor communication request. With this topology, mainapplication does not need to worry about RS485 command structure, command index andso on. Class definition is made through "lasersensor.h" and "lasersensor.cpp" files. Listing5.1 summarize all declared slots for this class. Thanks to this kind of approach, a signalemitted by user click on a button can be connected to one of these slots, so whenever thatbutton is clicked, the laser sensor object will execute desired command.

1 p r i v a t e s l o t s :void FindAvai lab lePorts ( ) ;

3 void In i tConnect ion ( QString PORTName) ;void CheckConnection ( ) ;

5 void ReadAppl icat ionError ( ) ;void ReadVendorInfo ( ) ;

7 void ReadDeviceInfo ( ) ;void ReadBusAddress ( ) ;

9 void WriteBusAddress ( i n t BusAddressValue ) ;void ReadBaudRate ( ) ;

11 void WriteBaudRate ( i n t S e l e c t ) ;void ReadRS485Lock ( ) ;

13 void WriteRS485Lock ( bool Switch ) ;void ReadTouchButtonLock ( ) ;

15 void WriteTouchButtonLock ( bool Switch ) ;void ReadMeasurementType ( ) ;

17 void WriteMeasurementType ( i n t S e l e c t ) ;void ReadMeasurementValue ( ) ;

19 void ReadAllMeasurementValues ( ) ;void ReadFieldOfView ( ) ;

21 void WriteFieldOfView ( i n t LimitLeft , i n t LimitRight ) ;void WriteFiledOfViewToMax ( ) ;

23 void ReadObjectType ( ) ;void WriteObjectType ( bool Switch ) ;

25 void ReadPrec is ion ( ) ;void Wri tePrec i s i on ( i n t S e l e c t ) ;

27 void ReadLaserOffDataHold ( ) ;void WriteLaserOffDataHold ( bool Switch ) ;

29 void ReadFlexMountEnable ( ) ;void WriteFlexMountEnable ( bool Switch ) ;

31 void ReadSetFlexMount ( ) ;void WriteSetFlexMount ( f l o a t Angle , f l o a t Distance ) ;

33 void WriteTeachFlexMountCommand ( f l o a t ReferenceThickness ) ;void ReadDiagnoseMode ( ) ;

35 void WriteDiagnoseMode ( bool Switch ) ;

34

Page 43: Thesis Report

5 – Acquisition Software

void ReadPro f i l e ( ) ;37 void WriteStoreConfigurationCommand ( i n t Conf ig ) ;

void WriteResetToFactorySettingsCommand ( i n t Command) ;39 void CloseConnect ion ( ) ;

void SampleNoChanged ( QString SampleNumber ) ;

Listing 5.1. LaserSensor Class Private Slots

Despite from these available slots, a LaserSensor object can emit signals. Signals canbe used in order to send the appropriate response back to the original program. Figure5.2 depicts an example of this approach. Listing 5.2 lists all declared signals for this class.

Figure 5.2. Signal Slots Example

s i g n a l s :2 void Ava i l ab l ePor t s ( i n t TotalNumber , QVector<QString> Ports ) ;

void Connect ionStatus ( bool Status ) ;4 void App l i ca t i onError ( i n t App l i ca t ionError ) ;

void VendorID ( i n t Vendor_ID ) ;6 void VendorName( QString Vendor_Name) ;

void DeviceID ( i n t Device_ID ) ;8 void VariantID ( i n t Variant_ID ) ;

void SensorType ( QString Sensor_Type ) ;10 void SerialNumber ( QString Serial_Number ) ;

void BusAddress ( i n t BusAddressValue ) ;12 void BaudRate ( i n t BuadRateValue ) ;

void RS485Lock ( bool Switch ) ;14 void TouchButtonLock ( bool Switch ) ;

void MeasurementType ( QString Type ) ;16 void MeasurementValue ( f l o a t MeasurementValue , QString Qual i ty ) ;

void Average ( QString average ) ;18 void Max ( QString max) ;

void Min ( QString min ) ;20 void Delta ( QString d e l t a ) ;

void StandardDeviat ion ( QString s tandarddev ia t i on ) ;22 void Qual i ty ( QString q u a l i t y ) ;

void FieldOfView ( i n t LimitLeft , i n t LimitRight ) ;24 void ObjectType ( QString ObjectType ) ;

void P r e c i s i o n ( QString P r e c i s i o n ) ;26 void LaserOffDataHold ( bool Switch ) ;

void FlexMountEnable ( bool Switch ) ;28 void SetFlexMount ( f l o a t Angle , f l o a t Distance ) ;

35

Page 44: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

void DiagnoseMode ( bool Switch ) ;30 void P r o f i l e ( i n t Xpos [ 3 0 0 ] , i n t Zpos [ 3 0 0 ] ) ;

void SensorTimedOut ( bool Switch ) ;32 void Pro f i l eReady ( ) ;

Listing 5.2. LaserSensor Class Signals

So with these slots and signals, all requests are sent through slots and all responsesare emitted via signals. Now lets go into the details and analyze the most important slotsfunctions.

• Laser Sensor Constructor:This function is called whenever a new object of class LaserSensor is created. Thisinitializes serial communication and sets its baud rate to 115200 bits/sec. This serialconnection uses a Qt library called "QtSerial.h". After serial port initialization,it initialize some other variables that will be covered later. Listing 5.3 denotesLaserSensor constructor definition.LaserSensor : : LaserSensor ( )

2 {qRegisterMetaType<QVector<QString> >(" QVector<QString>" ) ;

4 s e r i a l = new QSer ia lPort ( t h i s ) ;s e r i a l −>setBaudRate ( QSer ia lPort : : Baud115200 ) ;

6 s e r i a l −>setDataBits ( QSer ia lPort : : Data8 ) ;s e r i a l −>s e t P a r i t y ( QSer ia lPort : : EvenParity ) ;

8 s e r i a l −>setStopB i t s ( QSer ia lPort : : OneStop ) ;s e r i a l −>setFlowContro l ( QSer ia lPort : : NoFlowControl ) ;

10 DeviceAddress =1;Yindex=0;

12 f i l e c r e a t e d=f a l s e ;SampleNo=" 1 " ;

14 }

Listing 5.3. LaserSensor Constructor

The third line of code has the duty to register a meta type in order to providepossibility to move an object of this class to a new thread. DeviceAddress variableis always one since there is only one sensor in RS485 network. Yindex is the indexof scanned lines and it is set to zero at first. After each successful acquisition it willbe automatically incremented. filecreated flag is used to check if the profile text fileis created or not. In read profile mode, laser sensor class should store acquisitiondata in a text file. SampleNo variable is defined to identify different tire samples. Itis just there for further result comparisons.

• FindAvailablePortsThis function scans for all COM ports, then removes those ones that are not available.A COM port is not available when another program is using it and it is flagged asbusy. Then it emits a signal containing total number of available ports and theirnames. Listing 5.4 denotes corresponding codes.void LaserSensor : : F indAvai lab lePorts ( )

36

Page 45: Thesis Report

5 – Acquisition Software

2 {i n t TotalNumber=0;

4 QVector<QString> Ports (0 ) ;f o r each ( const QSer i a lPor t In fo &in fo , QSer i a lPor t In fo : :a v a i l a b l e P o r t s ( ) )

6 {i f ( ! i n f o . isBusy ( ) )

8 {Ports . append ( i n f o . portName ( ) ) ;

10 TotalNumber++;}

12 }emit Ava i l ab l ePor t s ( TotalNumber , Ports ) ;

14 }

Listing 5.4. FindAvailablePorts: Returns all ready to connect COM ports

• SendCommandAll slots use a function to send a command to laser sensor. SendCommand receivesa string as input, then adds other necessary elements to its begin and end accordingto the RS485 command structure. Listing 5.5 contains corresponding codes.

void LaserSensor : : SendCommand ( QString Command)2 {

QChar cr=0x0D ;4 QChar cn=0x0A ;

QChar stopchar=0x0B ;6 QString ToSend=" : " ;

ToSend . append ( QString ( "%1" ) . arg ( DeviceAddress , 2 , 10 , QChar( ’ 0 ’ ) ) ) ;8 ToSend . append (Command) ;

ToSend . append ( " ; " ) ;10 ToSend . append ( " ∗∗∗∗ " ) ;

ToSend . append ( cr ) ;12 ToSend . append ( cn ) ;

ToSend . append ( stopchar ) ;14 s e r i a l −>wr i t e ( ToSend . toLat in1 ( ) ) ;

}

Listing 5.5. SendCommand: Prepares command and sends it.

In this function start, carriage return, line feed and stop char has been defined. Stopchar is the conventional character 0x0B that informs micro-controller to change theRS485 line mode. After command preparation, it will be sent byte by byte to serialport thanks to the toLatin1 method of QString class.

• ReceiveResponseThis function is intended to be called by each slot after SendCommand execution.In this way, the function will be blocked until a response is received or a time-outoccurs. Listing 5.6 gathers all necessary codes for this purpose. This function returnstrue in case of response receipt and false in case of time-out.

37

Page 46: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

1 bool LaserSensor : : ReceiveResponse ( ){

3 QChar cn=0x0A ;Response . c l e a r ( ) ;

5 bool CompletelyReceived=f a l s e ;whi l e ( ! CompletelyReceived )

7 {i f ( s e r i a l −>waitForReadyRead (500) )

9 {Response . append ( s e r i a l −>readAl l ( ) ) ;

11 qDebug ( ) << Response ;i f ( Response . conta in s ( cn ) ) CompletelyReceived=true ;

13 }e l s e

15 {return f a l s e ;

17 }}

19 qDebug ( ) << Response ;Payloads=Response . s p l i t ( " ; " ) ;

21 Payloads . removeFirst ( ) ;r e turn true ;

23 }

Listing 5.6. ReceiveResponse: Verifies response receipt.

This code makes use of serial library time-out ability. If no new byte is receivedwithin 500msec, if statement will be false and function returns false, acknowledgingthat the request has been timed-out so the main function should request it again.If a byte is received, it will be added to Response variable and cleared from serialbuffer. The while loop remains true, until the line feed character receipt. Aftersuccessful command receipt, function splits it to payloads. Usually sensor responseshave payloads to return measurement values.

• WriteDiagnoseModeAs previously mentioned about working with profile command of laser sensor, thiscommand is only available when laser sensor is in diagnose mode. So the WriteDi-agnoseMode has the duty to enter laser sensor to this mode. Listing 5.7 denotescorresponding functions.

1 void LaserSensor : : WriteDiagnoseMode ( bool Switch ){

3 SendCommand( "W030; −20;20 " ) ;ReceiveResponse ( ) ;

5 SendCommand( " R030 " ) ;ReceiveResponse ( ) ;

7 SendCommand( "W050; 1 " ) ;i f ( ReceiveResponse ( ) )

9 {emit DiagnoseMode ( t rue ) ;

11 }

38

Page 47: Thesis Report

5 – Acquisition Software

}

Listing 5.7. WriteDiagnoseMode: Activates diagnose mode.

Although this function is designed to just activate the diagnose mode, it also sets thefield of view range. In third line, laser sensor is asked to set its measuring range from-20mm to 20mm with respect to the center of red beam. Then the same attributerequested to read for verification. Finally at line 7, program sends diagnose modeactivation command and if the response is received, it emits a signal to MainWindowwhich yields to a check in a checkbox.

• ReadProfileFinally, its time to analyze the main function that collects acquisition data. Thisfunction creates two data files and store the same content into both of them. Thereason of creating two identical files is that, for image pre-processing part, it wasnecessary to address a constant file name in MATLAB. In order to prevent fromoverwriting the previously made acquisition, another file with date, time and alsosample number is created each time. According to listing 5.8, this function performsa profile acquisition once and emits a ProfileReady signal when its done. This is theduty of MainWindow to call this function in a loop to scan multiple lines.void LaserSensor : : ReadPro f i l e ( )

2 {i f ( ! f i l e c r e a t e d )

4 {QDateTime currentdateandt ime = QDateTime : : currentDateTime ( ) ;

6 Pro f i l eData . setFileName ( " Profi leData_Sample "+SampleNo+"_"+currentdateandt ime . t o S t r i n g ( " yyyy−MM−dd_hh−mm−s s " )+" . txt " ) ;

Pro f i l eData . open ( QIODevice : : WriteOnly ) ;8 Pro f i l eData1 . setFileName ( " Pro f i l eData . txt " ) ;

Pro f i l eData1 . open ( QIODevice : : WriteOnly ) ;10 Pro f i l eS t r eam . se tDev ice (& Pro f i l eData ) ;

Pro f i l eS t r eam << "Y\tX\ t \Z" <<endl <<endl ;12 Pro f i l eSt ream1 . se tDev ice (& Pro f i l eData1 ) ;

Pro f i l eSt ream1 << "Y\tX\ t \Z" <<endl <<endl ;14 f i l e c r e a t e d=true ;

}16 SendCommand( " R052 " ) ;

i f ( ReceiveResponse ( ) )18 {

QStr ingLi s t XZMeasurements ;20 XZMeasurements=Payloads [ 1 ] . s p l i t ( " " ) ;

i n t TotalMeasurements=XZMeasurements [ 0 ] . t o In t ( ) ;22 XZMeasurements . removeFirst ( ) ;

Yindex++;24 f o r ( i n t i =0; i<TotalMeasurements /2 ; i++)

{26 Pro f i l eS t r eam << Yindex <<" \ t " << XZMeasurements [ 2 ∗ i ] <<" \ t

" <<XZMeasurements [ 2 ∗ i +1] <<endl ;Pro f i l eSt ream1 << Yindex <<" \ t " << XZMeasurements [ 2 ∗ i ] <<" \

t " <<XZMeasurements [ 2 ∗ i +1] <<endl ;

39

Page 48: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

28 }

30 }emit Pro f i l eReady ( ) ;

32 }

Listing 5.8. ReadProfile: Makes profile acquisition once.

This function primarily checks for file existence, if it is not created, it creates two filesas described above. Then it prints column headers into these two files. After thata command with read profile index will be sent to laser sensor and upon successfulreceipt, it splits (x,z) pairs and prints them along corresponding y index into bothfiles. Listing 5.9 shows 10 lines of an acquisition data file with 10534 lines.

Y X Z2

1 0 38894 1 50 3897

1 100 39116 1 150 3955

1 200 39668 1 250 3953

1 300 397110 1 350 4006

Listing 5.9. Read Profile Sample

5.2 MainWindow Class

In previous section, the LaserSensor class was introduced. In this section MainWindowclass is going to be analyzed. This class also is defined by means of "MainWindow.h" and"MainWindow.cpp" files. MainWindow class is already filled by the information comingfrom user interface design and other necessary initialization. There are not too manymodifications required for this class since most of the work is done in LaserSensor class.By the way it is necessary to define a new object of class LaserSensor and a new threadto move the object into it. Listing 5.10 denotes corresponding codes.

LaserSensor ∗ Sensor = new LaserSensor ( ) ;2 QThread∗ SensorThread = new QThread ;

Sensor−>moveToThread ( SensorThread ) ;

Listing 5.10. Thread Creation for LaserSensor Object

Note that the thread should be started before program execution, but this will happenafter signal and slots connections definition. So next part should define the signal andslots connection. This process is like wiring building blocks. Listing 5.11 lists all of theseconnections.

1 // Find Ava i l ab l e Ports

40

Page 49: Thesis Report

5 – Acquisition Software

connect ( ui−>Refresh_Ports ,SIGNAL( c l i c k e d ( ) ) , Sensor ,SLOT(FindAvai lab lePorts ( ) ) ) ;

3 connect ( Sensor ,SIGNAL( Ava i l ab l ePor t s ( int , QVector<QString >)) , th i s ,SLOT(ShowAvai lablePorts ( int , QVector<QString >)) ) ;

5 // I n i t i a l i z e Connectionconnect ( th i s ,SIGNAL( In i tConnect ion ( QString ) ) , Sensor ,SLOT( In i tConnect ion( QString ) ) ) ;

7 connect ( Sensor ,SIGNAL( Connect ionStatus ( bool ) ) , ui−>Ser ia l_Status ,SLOT(setChecked ( bool ) ) ) ;

9 //Vendor In format ionconnect ( ui−>GetVendorInfo ,SIGNAL( c l i c k e d ( ) ) , Sensor ,SLOT( ReadVendorInfo ( )) ) ;

11 connect ( Sensor ,SIGNAL( VendorID ( i n t ) ) , ui−>VendorID_Label ,SLOT( setNum ( i n t) ) ) ;connect ( Sensor ,SIGNAL(VendorName( QString ) ) , ui−>VendorName_Label ,SLOT(setText ( QString ) ) ) ;

13

// Device In format ion15 connect ( ui−>GetDeviceInfo ,SIGNAL( c l i c k e d ( ) ) , Sensor ,SLOT( ReadDeviceInfo ( )

) ) ;connect ( Sensor ,SIGNAL( DeviceID ( i n t ) ) , ui−>DeviceID_Label ,SLOT( setNum ( i n t )) ) ;

17 connect ( Sensor ,SIGNAL( VariantID ( i n t ) ) , ui−>VariantID_Label ,SLOT( setNum (i n t ) ) ) ;connect ( Sensor ,SIGNAL( SensorType ( QString ) ) , ui−>SensorType_Label ,SLOT(setText ( QString ) ) ) ;

19 connect ( Sensor ,SIGNAL( SerialNumber ( QString ) ) , ui−>SerialNumber_Label ,SLOT( setText ( QString ) ) ) ;

21 //Read Al l Measurement Valuesconnect ( ui−>ReadAllMeasurementValues ,SIGNAL( c l i c k e d ( ) ) , Sensor ,SLOT(ReadAllMeasurementValues ( ) ) ) ;

23 connect ( Sensor ,SIGNAL( Average ( QString ) ) , ui−>Average_Label ,SLOT( setText (QString ) ) ) ;connect ( Sensor ,SIGNAL(Min( QString ) ) , ui−>Min_Label ,SLOT( setText ( QString ) )) ;

25 connect ( Sensor ,SIGNAL(Max( QString ) ) , ui−>Max_Label ,SLOT( setText ( QString ) )) ;connect ( Sensor ,SIGNAL( Delta ( QString ) ) , ui−>Delta_Label ,SLOT( setText (QString ) ) ) ;

27 connect ( Sensor ,SIGNAL( StandardDeviat ion ( QString ) ) , ui−>StandardDeviation_Label ,SLOT( setText ( QString ) ) ) ;connect ( Sensor ,SIGNAL( Qual i ty ( QString ) ) , ui−>Quality_Label ,SLOT( setText (QString ) ) ) ;

29

//Read P e r i o d i c a l l y31 connect ( ui−>ReadPer iod ica l ly ,SIGNAL( c l i c k e d ( ) ) , th i s ,SLOT(

ReadPer i od i ca l l y ( ) ) ) ;

33 // Enable Diagnose Modeconnect ( ui−>EnableDiagMode ,SIGNAL( c l i c k e d ( bool ) ) , Sensor ,SLOT(

WriteDiagnoseMode ( bool ) ) ) ;

41

Page 50: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

35 connect ( Sensor ,SIGNAL( DiagnoseMode ( bool ) ) , ui−>DiagModeStatus ,SLOT(setChecked ( bool ) ) ) ;

37 //Read P r o f i l e P e r i o d i c a l l yconnect ( ui−>ReadProf i l e ,SIGNAL( c l i c k e d ( ) ) , Sensor ,SLOT( ReadPro f i l e ( ) ) ) ;

39 connect ( Sensor ,SIGNAL( Prof i l eReady ( ) ) , Sensor ,SLOT( ReadPro f i l e ( ) ) ) ;connect ( ui−>spinBox ,SIGNAL( valueChanged ( QString ) ) , Sensor ,SLOT(

SampleNoChanged ( QString ) ) ) ;41

// Close Connection43 connect ( ui−>STOP,SIGNAL( c l i c k e d ( ) ) , Sensor ,SLOT( CloseConnect ion ( ) ) ) ;

45 SensorThread−>s t a r t ( ) ;

Listing 5.11. Signal-Slot Connections

These connections, connect user interface elements signals such as clicked() to a slotin sensor object. Then it connects a relevant signal of sensor to a slot of user interfaceelement. For example a click on Connect button in user interface, will cause a requestto laser sensor device to remove its RS485 lock and upon successful operation, a checkwill appear in user interface communication status checkbox. This concept is depicted onfigure 5.2 on page 35. After providing all connections, thread is started on line 45.

42

Page 51: Thesis Report

Chapter 6

Image Pre-Processing

In previous chapter, a Qt program developed to make use of communication interfaceto perform acquisition and store received data in a file. In this chapter, two differentapproaches are used to perform image pre-processing techniques. First approach is doneby MATLAB and second approach is designed with Qt C++ and help of OpenCV imageprocessing library.

6.1 MATLABIn many similar cases, when the goal is to perform image processing techniques and haveOCR program, the starting point is to use MATLAB software because it offers many easyto use functions which are already developed. In this section a .m program is analyzedstep by step to determine how does it work.

Step 1: Listing 6.1 represents a portion of code dedicated to open the data file, fill threex,y and z vectors based on imported data and draw a 3D object to represent scannedtire portion.

1 %Read measured data from data f i l ef i l ename = ’E: \ Education \ Un ive r s i ty \MS\4 th Semester \ Thes i s \ Vers ions \Qt\

v1 .6\ bui ld−DCR−Desktop_Qt_5_6_0_MSVC2015_64bit−Debug\ P r o f i l e s \Pro f i l eData . tpd ’ ;

3 d e l i m i t e r I n = ’ \ t ’ ;h e a d e r l i n e s I n = 1 ;

5 P r o f i l e = importdata ( f i l ename , d e l i m i t e r I n , h e a d e r l i n e s I n ) ;

7 %Store x , y , z combination on x , y and z v e c t o r sx=P r o f i l e . data ( : , 2 ) ;

9 y=P r o f i l e . data ( : , 1 ) ;z=P r o f i l e . data ( : , 3 ) ;

11

p lo t3 (x , y , z , ’ .− ’ )13

t r i = delaunay (x , y ) ;15 p lo t (x , y , ’ . ’ )

43

Page 52: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

17 [ r , c ] = s i z e ( t r i ) ;d i sp ( r )

19

h = t r i s u r f ( t r i , x , y , z ) ;21 a x i s v i s3d

a x i s o f f23 l = l i g h t ( ’ Po s i t i on ’ ,[ −50 −15 2 9 ] ) ;

s e t ( gca , ’ CameraPosition ’ , [ 208 −50 7687 ] ) ;25 l i g h t i n g phong

shading i n t e r p27 c o l o r b a r EastOutside

Listing 6.1. Data file loading

As previously mentioned, in order to run this program again and again for differentnewly scanned samples, file name points to "ProfileData.tpd". The ".tpd" extensionhas been chosen to the courtesy of Tire Profiles company and stands for Tire Pro-files Data. According to the previous convention about filling data file, it has onerow of column headers and values are separated by means of tabs. The code forrepresenting x,y and z vectors in 3D format, uses point by point drawing and thenchanging the color based on corresponding z value. Figure 6.1 shows output of thesecommands, As it is possible to observe the DOT code on tire is "DOT CN3R PY42".

On the right side of this figure, there is a bar showing corresponding color fordifferent distances. These distances are actually the distances between each pointand laser sensor. For example on right side of tire representation, color dedicatedto characters are less than background color in the sense that the correspondingdistance value is less than the same value for background. Which means the DOTcharacters are closer to the laser sensor rather than the background.

Step 2: For further improvements on achieved results it is a good choice to store x,yand z vectors inside a matrix called P such a way that x and y values are row andcolumn indices and z values are stored as matrix elements values. Listing 6.2 listsall required MATLAB commands to transform x,y,z vectors to P matrix.

1 %Loading Measured data to matrix PYindex=0;

3 Xindex=0;yvalue=−1;

5 f o r i =1: l ength ( x )i f ( y ( i )==yvalue )

7 Xindex=Xindex+1;e l s e

9 Yindex=Yindex+1;Xindex=1;

11 yvalue=y ( i ) ;end

13 P( Yindex , Xindex )=z ( i ) ;end

15

44

Page 53: Thesis Report

6 – Image Pre-Processing

Figure 6.1. MATLAB Loading Raw Data File

% Removing zero e lements from P r o f i l e matrix17 f o r x=1: s i z e (P, 1 )

f o r y=1: s i z e (P, 2 )19 i f (P(x , y )==0)

P(x , y )=P(x , y−1) ;21 end

end23 end

f i g u r e , s u r f (P) , t i t l e ( ’ 3D Sur face Representat ion ’ )

Listing 6.2. Store Loaded Data into P Matrix

In this portion of code, one loop sweeps all x,y,z elements and fill P matrix accord-ingly. Note that the value stored in x vector is not needed and only the sequence ofdata is important. After filling P matrix based on x,y,z vectors, it is possible to havezero elements in P because at time of acquisition sensor couldn’t scan for example400 points of a few lines. In such cases that are usually a result of functional criterionlimits trespassing, it is necessary to fill those zero elements with a neighbor non zeroelement. When P matrix is completely built up and does not have zero elementsinside, surf function can make a better 3D surface representation like in figure 6.2.

45

Page 54: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

Figure 6.2. MATLAB 3D Surface Representation

Step 3: As it is observable from 3D image, the acquisition is not perfect, in the sense thatsensor did not maintain a constant vertical distance to tire during scanning process.To reduce effect of this matter, listing 6.3 lists a few simple commands to level the3D model from one side.

f o r x=1: s i z e (P, 1 )2 P(x , : )=P(x , : ) −(P(x , 1 )−P( 1 : 1 ) ) ;

end4 P=f l i p l r (P) ;

f i g u r e , s u r f (P) , t i t l e ( ’ 3D Sur face Representat ion − Leveled ’ )

Listing 6.3. Leveled Model

In this code portion, all points of every single horizontal line are modified such away that the starting point of all lines have the same value. Figure 6.3 representsthe result of leveling process.

Step 4: Now that the 3D model is leveled, it is the time to scan for abrupt changes in themodel. The only way to recognize and the main reason behind using laser sensorinstead of camera is to find DOT code based on altitude changes instead of tryingto recognize it from a black on black pattern. Listing 6.4 summarizes all requiredcommands to find abrupt changes.

1 %% Finding maximum two conse cu t i v e po in t s d i f f e r e n c e

46

Page 55: Thesis Report

6 – Image Pre-Processing

Figure 6.3. Leveled Surface Representation

f o r y=1: s i z e (P, 2 )3 MaxDeltaVector ( y ) =0;

f o r x=2: s i z e (P, 1 )5 i f ( abs (P(x , y )−P(x−1,y ) )>MaxDeltaVector ( y ) )

MaxDeltaVector ( y )=abs (P(x , y )−P(x−1,y ) ) ;7 end

end9 end

MaxDelta=max( MaxDeltaVector ) ;11

% Finding abrupt z change between two conse c tu iv e po in t s ( r i g h t to l e f t)

13 f o r y=1: s i z e (P, 2 )P1(1 , y )=min (P ( : ) ) ;

15 P1(2 , y )=min (P ( : ) ) ;f o r x=3: s i z e (P, 1 )

17 ExpectedValue=2∗P(x−1,y )−P(x−2,y ) ;i f ( abs (P(x , y )−ExpectedValue ) <0.3∗MaxDelta )

19 P1(x , y )=min (P ( : ) ) ;e l s e

21 P1(x , y )=P(x , y ) ;end

23 endend

25

% Finding abrupt z change between two conse c tu iv e po in t s ( l e f t to r i g h t)

27 f o r y=1: s i z e (P, 2 )

47

Page 56: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

P1( end , y )=min (P ( : ) ) ;29 P1( end −1,y )=min (P ( : ) ) ;

f o r x=s i z e (P, 1 ) −2:−1:131 ExpectedValue=2∗P( x+1,y )−P( x+2,y ) ;

i f ( abs (P(x , y )−ExpectedValue ) >0.3∗MaxDelta && P1(x , y )==0)33 P1(x , y )=P(x , y ) ;

end35 end

end37 f i g u r e , s u r f (P1) , t i t l e ( ’ Abrupt a l t i t u d e changes in 3D model ’ )

Listing 6.4. Procedure to Find Abrupt Altitude Changes

This step works by finding the most variation between two consecutive points. Thisvalue gives an order of expected variation. Its expected to have the most variationsin altitude where ever there is an edge of DOT code. At the rest of code, MATLABwill try to find points that have a absolute consecutive change more than 0.3 timesof maximum abrupt changes. These points will be considered as potential edges.This control process is executed twice, one from right to left and one from left toright. All potentially important points are gathered in P1 matrix. Figre 6.4 showsabrupt changes in 3D model, all other points have been changed to have altitudeequal to zero.

Figure 6.4. MATLAB 3D Model Abrupt Changes

Step 5: As its observable from previous step result, the algorithm has found only theedges as it was intended to do. In order to have characters also included in thesegmented area, listing 6.5 contains the appropriate code to add a point to selected

48

Page 57: Thesis Report

6 – Image Pre-Processing

points if there is an already selected point in its neighborhood with size of threepoints.

1 % Adding neighbor po in t s to c o l l e c t e d dataNeighborSize =3;

3 P2=P1 ;f o r y=1+NeighborSize : s i z e (P, 2 )−NeighborSize

5 f o r x=1+NeighborSize : s i z e (P, 1 )−NeighborSizef o r i=−NeighborSize : NeighborSize

7 f o r j=−NeighborSize : NeighborSizei f (P1( x+i , y+j )==P( x+i , y+j ) )

9 P2(x , y )=P(x , y ) ;end

11 endend

13 endend

15 f i g u r e , s u r f (P2) , t i t l e ( ’Added neighbours ’ )

Listing 6.5. Adding Neighbors to Selected Points

This code uses four nested loops to check if a point has to be added to selected pointsor not. In order to prevent from selecting all points, a new P2 matrix is filled basedon P1 matrix data.

Figure 6.5. MATLAB 3D Model Added Neighbors

Step 6: For image segmentation it is better to have the 3D model with miinmum valueequal to zero. In this simple step minimum value of matrix is decremented from all

49

Page 58: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

points. Note that the minimum value is referred to the minimum value of all pointswithout considering points with zero value. Listing 6.6 lists these simple commands.

1 % Remove min value ( except 0)P2=P2−min (P2 ( : ) ) ;

3 minvalue=i n f ;f o r y=1: s i z e (P, 2 )

5 f o r x=1: s i z e (P, 1 )i f (P2(x , y )~=0 && P2(x , y )<minvalue )

7 minvalue=P2(x , y ) ;end

9 endend

11 f o r y=1: s i z e (P, 2 )f o r x=1: s i z e (P, 1 )

13 i f (P2(x , y ) ~=0)P2(x , y )=P2(x , y )−minvalue ;

15 endend

17 endf i g u r e , s u r f (P2) , t i t l e ( ’Min Value Removed ’ )

19 P=P2 ;

Listing 6.6. Removing Minimum Value (Except 0)

Figure 6.6 depicts the new 3D model which has zero minimum value. Comparisonmay be made by considering the z axis numbers.

Figure 6.6. MATLAB 3D Model Removed Min Value

50

Page 59: Thesis Report

6 – Image Pre-Processing

Step 7: Now that the 3D manipulation is made effectively by exploiting distance mea-surement feature, it is possible to convert this 3D model to a normal 2D image toperform some simple image pre-processing techniques. Listing 6.7 denotes requiredcommands to perform this important step.

1 % Image SegmentationP=P ’ ;

3 I = mat2gray (P) ;mask = f a l s e ( s i z e ( I ) ) ;

5

f o r x=1: s i z e ( I , 1 )7 f o r y=1: s i z e ( I , 2 )

i f (P(x , y ) >=0.9∗max(P ( : ) ) )9 mask(x , y )=true ;

end11 end

end13

W = g r a y d i f f w e i g h t ( I , mask , ’ GrayDi f f e renceCuto f f ’ , 25) ;15 thresh = 0 . 0 1 ;

[BW, D] = imsegfmm (W, mask , thresh ) ;17 f i g u r e

imshow (BW)19 t i t l e ( ’ Segmented BW Image ’ )

Listing 6.7. Image Black & White Segmentation

This step primarily uses a "mat2gray" function to just scale each matrix element valueto have a number between 0 and 255. "mask" variable is used to define a mask whichrepresents potential seeds of image segmentation. This binary matrix is filled withones for points with highest values (above 90%) and zeros for all remaining points."graydiffweight" uses the grayscale image and provided mask to calculate a weightfor pixels according to the difference between their value and masked point values.At the end, "imgsegfmm" function performs segmentation based on the weightedvalues, provided mask and a threshold which determines the border of black andwhite. Figure 6.7 shows the result of this process.

Step 8: It seems that the code has selected the correct region that contains the DOTcode but with current black and white image it is not possible to perform OCR forsure. So in this step, segmentation mask created by previous step is used to filteroriginal grayscale image obtained by beginning of previous step.

1 f o r x=1: s i z e ( I , 1 )f o r y=1: s i z e ( I , 2 )

3 i f (BW(x , y )==f a l s e )P(x , y ) =0;

5 endend

7 endI = mat2gray (P) ; f i g u r e , imshow ( I ) , t i t l e ( ’ Segmented Graysca le Image ’ )

51

Page 60: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

Figure 6.7. Segmented Black & White Image

Listing 6.8. Image Grayscale Segmentation

This code uses BW image created by previous step to filter original P matrix. Figure6.8 reveals grayscale segmented image which is quite promising.

Figure 6.8. Segmented Grayscale Image

Step 9: This image can be improved by means of contrast stretching. Listing 6.9 denotesrequired commands one after the other.%Contrast S t r e t ch ing

2 P=P−min (P(P>0) ) ;P(P<0)=0;

4 P=P. ∗255/max(P ( : ) ) ;I = mat2gray (P) ; f i g u r e , imshow ( I ) , t i t l e ( ’ Contrast Stre tched Image ’ ) ;

52

Page 61: Thesis Report

6 – Image Pre-Processing

Listing 6.9. Contrast Stretching

This code guarantees to have minimum and maximum grayscale values by removingminimum value and then stretch the gray value spectrum to 255. Figure 6.9 showsimproved constrast stretched image.

Figure 6.9. Contrast Stretched Image

Step 10: Since most of OCR techniques works best when the input image has black texton white background, 6.10 denotes the simple method to find the negative image.

1 %Negate ImageP=255−P;

3 I = mat2gray (P) ; f i g u r e , imshow ( I ) , t i t l e ( ’ Negative Image ’ ) ;

Listing 6.10. Negative Image

Finally, figure 6.10 shows the result of 10 consecutive steps for image pre-processing.

Figure 6.10. Negative Image

53

Page 62: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

Although this image pre-processing is not perfect but it offers a good approach to make the3D model clearer for image processing and specifically OCR. Anyway the thesis goal wasmainly to achieve a stable working condition for laser sensor communication and scannersoftware acquisition.

6.2 Qt and Open-CV

In previous section, a 10 step pre-image processing algorithm introduced to use with MAT-LAB program. Since the final program should be developed and deployed with Qt IDE,although this was not a part of this thesis subject, author tried to implement a few ba-sic pre-processing algorithms into the scanner Qt C++ software. In this way the field iswidely open for another engineers to expand and make use of it.Open-CV is an open source computer vision library that supports various operating sys-tems and programming languages. This flexibility is encouraging programmers to use thislibrary for their image processing applications. Qt and Open-CV can make a powerfulimage processing software since both of them can deploy programs for different operatingsystems.[13]The new Qt software developed along with Open-CV libraries has one more class named"ProfileProcessor". This class also is defined by files "profileprocessor.h" and "profilepro-cessor.cpp". Listing 6.11 denotes public and private functions declared by this class.

1 pub l i c :P r o f i l e P r o c e s s o r ( ) ;

3 void Process ( QString Pro f i l eDataLocat ion , QStringCon f i gu ra t i onF i l eLoca t i on ) ;

p r i v a t e :5 void LoadPro f i l e ( QString F i l eLoca t i on ) ;

void ShowImage ( ) ;7 void Cor rec tOr i enta t i on ( ) ;

void Inver tCo lo r ( ) ;9 void SharpenEdges ( ) ;

Listing 6.11. ProfileProcessor Functions

In this case there is no advantage to use slots over class functions because the processeddata by the profile processor object should be handled differently than just connectingit to a user interface element slot. But for signals part, listing 6.12 shows two signalsdeclared by this class.

1 s i g n a l s :void SendImage (QPixmap Image ) ;

3 void SendCurrentOperation ( QString Command) ;

Listing 6.12. ProfileProcessor Signals

SendImage and SendCurrentOperation signals, send an image and a descriptive stringrespectively. This design is intended in order to make possible to have a good interface inMainWindow object. Further information will be available later.Listing F.1 describes the definition of process function of this class.

54

Page 63: Thesis Report

6 – Image Pre-Processing

1 void P r o f i l e P r o c e s s o r : : Process ( QString Pro f i l eDataLocat ion , QStringCon f i gu ra t i onF i l eLoca t i on )

{3 QFile Conf igurat ion ;

Conf igurat ion . setFileName ( Con f i gu ra t i onF i l eLoca t i on ) ;5 Conf igurat ion . open ( QIODevice : : ReadOnly ) ;

QTextStream Conf igurat ionStream ;7 Conf igurat ionStream . se tDev ice (& Conf igurat ion ) ;

whi l e ( ! Conf igurat ionStream . atEnd ( ) )9 {

QString Action=Conf igurat ionStream . readLine ( ) ;11 i f ( Action . conta in s ( " Load F i l e " ) )

{13 LoadPro f i l e ( Pro f i l eDataLocat ion ) ;

}15 e l s e i f ( Action . conta in s ( " Correct Or i entat i on " ) )

{17 Correc tOr i enta t i on ( ) ;

}19 e l s e i f ( Action . conta in s ( " Inve r t Color " ) )

{21 Inver tCo lo r ( ) ;

}23 e l s e i f ( Action . conta in s ( " Sharpen Edges " ) )

{25 SharpenEdges ( ) ;

}27 }

29 Conf igurat ion . c l o s e ( ) ;Pro f i l eMat . r e l e a s e ( ) ;

31 Pro f i l eData . c l o s e ( ) ;

33 }

Listing 6.13. ProfileProcessor Process Function

This portion of code, defines that this function requires two arguments as inputs. Oneis the location address of a profile data file and the other is the location address of aconfiguration file. Profile data file is the same file that has been used to store acquisitiondata while configuration file is a new input file which dictates to processor how to processfiles. This new file may seems to make the system unnecessarily complex but this option isintended to make it simpler. Sometimes when a utility software similar to this one is sold,it happens that the system is no longer be able to perform its job. In most cases whena technical support gets dispatched and checks the system, it comes up that the systemneeds to reconfigure to adopt to the new situation. A change in situation may be causedby even different illumination. So in this cases it is much easier to change a configurationfile instead of whole program. By the way, this function reads contents of configurationfile and decides what is the next action to take. After all actions are finished, it closes twotext files.Now lets analyze four actions that have been already implemented.

• LoadProfile

55

Page 64: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

Listing 6.14 lists the required functions to load a profile data file.

1 void P r o f i l e P r o c e s s o r : : LoadPro f i l e ( QString F i l eLoca t i on ){

3 Pro f i l eData . setFileName ( F i l eLoca t i on ) ;Pro f i l eData . open ( QIODevice : : ReadOnly ) ;

5 Pro f i l eS t r eam . se tDev ice (& Pro f i l eData ) ;i n t x , y , z , yold =0, xindex=−1,yindex=−1;

7 i n t xindexmax=0,yindexmax=0,zmax=0,zmin=std : : numeric_l imits<int >: :max( ) ;QString ReadLine ;

9 QList <QString> Spl i t tedData ;

11 //Scan f i l e in order to f i n d the image dimensionsPro f i l eS t r eam . readLine ( ) ; // F i r s t Line

13 Pro f i l eS t r eam . readLine ( ) ; // Second Linewhi l e ( ! Pro f i l eS t r eam . atEnd ( ) )

15 {ReadLine=Pro f i l eS t r eam . readLine ( ) ;

17 Spl i t t edData=ReadLine . s p l i t ( " \ t " ) ;y=Spl i t tedData . at (0 ) . t o In t ( ) ;

19 x=Spl i t tedData . at (1 ) . t o In t ( ) ;z=Spl i t tedData . at (2 ) . t o In t ( ) ;

21 i f ( y!= yold ){

23 yindex++;xindex=−1;

25 yold=y ;}

27 xindex++;i f ( xindex>xindexmax ) xindexmax=xindex ;

29 i f (y>yindexmax ) yindexmax=y ;i f ( z>zmax) zmax=z ;

31 i f ( z<zmin ) zmin=z ;}

33

// Create Mat o b j e c t based on image s i z e35 Prof i l eMat= Mat : : z e r o s ( yindexmax+1,xindexmax+1,CV_8UC1) ;

37 //Read f i l e again to f i l l the Mat o b j e c t a c co rd ing lyPro f i l eS t r eam . seek (0 ) ;

39 Pro f i l eS t r eam . readLine ( ) ; // F i r s t LinePro f i l eS t r eam . readLine ( ) ; // Second Line

41 xindex=−1;yindex=−1;

43 whi le ( ! Pro f i l eS t r eam . atEnd ( ) ){

45 ReadLine=Pro f i l eS t r eam . readLine ( ) ;Sp l i t t edData=ReadLine . s p l i t ( " \ t " ) ;

47 y=Spl i t tedData . at (0 ) . t o In t ( ) ;x=Spl i t tedData . at (1 ) . t o In t ( ) ;

49 z=Spl i t tedData . at (2 ) . t o In t ( ) ;i f ( y!= yold )

51 {yindex++;

56

Page 65: Thesis Report

6 – Image Pre-Processing

53 xindex=−1;yold=y ;

55 }xindex++;

57 i n t ScaledValue =((z−zmin ) ∗ 254/(zmax−zmin ) ) +1;Pro f i l eMat . at<uchar >(yindex , xindex )= ScaledValue ;

59 }//Check i f i t has zero va lue s

61 f o r ( yindex =1; yindex<Prof i l eMat . rows ; yindex++)f o r ( xindex =0; xindex<Prof i l eMat . c o l s ; xindex++)

63 i f ( Pro f i l eMat . at<uchar >(yindex , xindex )==0){

65 Prof i l eMat . at<uchar >(yindex , xindex )= Prof i l eMat . at<uchar >(yindex −1, xindex ) ;

}67 f o r ( yindex=Prof i l eMat . rows −2; yindex >=0;yindex −−)

f o r ( xindex=Prof i l eMat . co l s −1; xindex >=0;xindex −−)69 i f ( Pro f i l eMat . at<uchar >(yindex , xindex )==0)

{71 Prof i l eMat . at<uchar >(yindex , xindex )= Prof i l eMat . at<

uchar >(yindex +1, xindex ) ;}

73 emit SendCurrentOperation ( " P r o f i l e Data Loaded " ) ;ShowImage ( ) ;

75 }

Listing 6.14. ProfileProcessor Load Profile

The LoadProfile function primarily opens the data file and reads it line by line.Two first lines are not important since they are dedicated to column headers. Thenit reads following lines and use the same method of MATLAB program to finddimensions of P matrix. Open-CV uses a variable of type mat to store and workwith images. This variable dynamically allocates memory and release it when it isnot needed anymore. Copying mat objects by using a=b syntax does not copy thedata but it only copies the pointer. There is a specific function to copy also thecontent of mat objects. in the first loop the function scans the file just to find theappropriate dimensions of final mat object. After that at line 35, it creates a matobject which is a matrix of appropriate dimensions and defines that the value ofthis matrix elements is a single scalar and can be represented by 8 bits. This is themethod that Open-CV deals with grayscale images. Now that the matrix is createdand filled with zeros, its the time to restart reading data file and fill the mat objectaccordingly. Same as MATLAB code it is possible to have zero elements inside thematrix because sensor does not return same number of points for every acquisition,so it is necessary to fill the zero elements with a neighbor’s value. Figure 6.11 depictsthe output of this stage.

• According to obtained picture, it is necessary to rotate the image whenever its xdimension is less than y dimension. Listing 6.15 lists the required command tocheck and rotate image mat.

57

Page 66: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

Figure 6.11. Open-CV Loaded File

1 void P r o f i l e P r o c e s s o r : : Cor rec tOr i enta t i on ( ){

3 //Check i f i t i s nece s sa ry to r o t a t e the imagei f ( Pro f i l eMat . co l s <Prof i l eMat . rows )

5 t ranspose ( Prof i leMat , Pro f i l eMat ) ;emit SendCurrentOperation ( " Or i entat i on Corrected " ) ;

7 ShowImage ( ) ;}

Listing 6.15. ProfileProcessor Correct Orientation

This function and all others send the title of operation and also the image to "Main-Window" by means of two signals. Figure 6.12 depicts the image with correctedorientation.

• Same as MATLAB’s procedure, next step is to invert colors. Listing 6.16 shows theusage of "bitwise_not" command that is defined in Open-CV library.

void P r o f i l e P r o c e s s o r : : Inver tCo lo r ( )2 {

bitwise_not ( Prof i leMat , Pro f i l eMat ) ;4 emit SendCurrentOperation ( " Colors Inver ted " ) ;

ShowImage ( ) ;6 }

Listing 6.16. ProfileProcessor Invert Colors

Figure 6.13 shows the result of color inversion.

58

Page 67: Thesis Report

6 – Image Pre-Processing

Figure 6.12. Open-CV Orientation Corrected

Figure 6.13. Open-CV Colors Inverted

• Sharpen edges action is a bit different from what was done in MATLAB procedure.Listing 6.17 shows the steps of this action.void P r o f i l e P r o c e s s o r : : SharpenEdges ( )

2 {

4 GaussianBlur ( Prof i leMat , ProfileMatAux , S i z e (0 , 0) , 3) ;addWeighted ( Prof i leMat , 1 . 5 , ProfileMatAux , −0.5 , 0 , ProfileMatAux );

59

Page 68: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

6 Prof i l eMat=ProfileMatAux ;emit SendCurrentOperation ( " Edges Sharpened " ) ;

8 ShowImage ( ) ;}

Listing 6.17. ProfileProcessor Sharpen Edges

This function finds a new image by applying Gaussian blur technique. Then thisblurred new image is deducted from original one with a half weight. The resultingimage is depicted on figure 6.14.

Figure 6.14. Open-CV Edges Sharpened

• As previously mentioned all of these functions use a function to send the imageresult. Listing 6.18 denotes the required commands to transform a mat object to aQPixmap object so that Qt will be able to show it as a background image of a label.

1 void P r o f i l e P r o c e s s o r : : ShowImage ( ){

3 QThread : : msleep (200) ;s t a t i c QVector<QRgb> sColorTable ;

5

// only c r e a t e our c o l o r t a b l e once7 i f ( sColorTable . isEmpty ( ) )

{9 f o r ( i n t i = 0 ; i < 256 ; ++i )

sColorTable . push_back ( qRgb( i , i , i ) ) ;11 }

13 QImage ImageQImage ( Pro f i l eMat . data , Pro f i l eMat . co l s , Pro f i l eMat .rows , Pro f i l eMat . step , QImage : : Format_Indexed8 ) ;ImageQImage . setColorTable ( sColorTable ) ;

60

Page 69: Thesis Report

6 – Image Pre-Processing

15

QPixmap ImageQPixmap = QPixmap : : fromImage ( ImageQImage ) ;17 emit SendImage ( ImageQPixmap) ;

}

Listing 6.18. ProfileProcessor ShowImage

ShowImage function creates a color table only once to map a single color value tothree values colors. This action is necessary since QImage objects needs to storecolor data in RGB format. When the QImage object is created, it can be convertedto QPixmap object and sent to MainWindow.

These actions were the implemented ones in this thesis. Since the main focus of itwas on design and build of RS485 interface, other image processing actions were left forfuture studies. The most important point is that this software created an infrastructurefor further completions which is easy to understand and interact.

61

Page 70: Thesis Report

62

Page 71: Thesis Report

Chapter 7

Conclusion

This thesis analyzed the importance of DOT code and created a device to make possiblethe communication between a laser sensor and PC. It also developed different computerprograms to acquire and process data. In order to have the final device to be sold thereare still following works to be done.

• A gyroscope should be added to this device to compensate sudden movements ofdevice otherwise the scanned data could be scrambled.

• A cloud server should be procured and the corresponding program should be up-loaded on it.

• A wireless module should be added to system such a way that it interacts withmicro-controller and MAX485 on behalf of USB to Serial converter.

• Further actions should be added to Qt plus Open-CV application. The substrate forthis addition has been already done. So this work will be fast.

• A PC application should be developed to just receive the final answer of cloud whichis a DOT code and print it with its corresponding data on a paper. This applicationneeds socket programming.

Although this approach can be modified to have better and more accurate data, thevariable illumination (structured lighting) method will be much more accurate since inthis approach there is no need to move the device over tire and it can be done by hoveringthe device on DOT code for less than a second.

63

Page 72: Thesis Report

64

Page 73: Thesis Report

Bibliography

[1] Michelin Company Canada, Reading A Tire Sidewall, available on-line at <http://www.michelin.ca/tires-101/tire-basics/about-tires/reading-your-sidewall.page>

[2] Leith Autopark Kia, September 2014, How To Check YourTire Tread for Wear. <http://blog.leithautoparkkia.com/how-to-check-your-tire-tread-tires-raleigh/>

[3] Tire Profiles LLC, TreadSpec Documents. <http://www.tireprofiles.com/treadspec/>

[4] Tire Profiles LLC, GrooveGlove Documents. <http://www.tireprofiles.com/grooveglove/>

[5] TIRE TECH, Determining the Age of a Tire, available online at <http://www.tirerack.com/tires/tiretech/techpage.jsp?techid=11>

[6] Baumer, BA OM70 MESAX multi-spot. <http://pfinder.baumer.com/pfinder_sensor/downloads/Produkte/PDF/Allgemein/en_BA_RS485_MESAX_multi-spot_Commands.pdf>

[7] Baumer, BA RS485 MESAX multi-spot commands,<http://pfinder.baumer.com/pfinder_sensor/downloads/Produkte/PDF/Allgemein/en_BA_OM70_MESAX_multi-spot.pdf>

[8] WIKIBOOKS, April 2016, Serial Programming/RS-485. <https://en.wikibooks.org/wiki/Serial_Programming/RS-485>

[9] Atmel, ATmega16(L) datasheet, available online at <http://www.atmel.com/images/doc2466.pdf>

[10] Maxminintegrated, MAX481 MAX483 MAX485 MAX487 MAX491 MAX1487,available online at <https://datasheets.maximintegrated.com/en/ds/MAX1487-MAX491.pdf>

[11] Prolific Technology Inc., PL-2303HXD Datasheet, available online at http://www.prolific.com.tw/UserFiles/files/ds_pl2303HXD_v1_4_4.pdf>

[12] Nokia, Qt Documentation, available online at http://doc.qt.io/>[13] OpenCV, Open Source Computer Vision v3.1.0, http://docs.opencv.org/3.1.0/

#gsc.tab=0>[14] Kyung, C.M. ed., 2016. Theory and Applications of Smart Cameras. Springer Nether-

lands.

65

Page 74: Thesis Report

Appendices

66

Page 75: Thesis Report

Appendix A

Micro-controller C Code

#inc lude <mega16 . h>2 #inc lude <delay . h>

// Dec lare your g l o b a l v a r i a b l e s here4 i n t i ;

#d e f i n e DATA_REGISTER_EMPTY (1<<UDRE)6 #d e f i n e RX_COMPLETE (1<<RXC)

#d e f i n e FRAMING_ERROR (1<<FE)8 #d e f i n e PARITY_ERROR (1<<UPE)

#d e f i n e DATA_OVERRUN (1<<DOR)10

// Get a charac t e r from the USART Rece iver12 #i f n d e f _DEBUG_TERMINAL_IO_

#d e f i n e _ALTERNATE_GETCHAR_14 #pragma used+

char getchar ( void )16 {

char s tatus , data ;18 whi le (1 )

{20 whi le ( ( ( s t a t u s=UCSRA) & RX_COMPLETE)==0) ;

data=UDR;22 i f ( ( s t a t u s & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN) )==0)

return data ;24 }

}26 #pragma used−

#e n d i f28

// Write a charac t e r to the USART Transmitter30 #i f n d e f _DEBUG_TERMINAL_IO_

#d e f i n e _ALTERNATE_PUTCHAR_32 #pragma used+

void putchar ( char c )34 {

whi l e ( (UCSRA & DATA_REGISTER_EMPTY)==0) ;36 UDR=c ;

}38 #pragma used−

67

Page 76: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

#e n d i f40

// Standard Input /Output f u n c t i o n s42 #inc lude <s t d i o . h>

44 void main ( void ){

46 // Dec lare your l o c a l v a r i a b l e s herechar ch , cr , cn ;

48

// Input /Output Ports i n i t i a l i z a t i o n50 // Port A i n i t i a l i z a t i o n

// Function : Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In52 DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) |

(0<<DDA1) | (0<<DDA0) ;// State : Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

54 PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) |(0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0) ;

56 // Port B i n i t i a l i z a t i o n// Function : Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

58 DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) |(0<<DDB1) | (0<<DDB0) ;

// State : Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T60 PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) |

(0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0) ;

62 // Port C i n i t i a l i z a t i o n// Function : Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In

64 DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) |(0<<DDC1) | (0<<DDC0) ;

// State : Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T66 PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) |

(0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0) ;

68 // Port D i n i t i a l i z a t i o n// Function : Bit7=In Bit6=Out Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=

In70 DDRD=(0<<DDD7) | (1<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) |

(0<<DDD1) | (0<<DDD0) ;// State : Bit7=T Bit6=0 Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T

72 PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) |(0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0) ;

74 // Timer/Counter 0 i n i t i a l i z a t i o n// Clock source : System Clock

76 // Clock value : Timer 0 Stopped// Mode : Normal top=0xFF

78 // OC0 output : DisconnectedTCCR0=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (0<<CS02) | (0<<

CS01) | (0<<CS00) ;80 TCNT0=0x00 ;

OCR0=0x00 ;82

68

Page 77: Thesis Report

A – Micro-controller C Code

// Timer/Counter 1 i n i t i a l i z a t i o n84 // Clock source : System Clock

// Clock value : Timer1 Stopped86 // Mode : Normal top=0xFFFF

// OC1A output : Disconnected88 // OC1B output : Disconnected

// Noise Cance ler : Off90 // Input Capture on F a l l i n g Edge

// Timer1 Overflow In t e r r u p t : Off92 // Input Capture In t e r r up t : Off

// Compare A Match I n t e r ru p t : Off94 // Compare B Match In t e r r u p t : Off

TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) |(0<<WGM10) ;

96 TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (0<<CS10) ;

TCNT1H=0x00 ;98 TCNT1L=0x00 ;

ICR1H=0x00 ;100 ICR1L=0x00 ;

OCR1AH=0x00 ;102 OCR1AL=0x00 ;

OCR1BH=0x00 ;104 OCR1BL=0x00 ;

106 // Timer/Counter 2 i n i t i a l i z a t i o n// Clock source : System Clock

108 // Clock value : Timer2 Stopped// Mode : Normal top=0xFF

110 // OC2 output : DisconnectedASSR=0<<AS2 ;

112 TCCR2=(0<<PWM2) | (0<<COM21) | (0<<COM20) | (0<<CTC2) | (0<<CS22) | (0<<CS21) | (0<<CS20) ;

TCNT2=0x00 ;114 OCR2=0x00 ;

116 // Timer ( s ) /Counter ( s ) I n t e r r up t ( s ) i n i t i a l i z a t i o nTIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1 ) | (0<<OCIE1A) | (0<<OCIE1B) |

(0<<TOIE1) | (0<<OCIE0) | (0<<TOIE0) ;118

// External I n t e r ru p t ( s ) i n i t i a l i z a t i o n120 // INT0 : Off

// INT1 : Off122 // INT2 : Off

MCUCR=(0<<ISC11 ) | (0<<ISC10 ) | (0<<ISC01 ) | (0<<ISC00 ) ;124 MCUCSR=(0<<ISC2 ) ;

126 // USART i n i t i a l i z a t i o n// Communication Parameters : 8 Data , 1 Stop , Even Par i ty

128 // USART Rece iver : On// USART Transmitter : On

130 // USART Mode : Asynchronous// USART Baud Rate : 57600

69

Page 78: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

132 UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (0<<U2X) | (0<<MPCM) ;

UCSRB=(0<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (1<<RXEN) | (1<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8) ;

134 UCSRC=(1<<URSEL) | (0<<UMSEL) | (1<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL) ;

UBRRH=0x00 ;136 UBRRL=0x0B ;

138 // Analog Comparator i n i t i a l i z a t i o n// Analog Comparator : Off

140 // The Analog Comparator ’ s p o s i t i v e input i s// connected to the AIN0 pin

142 // The Analog Comparator ’ s negat ive input i s// connected to the AIN1 pin

144 ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) |(0<<ACIS1) | (0<<ACIS0) ;

SFIOR=(0<<ACME) ;146

// ADC i n i t i a l i z a t i o n148 // ADC d i s a b l e d

ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) | (0<<ADPS1) | (0<<ADPS0) ;

150

// SPI i n i t i a l i z a t i o n152 // SPI d i s a b l e d

SPCR=(0<<SPIE) | (0<<SPE) | (0<<DORD) | (0<<MSTR) | (0<<CPOL) | (0<<CPHA) |(0<<SPR1) | (0<<SPR0) ;

154

// TWI i n i t i a l i z a t i o n156 // TWI d i s a b l e d

TWCR=(0<<TWEA) | (0<<TWSTA) | (0<<TWSTO) | (0<<TWEN) | (0<<TWIE) ;158

PORTD.6=1;160 cr=0x0D ;

cn=0x0A ;162 delay_ms (2000) ;

p r i n t f ( " : 01W010 ; 0 ; ∗∗∗∗%c%c " , cr , cn ) ;164 delay_ms (100) ;

p r i n t f ( " : 01W006 ; 2 ; ∗∗∗∗%c%c " , cr , cn ) ;166 delay_ms (100) ;

UBRRL=0x05 ;168 // whi le (1 )

//{170 // p r i n t f ( " : 0 1 R001 ; ∗∗∗∗%c%c " , cr , cn ) ;

//delay_ms (500) ;172 //}

174 whi le (1 ){

176 // Place your code herech=getchar ( ) ;

178 i f ( ch==’ : ’ ){

70

Page 79: Thesis Report

A – Micro-controller C Code

180 PORTD.6=1;putchar ( ch ) ;

182 }e l s e i f ( ch==0x0B)

184 {// putchar ( ch ) ;

186 f o r ( i =0; i <100; i++) ;PORTD.6=0;

188 }e l s e

190 putchar ( ch ) ;}

192 }

71

Page 80: Thesis Report

Appendix B

Laser Sensor Header Code

#i f n d e f LASERSENSOR_H2 #d e f i n e LASERSENSOR_H

4 #inc lude <QtSer ia lPort >#inc lude <QString>

6

c l a s s LaserSensor : pub l i c QObject8 {

Q_OBJECT10

12 pub l i c :LaserSensor ( ) ; // Constructor

14 ~ LaserSensor ( ) ;

16 p r i v a t e s l o t s :void ReadPro f i l e ( ) ;

18 void FindAvai lab lePorts ( ) ; // Searches f o r a l l a v a i l a b l e COM port svoid In i tConnect ion ( QString PORTName) ; // I n i t i a t e s the connect ion

20 void CheckConnection ( ) ; // Checks f o r connect ion presencevoid ReadAppl icat ionError ( ) ; //Reads a p p l i c a t i o n e r r o r code

22 void ReadVendorInfo ( ) ;void ReadDeviceInfo ( ) ;

24 void ReadBusAddress ( ) ;void WriteBusAddress ( i n t BusAddressValue ) ;

26 void ReadBaudRate ( ) ;void WriteBaudRate ( i n t S e l e c t ) ;

28 void ReadRS485Lock ( ) ;void WriteRS485Lock ( bool Switch ) ;

30 void ReadTouchButtonLock ( ) ;void WriteTouchButtonLock ( bool Switch ) ;

32 void ReadMeasurementType ( ) ;void WriteMeasurementType ( i n t S e l e c t ) ;

34 void ReadMeasurementValue ( ) ;void ReadAllMeasurementValues ( ) ;

36 void ReadFieldOfView ( ) ;void WriteFieldOfView ( i n t LimitLeft , i n t LimitRight ) ;

38 void WriteFiledOfViewToMax ( ) ;

72

Page 81: Thesis Report

B – Laser Sensor Header Code

void ReadObjectType ( ) ;40 void WriteObjectType ( bool Switch ) ;

void ReadPrec is ion ( ) ;42 void Wri tePrec i s i on ( i n t S e l e c t ) ;

void ReadLaserOffDataHold ( ) ;44 void WriteLaserOffDataHold ( bool Switch ) ;

void ReadFlexMountEnable ( ) ;46 void WriteFlexMountEnable ( bool Switch ) ;

void ReadSetFlexMount ( ) ;48 void WriteSetFlexMount ( f l o a t Angle , f l o a t Distance ) ;

void WriteTeachFlexMountCommand ( f l o a t ReferenceThickness ) ;50 void ReadDiagnoseMode ( ) ;

void WriteDiagnoseMode ( bool Switch ) ;52 void WriteStoreConfigurationCommand ( i n t Conf ig ) ;

void WriteResetToFactorySettingsCommand ( i n t Command) ;54 void SampleNoChanged ( QString SampleNumber ) ;

void CloseConnect ion ( ) ;56

s i g n a l s :58 void Ava i l ab l ePor t s ( i n t TotalNumber , QVector<QString> Ports ) ; // Searches

f o r a l l a v a i l a b l e COM port svoid Connect ionStatus ( bool Status ) ;

60 void App l i ca t i onError ( i n t App l i ca t ionError ) ; //Reads a p p l i c a t i o n e r r o rcodevoid VendorID ( i n t Vendor_ID ) ;

62 void VendorName( QString Vendor_Name) ;void DeviceID ( i n t Device_ID ) ;

64 void VariantID ( i n t Variant_ID ) ;void SensorType ( QString Sensor_Type ) ;

66 void SerialNumber ( QString Serial_Number ) ;void BusAddress ( i n t BusAddressValue ) ;

68 void BaudRate ( i n t BuadRateValue ) ;void RS485Lock ( bool Switch ) ;

70 void TouchButtonLock ( bool Switch ) ;void MeasurementType ( QString Type ) ;

72 void MeasurementValue ( f l o a t MeasurementValue , QString Qual i ty ) ;void Average ( QString average ) ;

74 void Max ( QString max) ;void Min ( QString min ) ;

76 void Delta ( QString d e l t a ) ;void StandardDeviat ion ( QString s tandarddev ia t i on ) ;

78 void Qual i ty ( QString q u a l i t y ) ;void FieldOfView ( i n t LimitLeft , i n t LimitRight ) ;

80 void ObjectType ( QString ObjectType ) ;void P r e c i s i o n ( QString P r e c i s i o n ) ;

82 void LaserOffDataHold ( bool Switch ) ;void FlexMountEnable ( bool Switch ) ;

84 void SetFlexMount ( f l o a t Angle , f l o a t Distance ) ;void DiagnoseModeEnabled ( ) ;

86 void P r o f i l e ( i n t Xpos [ 3 0 0 ] , i n t Zpos [ 3 0 0 ] ) ;void SensorTimedOut ( bool Switch ) ;

88 void Pro f i l eReady ( ) ;

90 p r i v a t e :

73

Page 82: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

bool ReceiveResponse ( ) ;92 void SendCommand ( QString Command) ;

QString CRCMake( QString Command) ;94 QSer ia lPort ∗ s e r i a l ;

i n t DeviceAddress ;96 QString Response ;

QStr ingLi s t Payloads ;98 QFile Pro f i l eData ;

QTextStream Pro f i l eS t r eam ;100 QFile Pro f i l eData1 ;

QTextStream Pro f i l eSt ream1 ;102 QString SampleNo ;

i n t Yindex ;104 bool f i l e c r e a t e d ;

} ;106

108 #e n d i f // LASERSENSOR_H

74

Page 83: Thesis Report

Appendix C

Laser Sensor C++ Code

#inc lude " l a s e r s e n s o r . h "2

LaserSensor : : LaserSensor ( )4 {

qRegisterMetaType<QVector<QString> >(" QVector<QString>" ) ;6 s e r i a l = new QSer ia lPort ( t h i s ) ;

s e r i a l −>setBaudRate ( QSer ia lPort : : Baud115200 ) ;8 s e r i a l −>setDataBits ( QSer ia lPort : : Data8 ) ;

s e r i a l −>s e t P a r i t y ( QSer ia lPort : : EvenParity ) ;10 s e r i a l −>setStopBi t s ( QSer ia lPort : : OneStop ) ;

s e r i a l −>setFlowContro l ( QSer ia lPort : : NoFlowControl ) ;12 DeviceAddress =1;

Yindex=0;14 f i l e c r e a t e d=f a l s e ;

SampleNo=" 1 " ;16 }

18 void LaserSensor : : F indAvai lab lePorts ( ){

20 i n t TotalNumber=0;QVector<QString> Ports (0 ) ;

22 f o r each ( const QSer i a lPor t In fo &in fo , QSer i a lPor t In fo : : a v a i l a b l e P o r t s ( ) ){

24 i f ( ! i n f o . isBusy ( ) ){

26 Ports . append ( i n f o . portName ( ) ) ;TotalNumber++;

28 }}

30 emit Ava i l ab l ePor t s ( TotalNumber , Ports ) ;}

32

void LaserSensor : : In i tConnect ion ( QString PORTName)34 {

s e r i a l −>setPortName (PORTName) ;36 s e r i a l −>open ( QIODevice : : ReadWrite ) ;

i f ( s e r i a l −>isOpen ( ) && s e r i a l −>isWr i tab l e ( ) )38 emit Connect ionStatus ( t rue ) ;

75

Page 84: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

e l s e40 {

emit Connect ionStatus ( f a l s e ) ;42 }

SendCommand( "W010; 0 " ) ;44 ReceiveResponse ( ) ;

}46

void LaserSensor : : CheckConnection ( )48 {

50 }

52 void LaserSensor : : ReadAppl icat ionError ( ){

54

}56

void LaserSensor : : ReadVendorInfo ( )58 {

SendCommand( " R001 " ) ;60 i f ( ReceiveResponse ( ) )

{62 emit VendorID ( Payloads [ 1 ] . t o In t ( ) ) ;

emit VendorName( Payloads [ 2 ] ) ;64 }

66 }

68 void LaserSensor : : ReadDeviceInfo ( ){

70 SendCommand( " R002 " ) ;i f ( ReceiveResponse ( ) )

72 {emit DeviceID ( Payloads [ 1 ] . t o In t ( ) ) ;

74 emit VariantID ( Payloads [ 2 ] . t o In t ( ) ) ;emit SensorType ( Payloads [ 3 ] ) ;

76 emit SerialNumber ( Payloads [ 4 ] ) ;}

78 }

80 void LaserSensor : : ReadBusAddress ( ){

82

}84

void LaserSensor : : WriteBusAddress ( i n t BusAddressValue )86 {

88 }

90 void LaserSensor : : ReadBaudRate ( ){

92

76

Page 85: Thesis Report

C – Laser Sensor C++ Code

}94

void LaserSensor : : WriteBaudRate ( i n t S e l e c t )96 {

98 }

100 void LaserSensor : : ReadRS485Lock ( ){

102

}104

void LaserSensor : : WriteRS485Lock ( bool Switch )106 {

108 }

110 void LaserSensor : : ReadTouchButtonLock ( ){

112

}114

void LaserSensor : : WriteTouchButtonLock ( bool Switch )116 {

118 }

120 void LaserSensor : : ReadMeasurementType ( ){

122

}124

void LaserSensor : : WriteMeasurementType ( i n t S e l e c t )126 {

128 }

130 void LaserSensor : : ReadMeasurementValue ( ){

132

}134

void LaserSensor : : ReadAllMeasurementValues ( )136 {

SendCommand( " R022 " ) ;138 i f ( ReceiveResponse ( ) )

{140 emit Average ( Payloads [ 1 ] ) ;

emit Max( Payloads [ 2 ] ) ;142 emit Min( Payloads [ 3 ] ) ;

emit Delta ( Payloads [ 4 ] ) ;144 emit StandardDeviat ion ( Payloads [ 5 ] ) ;

emit Qual i ty ( Payloads [ 6 ] ) ;146 }

77

Page 86: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

}148

void LaserSensor : : ReadFieldOfView ( )150 {

152 }

154 void LaserSensor : : WriteFieldOfView ( i n t LimitLeft , i n t LimitRight ){

156

}158

void LaserSensor : : WriteFiledOfViewToMax ( )160 {

162 }

164 void LaserSensor : : ReadObjectType ( ){

166

}168

void LaserSensor : : WriteObjectType ( bool Switch )170 {

172 }

174 void LaserSensor : : ReadPrec is ion ( ){

176

}178

void LaserSensor : : Wr i t ePrec i s i on ( i n t S e l e c t )180 {

182 }

184 void LaserSensor : : ReadLaserOffDataHold ( ){

186

}188

void LaserSensor : : WriteLaserOffDataHold ( bool Switch )190 {

192 }

194 void LaserSensor : : ReadFlexMountEnable ( ){

196

}198

void LaserSensor : : WriteFlexMountEnable ( bool Switch )200 {

78

Page 87: Thesis Report

C – Laser Sensor C++ Code

202 }

204 void LaserSensor : : ReadSetFlexMount ( ){

206

}208

void LaserSensor : : WriteSetFlexMount ( f l o a t Angle , f l o a t Distance )210 {

212 }

214 void LaserSensor : : WriteTeachFlexMountCommand ( f l o a t ReferenceThickness ){

216

}218

void LaserSensor : : ReadDiagnoseMode ( )220 {

222 }

224 void LaserSensor : : WriteDiagnoseMode ( bool Switch ){

226 //SendCommand ( "W032 ; 1 " ) ;// ReceiveResponse ( ) ;

228 //SendCommand ( "W020 ; 1 0 " ) ;// ReceiveResponse ( ) ;

230 SendCommand( "W030; −20;20 " ) ;ReceiveResponse ( ) ;

232 SendCommand( " R030 " ) ;ReceiveResponse ( ) ;

234 SendCommand( "W050; 1 " ) ;i f ( ReceiveResponse ( ) )

236 {emit DiagnoseModeEnabled ( ) ;

238 }}

240

void LaserSensor : : ReadPro f i l e ( )242 {

i f ( ! f i l e c r e a t e d )244 {

QDateTime currentdateandt ime = QDateTime : : currentDateTime ( ) ;246 i f ( ! QDir ( " P r o f i l e s " ) . e x i s t s ( ) )

QDir ( ) . mkdir ( " P r o f i l e s " ) ;248 Pro f i l eData . setFileName ( QDir : : currentPath ( )+" / P r o f i l e s /

Profi leData_Sample "+SampleNo+"_"+ currentdateandt ime . t o S t r i n g ( " yyyy−MM−dd_hh−mm−s s " )+" . tpd " ) ;

Pro f i l eData . open ( QIODevice : : WriteOnly ) ;250 Pro f i l eData1 . setFileName ( QDir : : currentPath ( )+" / P r o f i l e s / Pro f i l eData .

tpd " ) ;Pro f i l eData1 . open ( QIODevice : : WriteOnly ) ;

79

Page 88: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

252 Pro f i l eS t r eam . se tDev ice (& Pro f i l eData ) ;Pro f i l eS t r eam << "Y\tX\ t \Z" <<endl <<endl ;

254 Pro f i l eSt ream1 . se tDev ice (& Pro f i l eData1 ) ;Pro f i l eSt ream1 << "Y\tX\ t \Z" <<endl <<endl ;

256 f i l e c r e a t e d=true ;}

258 SendCommand( " R052 " ) ;i f ( ReceiveResponse ( ) )

260 {i f ( Payloads [ 0 ] . c onta in s ( "A" ) )

262 {QStr ingLi s t XZMeasurements ;

264 XZMeasurements=Payloads [ 2 ] . s p l i t ( " " ) ;i n t TotalMeasurements=XZMeasurements [ 0 ] . t o In t ( ) ;

266 XZMeasurements . removeFirst ( ) ;Yindex++;

268 f o r ( i n t i =0; i<TotalMeasurements /2 ; i++){

270 Pro f i l eS t r eam << Yindex <<" \ t " << XZMeasurements [ 2 ∗ i ] <<" \ t "<<XZMeasurements [ 2 ∗ i +1] <<endl ;

Pro f i l eSt ream1 << Yindex <<" \ t " << XZMeasurements [ 2 ∗ i ] <<" \ t" <<XZMeasurements [ 2 ∗ i +1] <<endl ;

272 }emit Pro f i l eReady ( ) ;

274 }e l s e

276 {qDebug ( )<<" Error Handling "<<Payloads [ 0 ] ;

278 i f ( Payloads [1]== " 7 " )WriteDiagnoseMode ( t rue ) ;

280 e l s eReadPro f i l e ( ) ;

282 }}

284 e l s eemit Pro f i l eReady ( ) ;

286 }

288 void LaserSensor : : WriteStoreConfigurationCommand ( i n t Config ){

290

}292

void LaserSensor : : WriteResetToFactorySettingsCommand ( i n t Command)294 {

296 }

298 void LaserSensor : : CloseConnect ion ( ){

300 Yindex=0;Pro f i l eData . c l o s e ( ) ;

302 Pro f i l eData1 . c l o s e ( ) ;f i l e c r e a t e d=f a l s e ;

80

Page 89: Thesis Report

C – Laser Sensor C++ Code

304 }

306 void LaserSensor : : SendCommand ( QString Command){

308 QChar cr=0x0D ;QChar cn=0x0A ;

310 QChar stopchar=0x0B ;QString ToSend=" : " ;

312 ToSend . append ( QString ( "%1" ) . arg ( DeviceAddress , 2 , 10 , QChar( ’ 0 ’ ) ) ) ;ToSend . append (Command) ;

314 ToSend . append ( " ; " ) ;ToSend . append ( " ∗∗∗∗ " ) ;

316 ToSend . append ( cr ) ;ToSend . append ( cn ) ;

318 ToSend . append ( stopchar ) ;s e r i a l −>wr i t e ( ToSend . toLat in1 ( ) ) ;

320

}322

QString LaserSensor : : CRCMake( QString Command)324 {

QString s t r=" " ;326 re turn s t r ;

}328

bool LaserSensor : : ReceiveResponse ( )330 {

QChar cn=0x0A ;332 Response . c l e a r ( ) ;

bool CompletelyReceived=f a l s e ;334 whi le ( ! CompletelyReceived )

{336 i f ( s e r i a l −>waitForReadyRead (200) )

{338 Response . append ( s e r i a l −>readAl l ( ) ) ;

qDebug ( ) << Response ;340 i f ( Response . conta in s ( cn ) ) CompletelyReceived=true ;

}342 e l s e

{344 re turn f a l s e ;

}346 }

qDebug ( ) << Response ;348 Payloads=Response . s p l i t ( " ; " ) ;

// Payloads . removeFirst ( ) ;350 re turn true ;

}352

LaserSensor : : ~ LaserSensor ( )354 {

s e r i a l −>c l o s e ( ) ;356 }

81

Page 90: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

358 void LaserSensor : : SampleNoChanged ( QString SampleNumber ){

360 SampleNo=SampleNumber ;}

82

Page 91: Thesis Report

Appendix D

Profile Processer MATLAB Code

1 c l cc l e a r

3 c l o s e a l l

5 %Read measured data from data f i l ef i l ename = ’E: \ Education \ Un ive r s i ty \MS\4 th Semester \ Thes i s \ Vers ions \Qt\v1 .6\

bui ld−DCR−Desktop_Qt_5_6_0_MSVC2015_64bit−Debug\ P r o f i l e s \ Pro f i l eData . tpd ’;

7 d e l i m i t e r I n = ’ \ t ’ ;h e a d e r l i n e s I n = 1 ;

9 P r o f i l e = importdata ( f i l ename , d e l i m i t e r I n , h e a d e r l i n e s I n ) ;

11 %Store x , y , z combination on x , y and z v e c t o r sx=P r o f i l e . data ( : , 2 ) ;

13 y=P r o f i l e . data ( : , 1 ) ;z=P r o f i l e . data ( : , 3 ) ;

15

p lo t3 (x , y , z , ’ .− ’ )17

t r i = delaunay (x , y ) ;19 p lo t (x , y , ’ . ’ )

21 [ r , c ] = s i z e ( t r i ) ;d i sp ( r )

23

h = t r i s u r f ( t r i , x , y , z ) ;25 a x i s v i s3d

a x i s o f f27 l = l i g h t ( ’ Po s i t i on ’ ,[ −50 −15 2 9 ] ) ;

s e t ( gca , ’ CameraPosition ’ , [ 208 −50 7687 ] ) ;29 l i g h t i n g phong

shading i n t e r p31 c o l o r b a r EastOutside

33 %Loading Measured data to matrix PYindex=0;

35 Xindex=0;yvalue=−1;

83

Page 92: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

37 f o r i =1: l ength ( x )i f ( y ( i )==yvalue )

39 Xindex=Xindex+1;e l s e

41 Yindex=Yindex+1;Xindex=1;

43 yvalue=y ( i ) ;end

45 P( Yindex , Xindex )=z ( i ) ;end

47

% Removing zero e lements from P r o f i l e matrix49 f o r x=1: s i z e (P, 1 )

f o r y=1: s i z e (P, 2 )51 i f (P(x , y )==0)

P(x , y )=P(x , y−1) ;53 end

end55 end

f i g u r e , s u r f (P) , t i t l e ( ’ 3D Sur face Representat ion ’ )57

59

%%61 % f o r y=1: s i z e (P, 2 )

% P( : , y )=P( : , y )−mean(P( : , y ) )+mean(P ( : ) ) ;63 % end

f o r x=1: s i z e (P, 1 )65 P(x , : )=P(x , : ) −(P(x , 1 )−P( 1 : 1 ) ) ;

end67 P=f l i p l r (P) ;

f i g u r e , s u r f (P) , t i t l e ( ’ 3D Sur face Representat ion − Leveled ’ )69

%%71

73 %% Finding maximum two conse cu t i v e po in t s d i f f e r e n c ef o r y=1: s i z e (P, 2 )

75 MaxDeltaVector ( y ) =0;f o r x=2: s i z e (P, 1 )

77 i f ( abs (P(x , y )−P(x−1,y ) )>MaxDeltaVector ( y ) )MaxDeltaVector ( y )=abs (P(x , y )−P(x−1,y ) ) ;

79 endend

81 endMaxDelta=max( MaxDeltaVector ) ;

83

% Finding abrupt z change between two conse c tu iv e po in t s ( r i g h t to l e f t )85 f o r y=1: s i z e (P, 2 )

P1(1 , y )=min (P ( : ) ) ;87 P1(2 , y )=min (P ( : ) ) ;

f o r x=3: s i z e (P, 1 )89 ExpectedValue=2∗P(x−1,y )−P(x−2,y ) ;

i f ( abs (P(x , y )−ExpectedValue ) <0.3∗MaxDelta )

84

Page 93: Thesis Report

D – Profile Processer MATLAB Code

91 P1(x , y )=min (P ( : ) ) ;e l s e

93 P1(x , y )=P(x , y ) ;end

95 endend

97

% Finding abrupt z change between two conse c tu iv e po in t s ( l e f t to r i g h t )99 f o r y=1: s i z e (P, 2 )

P1( end , y )=min (P ( : ) ) ;101 P1( end −1,y )=min (P ( : ) ) ;

f o r x=s i z e (P, 1 ) −2:−1:1103 ExpectedValue=2∗P( x+1,y )−P( x+2,y ) ;

i f ( abs (P(x , y )−ExpectedValue ) >0.3∗MaxDelta && P1(x , y )==0)105 P1(x , y )=P(x , y ) ;

end107 end

end109 f i g u r e , s u r f (P1) , t i t l e ( ’ Abrupt a l t i t u d e changes in 3D model ’ )

%%111 % Adding neighbor po in t s to c o l l e c t e d data

NeighborSize =3;113 P2=P1 ;

f o r y=1+NeighborSize : s i z e (P, 2 )−NeighborSize115 f o r x=1+NeighborSize : s i z e (P, 1 )−NeighborSize

f o r i=−NeighborSize : NeighborSize117 f o r j=−NeighborSize : NeighborSize

i f (P1( x+i , y+j )==P( x+i , y+j ) )119 P2(x , y )=P(x , y ) ;

end121 end

end123 end

end125 f i g u r e , s u r f (P2) , t i t l e ( ’Added neighbours ’ )

%%127 % Remove min value ( except 0)

P2=P2−min (P2 ( : ) ) ;129 minvalue=i n f ;

f o r y=1: s i z e (P, 2 )131 f o r x=1: s i z e (P, 1 )

i f (P2(x , y )~=0 && P2(x , y )<minvalue )133 minvalue=P2(x , y ) ;

end135 end

end137 f o r y=1: s i z e (P, 2 )

f o r x=1: s i z e (P, 1 )139 i f (P2(x , y ) ~=0)

P2(x , y )=P2(x , y )−minvalue ;141 end

end143 end

f i g u r e , s u r f (P2) , t i t l e ( ’Min Value Removed ’ )

85

Page 94: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

145 P=P2 ;

147 % % Saturated Leve l s% P(P>mean(P ( : ) ) )=mean(P ( : ) ) ;

149 % f i g u r e , s u r f (P) , t i t l e ( ’ Homogenized Levels ’ )%%

151 % Image SegmentationP=P ’ ;

153 I = mat2gray (P) ;mask = f a l s e ( s i z e ( I ) ) ;

155

f o r x=1: s i z e ( I , 1 )157 f o r y=1: s i z e ( I , 2 )

i f (P(x , y ) >=0.9∗max(P ( : ) ) )159 mask(x , y )=true ;

end161 end

end163

W = g r a y d i f f w e i g h t ( I , mask , ’ GrayDi f f e renceCuto f f ’ , 25) ;165 thresh = 0 . 0 1 ;

[BW, D] = imsegfmm (W, mask , thresh ) ;167 f i g u r e

imshow (BW)169 t i t l e ( ’ Segmented BW Image ’ )

%%171 f o r x=1: s i z e ( I , 1 )

f o r y=1: s i z e ( I , 2 )173 i f (BW(x , y )==f a l s e )

P(x , y ) =0;175 end

end177 end

I = mat2gray (P) ; f i g u r e , imshow ( I ) , t i t l e ( ’ Segmented Graysca le Image ’ )179

181 % % Modifying each l i n e a l t i t u d e to have same max value f o r a l l l i n e s% P=P ’ ;

183 % maxalt i tude=max(P ( : ) ) ;% f o r y=1: s i z e (P, 2 )

185 % P( : , y )=P( : , y ) ∗ ( maxalt i tude /max(P( : , y ) ) ) ;% end

187 % f i g u r e , s u r f (P) , t i t l e ( ’ Modif ied Image to have same max value f o r each l i n e’ )

% P=P ’ ;189

%P=P. ^ 5 ;191 %f i g u r e , s u r f (P)

193

195

%197 I = mat2gray (P) ; f i g u r e , imshow ( I )

86

Page 95: Thesis Report

D – Profile Processer MATLAB Code

%Contrast S t r e t ch ing199 P=P−min (P(P>0) ) ;

P(P<0)=0;201 P=P. ∗255/max(P ( : ) ) ;

I = mat2gray (P) ; f i g u r e , imshow ( I ) , t i t l e ( ’ Contrast Stre tched Image ’ ) ;203

%Negate Image205 P=255−P;

I = mat2gray (P) ; f i g u r e , imshow ( I ) , t i t l e ( ’ Negative Image ’ ) ;207

% Perform OCR209 r e s u l t s = ocr ( I ) ;

211 % Display one o f the recogn i z ed wordsword = r e s u l t s . Words{2}

213

% Locat ion o f the word in I215 wordBBox = r e s u l t s . WordBoundingBoxes ( 2 , : )

87

Page 96: Thesis Report

Appendix E

Profile Processor Header Code

1 #i f n d e f PROFILEPROCESSOR_H#d e f i n e PROFILEPROCESSOR_H

3

#inc lude <QWidget>5 #inc lude <opencv2/ core / core . hpp>

#inc lude <opencv2/ h ighgu i / h ighgu i . hpp>7 #inc lude <opencv2/ imgproc / imgproc . hpp>

#inc lude <QString>9 #inc lude <iostream>

#inc lude <QFile>11 #inc lude <QTextStream>

#inc lude <QDebug>13 #inc lude <QGenericMatrix>

#inc lude <QPixmap>15 #inc lude <QThread>

17 us ing namespace std ;us ing namespace cv ;

19

c l a s s P r o f i l e P r o c e s s o r : pub l i c QObject21 {

Q_OBJECT23

pub l i c :25 P r o f i l e P r o c e s s o r ( ) ;

void Process ( QString Pro f i l eDataLocat ion , QStringCon f i gu ra t i onF i l eLoca t i on ) ;

27 s i g n a l s :void SendImage (QPixmap Image ) ;

29 void SendCurrentOperation ( QString Command) ;p r i v a t e :

31 void LoadPro f i l e ( QString F i l eLoca t i on ) ;void ShowImage ( ) ;

33 void Cor rec tOr i enta t i on ( ) ;void Inver tCo lo r ( ) ;

35 void SharpenEdges ( ) ;Mat Prof i l eMat ;

37 Mat ProfileMatAux ;

88

Page 97: Thesis Report

E – Profile Processor Header Code

QFile Pro f i l eData ;39 QTextStream Pro f i l eS t r eam ;

QList <QList <int >> P r o f i l e M a t r i x ;41 QPixmap Prof i lePixmap ;

} ;43

#e n d i f // PROFILEPROCESSOR_H

89

Page 98: Thesis Report

Appendix F

Profile Processor C++ Code

#inc lude " p r o f i l e p r o c e s s o r . h "2

P r o f i l e P r o c e s s o r : : P r o f i l e P r o c e s s o r ( )4 {

// qRegisterMetaType<QVector<QString> >("QVector<QString >") ;6 }

8 void P r o f i l e P r o c e s s o r : : Process ( QString Pro f i l eDataLocat ion , QStringCon f i gu ra t i onF i l eLoca t i on )

{10 QFile Conf igurat ion ;

Conf igurat ion . setFileName ( Con f i gu ra t i onF i l eLoca t i on ) ;12 Conf igurat ion . open ( QIODevice : : ReadOnly ) ;

QTextStream Conf igurat ionStream ;14 Conf igurat ionStream . se tDev ice (& Conf igurat ion ) ;

whi l e ( ! Conf igurat ionStream . atEnd ( ) )16 {

QString Action=Conf igurat ionStream . readLine ( ) ;18 i f ( Action . conta in s ( " Load F i l e " ) )

{20 LoadPro f i l e ( Pro f i l eDataLocat ion ) ;

}22 e l s e i f ( Action . conta in s ( " Correct Or i entat i on " ) )

{24 Correc tOr i enta t i on ( ) ;

}26 e l s e i f ( Action . conta in s ( " Inve r t Color " ) )

{28 Inver tCo lo r ( ) ;

}30 e l s e i f ( Action . conta in s ( " Sharpen Edges " ) )

{32 SharpenEdges ( ) ;

}34 }

36 Conf igurat ion . c l o s e ( ) ;Pro f i l eMat . r e l e a s e ( ) ;

90

Page 99: Thesis Report

F – Profile Processor C++ Code

38 Pro f i l eData . c l o s e ( ) ;

40 }

42 void P r o f i l e P r o c e s s o r : : LoadPro f i l e ( QString F i l eLoca t i on ){

44 Pro f i l eData . setFileName ( F i l eLoca t i on ) ;Pro f i l eData . open ( QIODevice : : ReadOnly ) ;

46 Pro f i l eS t r eam . se tDev ice (& Pro f i l eData ) ;i n t x , y , z , yold =0, xindex=−1,yindex=−1;

48 i n t xindexmax=0,yindexmax=0,zmax=0,zmin=std : : numeric_l imits<int >: :max( ) ;QString ReadLine ;

50 QList <QString> Spl i t tedData ;

52 //Scan f i l e in order to f i n d the image dimensionsPro f i l eS t r eam . readLine ( ) ; // F i r s t Line

54 Pro f i l eS t r eam . readLine ( ) ; // Second Linewhi l e ( ! Pro f i l eS t r eam . atEnd ( ) )

56 {ReadLine=Pro f i l eS t r eam . readLine ( ) ;

58 Spl i t t edData=ReadLine . s p l i t ( " \ t " ) ;y=Spl i t tedData . at (0 ) . t o In t ( ) ;

60 x=Spl i t tedData . at (1 ) . t o In t ( ) ;z=Spl i t tedData . at (2 ) . t o In t ( ) ;

62 i f ( y!= yold ){

64 yindex++;xindex=−1;

66 yold=y ;}

68 xindex++;i f ( xindex>xindexmax ) xindexmax=xindex ;

70 i f (y>yindexmax ) yindexmax=y ;i f ( z>zmax) zmax=z ;

72 i f ( z<zmin ) zmin=z ;}

74

// Create Mat o b j e c t based on image s i z e76 Prof i l eMat= Mat : : z e r o s ( yindexmax+1,xindexmax+1,CV_8UC1) ;

78 //Read f i l e again to f i l l the Mat o b j e c t a c co rd ing lyPro f i l eS t r eam . seek (0 ) ;

80 Pro f i l eS t r eam . readLine ( ) ; // F i r s t LinePro f i l eS t r eam . readLine ( ) ; // Second Line

82 xindex=−1;yindex=−1;

84 whi le ( ! Pro f i l eS t r eam . atEnd ( ) ){

86 ReadLine=Pro f i l eS t r eam . readLine ( ) ;Sp l i t t edData=ReadLine . s p l i t ( " \ t " ) ;

88 y=Spl i t tedData . at (0 ) . t o In t ( ) ;x=Spl i t tedData . at (1 ) . t o In t ( ) ;

90 z=Spl i t tedData . at (2 ) . t o In t ( ) ;i f ( y!= yold )

91

Page 100: Thesis Report

Iman AMIRTAHERI: Design RS485 Interface & DOT Code Scanner Software

92 {yindex++;

94 xindex=−1;yold=y ;

96 }xindex++;

98 i n t ScaledValue =((z−zmin ) ∗ 254/(zmax−zmin ) ) +1;Pro f i l eMat . at<uchar >(yindex , xindex )= ScaledValue ;

100 }//Check i f i t has zero va lue s

102 f o r ( yindex =1; yindex<Prof i l eMat . rows ; yindex++)f o r ( xindex =0; xindex<Prof i l eMat . c o l s ; xindex++)

104 i f ( Pro f i l eMat . at<uchar >(yindex , xindex )==0){

106 Prof i l eMat . at<uchar >(yindex , xindex )= Prof i l eMat . at<uchar >(yindex −1, xindex ) ;

}108 f o r ( yindex=Prof i l eMat . rows −2; yindex >=0;yindex −−)

f o r ( xindex=Prof i l eMat . co l s −1; xindex >=0;xindex −−)110 i f ( Pro f i l eMat . at<uchar >(yindex , xindex )==0)

{112 Prof i l eMat . at<uchar >(yindex , xindex )= Prof i l eMat . at<uchar >(

yindex +1, xindex ) ;}

114 emit SendCurrentOperation ( " P r o f i l e Data Loaded " ) ;ShowImage ( ) ;

116 }

118 void P r o f i l e P r o c e s s o r : : ShowImage ( ){

120 QThread : : msleep (200) ;s t a t i c QVector<QRgb> sColorTable ;

122

// only c r e a t e our c o l o r t a b l e once124 i f ( sColorTable . isEmpty ( ) )

{126 f o r ( i n t i = 0 ; i < 256 ; ++i )

sColorTable . push_back ( qRgb( i , i , i ) ) ;128 }

130 QImage ImageQImage ( Pro f i l eMat . data , Pro f i l eMat . co l s , Pro f i l eMat . rows ,Pro f i l eMat . step , QImage : : Format_Indexed8 ) ;ImageQImage . setColorTable ( sColorTable ) ;

132

QPixmap ImageQPixmap = QPixmap : : fromImage ( ImageQImage ) ;134 emit SendImage ( ImageQPixmap) ;

}136

void P r o f i l e P r o c e s s o r : : Cor rec tOr i enta t i on ( )138 {

//Check i f i t i s nece s sa ry to r o t a t e the image140 i f ( Pro f i l eMat . co l s <Prof i l eMat . rows )

t ranspose ( Prof i leMat , Pro f i l eMat ) ;142 emit SendCurrentOperation ( " Or i entat i on Corrected " ) ;

92

Page 101: Thesis Report

F – Profile Processor C++ Code

ShowImage ( ) ;144 }

146 void P r o f i l e P r o c e s s o r : : Inver tCo lo r ( ){

148 bitwise_not ( Prof i leMat , Pro f i l eMat ) ;emit SendCurrentOperation ( " Colors Inver ted " ) ;

150 ShowImage ( ) ;}

152

154

void P r o f i l e P r o c e s s o r : : SharpenEdges ( )156 {

158 GaussianBlur ( Prof i leMat , ProfileMatAux , S i z e (0 , 0) , 3) ;addWeighted ( Prof i leMat , 1 . 5 , ProfileMatAux , −0.5 , 0 , ProfileMatAux ) ;

160 Prof i l eMat=ProfileMatAux ;emit SendCurrentOperation ( " Edges Sharpened " ) ;

162 ShowImage ( ) ;}

93