Three-dimensional scanning system based on a low-cost infrared sensor

—Nowadays, with the availability of 3D printers, the scanners for objects are becoming increasingly present since they allow to replicate objects by 3D printing, especially for small scale sizes. However, the majority of these technologies are expensive, due to the complexity of this task. Therefore, this work presents a prototype of a low-cost 3D scanning system for small objects using a point cloud to stereolithography approach where it was already validated in simulation in previous work. This concept has a restriction that the objects must have a uniform shape, i.e, without discontinuities. The architecture is composed of two stepper motors, due to their precision, a rotating plate to allow 360 degrees scans and another rotating structure that allows the infrared distance sensor to scan the object from bottom to top (90 degrees). The prototype was validated in the real scenario with good results.


I. INTRODUCTION
The increased demand for realistic 3D models in several areas of society has been increasing in the last few years.The applications areas are numerous, namely the construction industry, medical applications, reverse engineering, design, cultural heritage, entertainment, among others.Each application has its requirements for the scanning system.In this way, each system has its range of operation and accuracy, differing from the shape acquisition technology.In general, they are classified in contact and non-contact, however, there are several sub-classifications inside these two categories [1].The system proposed in this study uses an infrared (IR) distance sensor to acquire the shape of the objects, being this system classified as a non-contact active system that uses triangulation technology.
Each approach has its advantages, disadvantages, and tradeoffs.Two common ones for reflective-optical scanning systems are triangulation and time-of-flight (ToF).According to [2], in triangulation systems, their range and depth variation is limited, but they have greater precision.On the other hand, ToF systems have great range and depth variation with the cost of precision.The triangulation approach works, basically, by projecting a laser over the object and capturing the reflected wave with a digital camera.Knowing the distance between the camera and the scanning system, the distance from the object to the scanning system can be computed with trigonometry [2].On the contrary, in ToF based-systems, their accuracy is mainly governed by the sensor's ability to precisely measure the round-trip time of a pulse of light.In other words, they measure the distance between the sensor and the object by emitting a pulse of light and measuring the time that the reflected light takes to reach the sensor's detector.There is also another approach to measure the distance between the sensor and the object based on the Phase-Shift Method.Following this reasoning, despite the approach used, by moving the sensor itself or the object, the shape of the latter can be acquired.The trade-off in these types of systems is between the scanning speed and accuracy.By increasing the scanning speed of the system the accuracy will decrease, and vice-versa.This is mitigated by having expensive ranger finders with higher sampling frequencies.Also, accuracy during acquisition can be heavily decreased with light interference, noise in data acquisition, and the angle of incidence of the projected beam being much oblique.In this way, in a very controlled environment, a high-quality sensor and circuit must be used to perform quality scans.The angle of incidence, however, is less controllable since it depends on the scanning system and the object that is going to be scanned.In general, these 3D scanning systems are very expensive, even with the cheaper ones being costly to the regular user.Specially laser-based systems, which even though there are various options, are high-priced [3].However, in this work, the objective is to propose a low-cost 3D scanning system for small objects using an IR distance sensor using a point cloud to stereolithography approach.The proposed system, with the restriction of the objects having no discontinuities, was already validated in simulation [4].
The presented prototype can measure objects that fit inside a cylinder with 8 cm in radius and 10 cm in height.It uses two stepper motors to perform the horizontal and vertical (arc) rotational movements so that a distance measuring sensor unit can measure the distances all around the object.A metal arm supports the sensor.Therefore, this concept can be built on a bigger scale to support industrial automation, even changing the support metal arm with a robotic manipulator, for instance.It is important to take into consideration the sensor's limitations, however, changing if necessary.
The paper is organized as follows: A brief state of the art is described in Section II.The system architecture is presented in Section III, whereas the methodology is presented in Section IV.Then, Section V stresses the model reconstruction, and in Section VI, the results are addressed and discussed.Finally, the conclusion and future works are showed in Section VII.

