Adaptive Hough Transform Circle Detection Application in Developed 2D Coordinate Measuring System

This paper describes a cheap, portable coordinate system for measuring circular geometries. The developed soft - ware can measure diameters, circle center coordinates, and distances between them. The circle detector uses the Adaptive Hough Transform implemented in the OpenCV library. For image rectification, the system uses reference circle positions on the plane parallel to the plane of the measured ones. Pixel size is determined by the distances between the reference circle positions on the same plane. The mean measurement value from a series of photos was found efficient estimation of accurate value, significantly improving overall system accuracy.


INTRODUCTION
Optical measurement systems efficiently measure flat geometries, but solutions available on the market are expensive, complex, and often stationary.Some systems detect contour using illumination from below [1], which makes them inappropriate for measuring features on the surface.There are systems used for deflection [2] or displacement measurement detecting changes in dimension but not geometry characteristics in a coordinate system.Some papers describe systems designated strictly to one task, like measuring spur gear [3] or O-ring [4].Most portable solutions, like scanners, create a digital representation of the 3D object rather than measure geometric features in a defined coordinate system.Many expensive industrial optical coordinate measuring systems exist, but it is possible to build a cheap, simple, portable measurement system using computer vision algorithms and commonly available cameras, and this paper describes such one.Existing visual inspection systems offer extensive capabilities but cost about 100 times more than the parts of the developed system.Adaptive Hough Transform [5] is a modification of Hough Circles Transform.It is a method for detecting circles, which was described [6], implemented [7], and applied [8].In metrological applications, its main drawback is that it can produce relatively different results for images of the same object in almost the same conditions (visible in (a) chart in Figure 6).Resolving variation issues is the main subject of the paper.

SOFTWARE AND HARDWARE SETUP
Images are taken with the ArduCam OV5647 camera with a 5 Mpx CMOS 1/2.5"sensor and LS-2718 4 mm objective.The camera is connected to Raspberry Pi 4. The appropriate lighting conditions are provided by the LED lamp Newell Air 1100.Enlisted elements are pictured in Figure 1

CIRCLE DETECTION
Before detection, the image is converted to grayscale and blurred with Gaussian blur with kernel size k = 7 and standard deviation σ = 1.5 -both parameters identical in the x and y directions.Circle detection is performed with Adaptive Hough Transform implemented in the HoughCircles function in the HOUGH_GRA-DIENT_ALT mode.Inverse ratio of accumulator resolution dp = 1, and param1 = 300 and param2 = 0.9.

IMAGE PREPARATION
The measurement system needs a set of 100 photos to achieve the expected accuracy, but it will work the same way for a set consisting of only one image.The image preparation process consists of the following stages: • distortion correction; • reference circles detection in the undistorted images; • averaging coordinates of detected circle centers; • alignment of the image with reference circles used for pixel size determination and measurand; • detection of reference circles used for pixel size computation in the aligned image; • pixel size computation.
Due to visible distortions of LS-2718 4 mm objective, camera calibration was performed.OpenCV 9x6 chessboard pattern [9] UV printed on aluminum/polyethylene composite board was used.Based on the determined camera matrix and distortions vector, corrections are applied for every image (first operation in Figure 2) prepared by the system.In undistorted images, reference circles with pre-calibrated relative center positions on the board are detected for every image (second operation in Figure 2).In this example, geometries used to determine a transformation matrix and measured ones are on the same board.In real applications, measured ones can be parallel to the reference plane and at different distances from the camera.The final detected circle center coordinates are the mean coordinates from all images.Mean detected coordinates and these measured on the reference measurement system are used to determine the perspective transformation matrix with the findHomography function [10].The obtained matrix is passed to the warpPerspective function [11] along with the image, and the perspective is removed (the board image is parallel to the image plane) (Figure 3).Change can be barely visible but has a significant impact on measurement accuracy.For the perspective change visible in Figure 3, omitting perspective removal increases the x-coordinate absolute maximum error from less than 0.15 mm to 1 mm.The pixel square side is a ratio of calibrated distances on the measurement plane and these in image pixels (in Figure 4, distances between reference circle centers).Final pixel size is a mean of pixel sizes for all images.