II. STATE OF THE ART
The 3D scanning appeared during the second half of the 20s where laser triangulation technology was the way to scan 3D objects.This technology was usually reserved for industrial applications, however, this tool has evolved, and currently, there are two main used technologies for 3D scanning objects, structured light technology, and laser triangulation.Nowadays, there are several do it yourself projects available over the internet to perform this task, where most of them use one or more line laser projection and a camera.
As previously mentioned in Section I, 3D scanning systems have a wide area of applications, approaches, and ranges of operation.In this way, the focus of the state of the art will be related to triangulation and ToF scanning systems and their applications.For a more complete review, the reader is referred to [5], [6].
In the context of civil structure detection, the authors from [7], with the intent to overcome the inconveniences of 3D laser scanning (cost, heavy, among others), designed a 3D scanning system that consisted of an elevating platform actuated by a stepper motor and a small 2D laser ranging sensor.The authors stated, based on the obtained results, that the system achieved a higher measurement accuracy with lower cost and stronger environmental adaptability.Besides, a subsystem to create a three-dimensional model of an orthopedic insole, based on 3D laser scanning data, was presented in [8].The authors used an adversarial neural network to model the orthopedic insoles.Also, an automated geometric quality inspection of mechanical, electrical, and plumbing (MEP) modules using 3D laser scanning was proposed in [9].The authors assessed their approach on two MEP modules.Moreover, the authors from [10] presented a technology to measure the 3D deformation of tunnels using 3D laser scanners and a processing algorithm for the point cloud data.They applied their technology to monitor the temporal evolution of the 3D deformation of a deep tunnel.Furthermore, an approach to create 3D models from point clouds of buildings and extract its indoor's navigation networks is presented in [11].The authors tested their approach in several real datasets and compared it with other state-of-the-art approaches.In addition, a new algorithm to correct 3D point cloud data from airborne LiDAR scans of 3D buildings was presented in [12].To verify the quality of the reconstructed objects, the authors used high-quality ground truth models from constructed meshes.Also, the accuracy of surface reconstruction using point clouds is analyzed in [13].The authors tested several methods and compared them using real data for accuracy.They also proposed an efficient method of surface reconstruction which has an accuracy improvement.Furthermore, a 3D scanner with a 1D laser, using the triangulation method, was proposed in [14].The authors designed and implemented the system with the help of LabVIEW.As the purpose of the paper was to demonstrate the principle of 3D scanners and 1D triangulation method, they approached all stages related to the development of the system.First, they presented the theory related to the technology and the applied method, and after, they focused on the implementation of the system (hardware and software).Additionally, authors in [15] proposed a similar system to our approach with some differences, where they show very good results.They used a 1D industrial photoelectric sensor, rated roughly e 340, to acquire the data in contrast of our IR low-cost sensor e 12.5.Additionally, their sensor moved only in Z, not scanning the top part of the objects.Finally, another similar approach was proposed in [16], in which they use two IR distance sensors and two motors to scan the object, its sides, and top parts.One result of a bottle scan was presented, where they plot the 3D image of the object using MATLAB.However, they did not provide any picture of the real system nor any percentage comparison between the real object and the scanned model.Moreover, our approach is cheaper since we use just one sensor and due to the overall architecture being simpler.Also, the 3D scanning system presented in this study is more flexible.
In sum, with the availability of 3D printers, the scanners for 3D objects are becoming increasingly present since they allow the replication of objects by 3D printing, especially for small-scale sizes.But most of the existing scanners perform the acquisition on the objects' lateral, lacking the top part.The proposed architecture allows scanning the side and top sides of the objects with a low-cost IR distance sensor.

III. SYSTEM ARCHITECTURE
The architecture of the global system is illustrated in Figure 1 and the description of each block and its interconnection will be presented throughout this section.The prototype, seen in Figure 2, was developed to validate the simulated concept [4].The experiments resorted to a rotating structure that supports the object to be scanned.This structure is actuated by a stepper motor that precisely rotates it continuously until the end of the cycle, corresponding to 360 degrees.An articulated part whose rotating axis is aligned with the center of the rotating structure, having attached an optical sensor (GP2Y0E02B from Sharp manufacturer) measuring the distance to the object, is also actuated with a stepper motor to rise in steps of 2 degrees (configurable) until the maximum of 90 degrees.The proposed optical sensor was selected since it is a combination of a CMOS image sensor and an IR-LED that are neither influenced by the temperature environment nor the reflectivity of the object.Both stepper motors used on this approach are the well-known NEMA17, controlled by the DRV8825 driver.Moreover, a limit switch sensor was added to be a reference to the position of 0 degrees.Over a cycle, the sensor takes 129 measurements, each one lasting 50 ms.The rotating plate's speed is approximately 55 deg/s (configurable).Then, the articulated part rotates 2 • and another time cycle is performed.The system is controlled by a lowcost microcontroller ESP32, transferring to the PC, by serial or Wi-Fi, the measured distance to the object as well as the angle between the sensor and the ground (0 degrees).According to the received data, the developed application on Lazarus IDE creates an .STL file of the desired object.

IV. METHODOLOGY
The scanning system works basically in two steps.First, the point cloud is generated by scanning the object.After, the model is reconstructed from the point cloud data with a software program that was developed for this system.The model is saved in ASCII and Binary STL files.The system's flowchart can be seen in Figure 3.

A. Scanning system
First, it is important to note that the notation used in this work, to explain the system, is in spherical coordinates, (l, θ, ϕ).The scanning process works by placing the object on the center of the global reference frame which is the rotating plate.
As presented in Figure 4, θ is the inclination's angle measured from the X axis to the Z axis, with range [0, π/2] rad, and ϕ is the signed azimuthal angle measured from X axis, in the XY plane, with range [0, 2π].
The parameter h p represents the distance from the rotating plate to the arm rotation point, and h s is the perpendicular distance from the arm to the sensor.The parameter l defines the length of the mechanical arm and d represents the distance between the sensor to the object's boundary, which is located on the rotating plate.
The position of the sensor s, X s = (x s , y s , z s ), in terms of the parameters (l, θ, ϕ), can be defined as follows.
x s = (l cos(θ) − h s sin(θ)) cos(ϕ) The position X p = (x p , y p , z p ), that defines the boundary of the object in a given moment, is represented by a translation considering ||X s || and d.Thus, it is possible to calculate X p as: where ||X s || = x 2 s + y 2 s + z 2 s , which represents the euclidean norm of (x s , y s , z s ).

B. Scanning procedure
When the scan process starts, the support plate starts rotating at a constant known angular speed.Each time the rotating plate completes a revolution, the system performs a small increment in the sensor's angle.Then, the entire system waits for one second, so that the mechanical parts of the scanner stabilize in the new position, thus avoiding measurement errors.This process repeats itself until θ reaches π 2 radians.This entire behavior can be seen clearly in the flowchart displayed in Figure 5.
After the scan is finished, the point cloud data is saved in a .CSV file and then processed by the reconstruction method that will define the object's boundary in a virtual environment, through a .STL file.

V. MODEL RECONSTRUCTION
This subsystem generates the meshes in three steps, making some assumptions.The first assumption comes from the way the system works, i.e, 2π scans of ϕ for every step of θ.That is, the system makes circular scans assuming that the object is somewhat uniform shape-wise, without discontinuities or holes.Therefore, the scan process works by acquiring n columns of points, within the range of [0, π 2 ] in θ, adjacent to one another.In this reasoning, two triangles are generated for every four points of each pair of adjacent columns, two points per column.In other words, in the same way, a square can be divided into two triangles, two triangles are built with four points of every pair of adjacent columns.This process and the first assumption can be better understood in Figure 6.
The circles represent the data points and the triangles' vertices.The black lines represent the lower left triangles' edges that are generated.In the same reasoning, the orange lines represent the upper right triangles' edges.The green lines are the common edges between every two triangles.
The first assumption becomes clear with the illustration because if the object's shape has discontinuities, i.e, one column has more data points than the other, the generated triangles between the columns become "distorted".This behavior can be seen clearly in Figure 7.In this illustration, it is possible to see that this behavior can happen from either side of each  column pair that is analyzed.The red circles represent the points that are ignored by the software program, as they have not their respective pairs in the adjacent column.Thus, the "distorted" triangles vertices' are the navy blue circles, and its edges are the orange lines.
The second step is to close the bottom gap of the model.This is necessary because this system assumes that the objects have a flat bottom layer, even if it is small (a pencil, for instance).With this second assumption, the system does not need to scan below the object.This approach is done simply by averaging all data points with the lowest Z and generating triangles with the common vertex being the averaged point, and the other two vertices, being pairs of these lowest Z points.This process can be seen clearly if we imagine a cube being scanned.Its projection on the XY plane would be a square and its illustration is displayed in Figure 8.Thus, with this assumption, for objects with a rounded bottom part, this would produce a flat bottom layer.Again, the first assumption still applies, however, now in the XY plane and with much less impact.
The third step is optional, as it depends on the object that is being scanned.Assuming it is an object with a closed top layer, as this system makes circular scans, even if the θ increments are extremely small, a tiny circle will be left out of the scan θ tends to π 2 ).Therefore, when the object has a closed top layer, the approach is the same process as the bottom layer, previously mentioned.That is, average all the data points with the highest Z and then, generate the triangles with the common vertex being the average data point.The other two vertices are taken in pairs of the same highest Z points.This idea is illustrated in Figure 9.
In this figure, the biggest white circle represents the last position of the sensor (when its angle tends to π 2 ).The smaller white circles represent the scanned data points, and the generated triangles' edges are the orange lines.Finally, the smallest navy blue circle represents the averaged data point.As this illustration is just a sketch, few scanned points were drawn for simplicity.In reality, the sensor operates much faster, generating a lot of points, as previously stated in Section III.

VI. RESULTS
The results section will address the performance of the entire system, that is, the scan and the model reconstruction subsystems.First, it was necessary to assess the optical sensor performance to compensate for any error or offset deviation that it might have.Secondly, two objects were scanned using the proposed methodology over the assembled scanner to validate the quality of the scanning system alongside the reconstruction algorithm.
The meshes were visualized in MeshLab, an open-source software for processing 3D triangular meshes [17].