MEASUREMENT PROCESS AND ACCURACY ASSESSMENT
The measurement consists of about 100 photos of the measured circles placed on the same plane as the reference circles defining pixel size.The final measurement results are averaged from the whole series.The measurement consists of the following stages: • circle detection; • scaling according to the pixel size; • the centers coordinates rotation and translation according to the local coordinate system.
In Figure 5, all checked characteristics have been drawn.The local coordinate system is defined according to Table 1.Numbers in rectangular fields are identifiers of the circles.The following features were measured: • circle center x position -measured relative to the origin; • circle center y position -measured relative to the origin; • distance between circle centers -measured between centers of neighboring circles; • diameters of circles.
On the board presented in Figure 5, there are 15 inner circles resulting in 15 x-coordinates, 15 y-coordinates, 15 diameters, and 38 distances (12 horizontally, 10 vertically, 16 diagonally).After comparing results with those obtained on the reference measurement system, errors were computed and their statistics were listed in Table 2. Figure 6a shows the maximum absolute errors for single image measurement, and Figure 6b for measurement results averaged from the current and previous ones.
In Figure 6a the maximum absolute errors for each dimension type are dispersed around one value level.It is especially visible for diameter, which has lower dispersion than circle center positions and distances between, it is discussed in the commentary to Figure 7. Differences in absolute max error distribution between coordinates can be connected with the asymmetry of the pattern and frame.Distance errors depend on coordinate ones.In Figure 6b, the error decreases as the number of samples increases.A significant error reduction often happens for the first 25 samples,   3 and Figure 6 describe the same measurement session.Check for outliers was conducted with Grubb's test.The measurement system does not use a point sampling method, so the International Standard ISO 10360-7 Geometrical product specifications (GPS) -Acceptance and reverification tests for coordinate measuring machines (CMM) -Part 7: CMMs equipped with imaging probing systems [12] is not appropriate for its accuracy assessment, and a maximum absolute error is used as a measure of accuracy.Accuracy assessment consists of 10 measurements of features marked in Figure 5 in different board positions.Conditions are as follows: • The image of the board fills an entire frame.
• Measured circles are on the same plane as reference circles used for pixel size determination.• The rotation of the board around the optical axis of the camera is smaller than 10°, and the rotations around axes perpendicular to this axis are lower than 5°.• The aperture stop, exposure time, and signal gain of the sensor are adjusted so that the contours of the measured feature are visible to the human eye.
and subsequent images have a lesser effect on reducing the error (Table 3).However, using a series of about 100 images improves the repeatability of maximum error between different measurement sessions (Table 4).An average of more than 100 images often does not reduce error (Table 5), so there is no purpose in using more photos.
Capturing 100 images takes about 45 s, including 0.1 seconds delay between consecutive photos.

Origin
The center of the circle with identifier 0 in Figure 4 X-axis rotation The vector from the center of the circle with identifier 0 to the center of the circle with identifier 4 in Figure 4 Table The system checks if the measurand's plane rotation meets the above requirement during perspective transformation matrix determination and displays a warning for improper position or rotation.Pattern pose estimation uses the camera intrinsics parameters obtained from calibration and reference circles data.In Figure 7, charts (a) (c) (e) (g) (left column) show the distribution of measurement errors without results averaging.Many outliers are visible, and variance is extensive.Charts (b) (d) (f) (h) (right column) represents results with averaging applied.The orange lines in Figure 7 are medians.Coordinates x and y of the circle center 0 and coordinate y of the circle center 4 define the local coordinate system (Table 1), so their position error is always equal to zero, which can be seen in Figure 7a and Figure 7b.According to Figure 7, averaging reduces the maximum absolute error for characteristics based on the circle center but has a lower impact on diameter measurement.This is due to the difference in circle center and diameter detection.The    Based on the error distribution in the right column of Figure 7, it is possible to reduce maximum measurement error by adding a correction to the results.For example, charts (g) and (h) show that adding 0.04 mm can reduce the maximum absolute error for diameter to ±0.02 mm.However, the distribution of errors can be different for circles with different sizes or border structures.According to the results presented in Figure 7, the maximum error is about 0.15 mm for the described setup assuming the conditions enlisted earlier are met.

CONCLUSIONS
Computing a mean value from a series provides significant maximum absolute error reduction.The most impactful improvement frequently occurs for the first 25 samples, but the most consistent result is for 100 -the level of reduction is more even among dimension types (Table 3).The maximum absolute error for ten measurement sessions of selected characteristics in the same plane as reference geometries is below 0.15 mm.Results correction can be performed based on the distribution of maximum absolute error for the mentioned characteristics.The mean value from a series of measurements effectively estimates the accurate value, but it depends on the error distribution similarity to the Gaussian distribution.Causes of error with other dispersal, like optical defects, should be reduced to improve measurement accuracy.
A greater focal length of the objective can reduce pixel size estimation error due to perspective shortening.Lower optical defects (especially distortion), higher optical resolution, and reduction of lens area used by a sensor can reduce measurement error.A camera with a higher effective resolution, lower electronic noise, and a monochrome sensor (instead of one with a Bayer color filter) also should be beneficial.Providing more uniform lighting conditions can improve the repeatability of image capture.The described system uses the Adaptive Hough Transform algorithm to measure only circles, but the image preparation process can work with other algorithms and geometries.
. The measurement system software is developed in Python 3.11.3 and uses algorithms implemented in OpenCV 4.8.0.The reference board with circles is made of soda lime glass to which the printed foil is attached and has dimensions 270 x 200 mm.Reference measurement (calibration of the board) was made on the Zeiss O'Inspect 442 at the Laboratory of Coordinate Metrology at Cracow University of Technology according to an accredited procedure using a multiple measurements strategy.The maximum permissible error of this instrument is MPE = 1.7 + 4 • (L/1000) µm, where L is the measured distance in mm.

Figure 1 .
Figure 1.Prototype of the developed measurement system

Figure 2 .Figure 3 .
Figure 2.An obtaining of points for perspective transformation matrix determination

Figure 6 .
Figure 6.Averaging impact on absolute maximum error

Table 1 .
Local coordinate system definition 2. Statistics of sample measurement

Table 3 .
Comparison of absolute maximum error reduction with average over 25 and 100 results

Table 4 .
Comparison of standard deviation reduction for 25 and 150 results

Table 5 .
Comparison of absolute maximum error reduction with average over 100 and 150 results Absolute error distributions for different feature types without and with averaging resolution of circle center position detection is limited by the size of the pixel, but the radius is determined with sub-pixel accuracy.