A. Optical sensor's performance
To analyze the reliability of the optical sensor, 256 experiments were made for 16 different distances spaced by 10 mm, from 50 mm to 200 mm.The distances were chosen according to the datasheet of the sensor, which refers that the measuring distance is between 40 and 500 mm.Based on Figure 10, it is possible to notice that the real and measured distances are very similar (just an offset of 12 mm based on the trend-line of the first-order approach).Moreover, the measurement's standard deviation can be seen in Figure 11.The average error is 1.69 mm while the maximum error was 3.21 mm at a distance of 180 mm, a value that is not critical for the considered use case.

B. Objects' Scanning
To validate the system's overall quality, two objects were scanned and their respective STL files were generated.For each case, the dimensions of the real object and its respective STL model were compared.The scans were performed with increments of 2 degrees in θ.Also, the developed application can preview and interact with the point cloud data before generating the STL's models, thus, making it possible to check if something went wrong during the scan process.To render the 3D graphics, an application was developed based on the GLScene library [18].The point cloud preview of both examples, which are going to be analyzed in this section, can be seen in Figure 12.First, a cardboard box was scanned with dimensions of 8.0×7.2×3.2 cm (length, width, and height).The real object can be seen in Figure 13.After the scan, its STL model was generated and can be seen in Figure 14.One can see that the object, despite having some minor deformations due to measurement errors from the sensor, maintained its overall structure.One problem that reflectiveoptical approaches have is that they can perform poorly in edges, as the reflected beam can be misdirected.Also, mainly in this type of scan technology, the problem lies when the angle of the projected beam is too oblique, affecting the measurement from the sensor's receptor (in this case a CMOS image sensor).Therefore, the shape of the object in relation to the sensor's emitter affects heavily the accuracy.A zoomed in top view of the box can be seen in Figure 15.
Two things can be seen from this figure.First, the polygons' rotated pattern, which happens due to the scan's rotated 15: Zoomed-in top view of the cardboard box STL model.Visualized in MeshLab.approach, which is intrinsic of the system.Secondly, the top layer approach for the model reconstruction, which was previously presented in Figure 9, is displayed in the middle of the figure.
The percentage errors in the dimensions between the box and its model can be seen in Table I  One can see that the length dimension was more affected than the others in this example, which is non-indifferent.
The second object that was scanned was a plant cup, with dimensions of 4.10×3.75×4.50cm which are the top radius, bottom radius, and height, respectively.The object is displayed in Figure 16.Its scan was less affected by measurement errors, as the material has a different reflectance and it does not have edges, which can be seen in perspective in Figure 17.
In this case, the third step of the reconstruction program was not applied, as the plant cup is not closed in its upper part.However, the bottom layer of the model displays the approach, presented in Section V, to average all the bottom points and assemble the triangles in pairs with the averaged point being the common vertex between all triangles.This behavior can be better seen in Figure 18.One can note in the illustration above that there were some measurement errors, specifically in the middle-right part of the model.Again, the same sources of errors could have influenced them.Finally, the percentage error comparison between the plant cup and its model can be seen in Table II  From the results displayed in this table, one can conclude that the plant cup was less affected in comparison to the preceding example by the sources of errors explained previously.

VII. CONCLUSIONS AND FUTURE WORK
A scanner for small objects was developed and evaluated in this paper.It uses two stepper motors to allow a distance measuring sensor unit to scan in two degrees of freedom (θ, ϕ).The distance sensor that was used is composed of an integrated combination of a CMOS image and an IR-LED, reducing the influence of the object's reflectance.The proposed approach has the advantage of scanning the object on both lateral and topsides with just one low-cost sensor, which is not so common on the other approaches.The system architecture, with its mechanical components, was assembled and tested using two objects.The objects' respective point clouds were acquired and processed.The developed algorithm to reconstruct the 3D model based on the point clouds was also presented.The results allow us to show and validate that the developed prototype can perform scans of small objects and reconstruct their digital STL models.The measurement errors although non-indifferent were small and acceptable taking into consideration the price of the sensor e 12.5.It is reasonable to assume that with more efficient sensors the system efficiency will increase.For future work, it is planned to add an extra degree of freedom on the distance sensor, by adding a servomotor and perform better error quantification.Thus, it will be able to acquire the same point of the object from different angles, minimizing reflection.

7 :
First assumption of the model reconstruction.Example of the two possibilities.

Fig. 8 :
Fig. 8: Second assumption of the model reconstruction.Hyphotethic XY plane projection of a scanned cube.

Fig. 9 :
Fig. 9: Third step (optional) of the model reconstruction.Approximated top view of the scanned data points when θ tends to π 2 .

Fig. 10 :
Fig. 10: Optical sensor's performance: comparison the real and measured values to offset compensation.

Fig. 12 :
Fig. 12: Point cloud preview in the developed application.Left figure represents the first example and the right figure, the second example.

TABLE I :
Dimensions comparison between the cardboard box and its STL model. .

TABLE II :
Dimensions comparison between the plant cup and its STL model.