Design and Implementation of Crack Width Detection System Based On Android
Design and Implementation of Crack Width Detection System Based On Android
Abstract—In general, the method of conventional crack intensity, construction acceptance and remediation [1, 2].
width detection based on PC is short of flexibility and The current crack width detection methods mainly include
convenience. A portable system for detecting crack width microscope measurement method, image recognition manual
based on Android was researched and designed. Firstly, it reading or image recognition automatic reading methods [3,
used mobile phone camera to collect the crack image. Then, 4]. Both the microscope measurement method and image
the collected image was processed by utilizing digital image recognition manual reading method required manual visual
processing technique, including preprocessing, filtering by reading, and there was artificial reading error. Although the
utilizing morphological filter and canny edge-detection, and
image recognition automatic reading method avoided the
then extracted the edges of the crack and calculated the width.
artificial reading error, it was mostly designed and
Compared the values of the system detected with the data of
crack width detector, the relative error does not exceed 7%.
implemented based on the personal computer [5, 6], which
The experimental results show that the system can detect the was not flexible and convenient enough to use. Therefore,
edges of the crack accurately and the width of the crack has based on the above shortcomings, this paper proposed an
higher accuracy compared with the standard width of the Android-based crack width detection system, making full
crack, so this system can make the measure more convenient use of image processing technology to achieve the automatic
and improve the efficiency of detection greatly. reading function of crack width detection and meet the
demands of portable crack detection for users.
Keywords—android, width measurement, image processing,
crack, edge detection II. SYSTEM DESIGN
The overall design idea of this system was to capture the
I. INTRODUCTION surface crack image by the mobile phone camera. Then
A large number of cracks inevitably existed on the applied image processing techniques to the crack images,
surfaces of engineering components such as houses, roads including grayscale, image enhancement, image
and bridges due to earthquake, settlement, thermal segmentation and edge extraction, etc. According to the
expansion and contraction, etc. The width of cracks was actual needs of users, the system function designed as in Fig.
often used as an important assessment basis for seismic 1
Crack Width Detection System
The system contained three function menus: crack image mainly included width calculation, waveform display and
acquisition, crack image processing and crack width data saving function, etc.
measurement. The image acquisition function included
camera preview, crack photography, image preservation and III. SYSTEM IMPLEMENTATION
camera closure. Image processing function included gray, The system was mainly divided into three parts to
histogram equalization, median filtering, binarization and implement, which were crack image acquisition, image
edge extraction. The crack width measurement function processing and crack width measurement.
Authorized licensed use limited to: UNIVERSIDAD DE SANTIAGO DE CHILE. Downloaded on April 19,2023 at 22:01:22 UTC from IEEE Xplore. Restrictions apply.
A. Image Acquisition of part B, parameter μA is the average grayness of part A,
This paper mainly realized the four functions of driving parameter μB is the average grayness of part B, parameter μ
mobile phone camera to open preview, take photos, save is the average grayness of the whole image, and parameter
photos and close the camera. σ2 is the interclass variance.
Android has two ways to call the camera [7] usually. One
is to call the system default camera directly through the max{V 2 (t )} max{ p A (t )[ P A (t ) P (t )]2
(1)
Intent, another is used in this paper. That is to instantiate a
SurfaceHolder class which contains a Callback interface.
pB (t )[ P B (t ) P (t )]2}
Three functions of SurfaceCreated, SurfaceChanged and
SurfaceDestoryed are realized by calling the Callback 3) Canny edge detector
interface. Those three functions are called when Surface is After binarization, the crack image turned into a binary
created or changed or destroyed. Then instantiating image. Then the most critical part of edge detection was
SurfaceView class to control Surface through the performed. After comparing the commonly used edge
SurfaceView. GetHolde function. By calling the parameters extraction methods [9, 10], the system adopted the Canny
class in the Camera object to set the camera parameters, and edge detection operator [11, 12], that was proposed by John
the key codes are as follows: Canny in 1986 and had the advantages of good
Camera.Parameters parameters = signal-to-noise ratio, high localization performance, and
mCamera01.getParameters();//create single-edge optimum. The flow chart of the algorithm is as
Camera.Parameters object in Fig.2.
parameters.setPictureFormat(PixelFormat.JPEG);// set Start
photo format to JPEG
Read image
parameters.setJpegQuality(100);// set image quality to
100%˗ Gaussian filtering
parameters.setPreviewSize(320, 240); // preview
Screen Size Gradient calculation :
parameters.setPictureSize(640, 480); // image Amplitude M[i,j] and Direction º[i,j]
resolution
M[i,j]==0?Determine Y
mCamera01.setParameters(parameters);// parameter
the local maximum
return N
B. Image Processing interpolation to find the gradient values
M1 and M2 of two adjacent points in
The crack image processing was divided into five parts. the direction of gradient φ[i,j]
The first four parts were the image pre-processing parts, Not local maximum,
N
including image grayscale, histogram equalization, median the gray value of this
M[i,j]>=M1&M[i,j]>=M2 ? point N [ i, j ] = 0
filtering and binarization, etc. The fifth part was the most
critical part of the system, and this part was used to extract Y
the edge information of cracks. its effectiveness will Local maximum,
the gray value of this point N[i, j]=128
determine the accuracy of the whole algorithm.
Calculation of high and low
1) Pretreatment threshold :TH,TL
In practice, the camera captured color images and the
Y Set N[i,j]=255
color information was irrelevant for crack detection. N[i,j]==128&&M[i,j]>=TH ? As a strong edge
Therefore, it is necessary to gray the collected color images. points
N
The acquired image inevitably contains interference and N [ i, j ] as the center point
noises usually. It is necessary to enhance and filter the Search within its 8-neighborhood
for ( int k=0; k<8; k++)
acquired image. In this system, the histogram equalization
method was used to enhance the image and the median Y Set N[i+k,j+k]=255
N(i+k,j+k)==128 &&
filtering method was used to filter the noises. As a weak
M(i+k,j+k)>=TL ?
edge point
2) Binarization N
After the crack image pre-processing, there was a set N[i+k,j+k]=0
obvious difference between the grayscale of the cracks and As non-edge point
the background. So the crack region can be distinguished Edge Connection
from the background region after binarization. Threshold is End
the key when binarizing image. In this paper, the more Fig. 2. Canny algorithm flow chart
classical and widely used OTSU threshold segmentation
method was chosen [8]. The basic idea was to set a threshold Firstly, the image was read and filtered. The selected
t to divide the gray image into part A and part B. The Gaussian function is as in (2). Secondly, the partial
probability of these two parts were PA(t) and PB(t), the larger derivatives Gx and Gy in the x and y directions of the image
the gray-scale difference between part A and B, the larger were calculated by (3) and (4). And the amplitude M[x,y]
the gray-scale difference between them and the whole image. and the direction θ[x,y] of the gradient were calculated by (5)
T was the best threshold when the difference was maximum, and (6). Then, applying non-maximal suppression to the
as in (1): parameter t was the threshold value, parameter PA(t) gradient to find out the possible edge points in the image. If
is the probability of part A, parameter PB(t) is the probability the gradient amplitude of a pixel in the gradient direction
446
Authorized licensed use limited to: UNIVERSIDAD DE SANTIAGO DE CHILE. Downloaded on April 19,2023 at 22:01:22 UTC from IEEE Xplore. Restrictions apply.
was greater than that of its adjacent two pixels, the point N[i+j*Width]=0; // If the current gradient amplitude is
may be an edge point, otherwise it was not an edge point, 0, it can be inferred that this point is not a local maximum,
and its gray value was set to 0. Finally, it is necessary to run and it is assigned 0
double-threshold detection on all points that may be the
edges. The implementation process was to compare the else……// Interpolation, find two adjacent gradient
points that may be the edges with the previously calculated amplitude M1, M2 in gradient direction (This part of the
high and low thresholds, found out which were the strong procedure is omitted)
edge points and which were the weak edge points, and if((M[i+j*Width]>=M1)&&(M[i+j*Width]>=M2))//
connected them respectively, the Gaussian function as in Judge local maximum
(2)˖
N[i+j*Width]=128;
else
1 x2 y 2
G ( x, y ) exp( ) (2) N[i+j*Width]=0;
2SV 2 2V 2
}
In (2): the σ is the standard deviation, the G(x,y) is the
value of the Gaussian function, the π is 3.14159. thresholding_tracker(threshold1, threshold2); // Dual
threshold tracking detection to determine strong and weak
The partial derivatives in the x and y directions as in (3) edge points}
and (4):
C. crack width measurement
In this system, the left and right edge point method was
Gx | [ f ( x 1, y) f ( x, y) f ( x 1, y 1) f ( x, y 1)] / 2 (3)
used to calculate the crack width. The calculation process
was to scan the crack image after edge extraction line by line,
Gy | [ f ( x, y 1) f ( x, y) f ( x 1, y 1) f ( x 1, y)] / 2 (4) and extract the coordinate points of the left and right
boundary of the crack. According to the distance calculation
equation between two points on the plane, as in (7). For any
In (3)and (4): the GX is the partial derivatives in the x point on the left boundary, (7) was used to traverse all points
directions, the Gy is the partial derivatives in the y directions, on the right boundary, When d takes the minimum value, it
f(x,y) is the x, y parameters of the function. was the crack width value corresponding to the point.
Gradient magnitude and gradient direction as in (5) and
(6):
d ( xr xl ) 2 ( yr yl ) 2
(7)
M [ x, y] G G
2
x
2
y (5)
in (7): (xl,yl) is the coordinate of the left boundary point,
(xr,yr) is the coordinate of the right boundary point, d is the
T [ x, y] tg 1[Gy / Gx ] (6) distance between two points.
IV. EXPERIMENTAL RESULTS AND ANALYSIS
The edge detection function is EdgeDetector() and its The experimental environment of this system was a
core code is as follows: model of smartphone with Qualcomm Snapdragon 870 CPU,
public class EdgeDetector { 4GB RAM, Android 6.0 system, 12 million camera with
autofocus support and 1920x1080 pixels resolution. The
setWidGaussianKernel(15); application was installed on the mobile phone to run the
// Set the Gaussian kernel size system. The experimental results as in Fig. 3 and Fig. 4.
float f = 1.0F;
canny_core(f, widGaussianKernel);
// Gaussian filtering
……
for(i=0;i<Height;i++)
{ for(j=0;j<Width;j++)
{M[i*Width+j]=(int)(sqrt(P[i*Width+j]*P[i*Width+j] +
Q[i*Width+j]*Q[i*Width+j])+0.5);
// Calculation of gradient amplitude Fig. 3. Image processing results 1
Phy[i*Width+j]=atan2(Q[i*Width+j], P[i*nWidth+j]) ;
// Calculation of gradient direction}}
if (M[i+j*Width]==0)
447
Authorized licensed use limited to: UNIVERSIDAD DE SANTIAGO DE CHILE. Downloaded on April 19,2023 at 22:01:22 UTC from IEEE Xplore. Restrictions apply.
Fig. 4. Image processing results 2
448
Authorized licensed use limited to: UNIVERSIDAD DE SANTIAGO DE CHILE. Downloaded on April 19,2023 at 22:01:22 UTC from IEEE Xplore. Restrictions apply.
[2] G. Yang, J.C. Wu, Y.J. Cai, et al㸬 “A Rapid Width Detection Method [8] Y.Q. Wu, T.L. Meng, and S.H. Wu, “Research progress of image
of House Crack in Earthquake Field,” Technology for Earthquake thresholding method in recent years (1994-2014),” Data Acquisition
Disaster Prevention, vol. 14, no. 1, pp. 220-230, March 2019. and Processing, vol. 30, no. 1, pp. 1-23, January 2015.
[3] T. Gao, “Research on Tunnel Crack Image Acquisition and Detection [9] W.Q. Yuan, and D. Xue, “Review of tunnel lining crack detection
Technology”, Beijing: Beijing Jiao tong University, 2018. algorithm based on machine vision,” Chinese Journal of Scientific
[4] Y.F. Liu, J.S. Fan, J.G. Nie, et al 㸬 “Review and prospect of Instrument, vol. 38, no. 12, pp. 3100-3111, December 2017.
digital-image-based crack detection of structure surface,” China Civil [10] H.B. Wei, S.W. Wu, Q.F. Zhang, et al. “Research on Crack
Engineering Journal, vol. 54, no. 6, pp. 79-98, June 2021. Recognition Algorithm of Asphalt Pavement Based on Image
[5] X.J. Han, and Z.C. Zhao, “Structural surface crack detection method Processing,” Chinese and Foreign Highways, vol. 40, no. 4, pp.
based on computer vision technology,” Journal of Building 73-78, August 2020.
Structures, vol. 39, no. S1, pp. 418-427, September 2018. [11] H.X. Zhang, C. Wang, X. Liu, et al. “Image edge detection algorithm
[6] H.L. Geng, “Width Calculation Based on Computer Vision”, Beijing: and its new development,” Computer Engineering and Applications,
Beijing University of Technology, 2020. vol. 54, no. 14, pp. 11-18, November 2018.
[7] T. Yin, and J.D. Cui, “Research on componentization of software [12] X. Fan, S.W. Fei, Y.B. Chu et al. “Improved Algorithm for Image
development based on Android,” Computer Applications and Edge Extraction Based on Canny Operator,” Automation &
Software, vol. 36, no. 9, pp. 16-20, September 2019. instrumentation, vol. 34, no. 1, pp. 41-44, January 2019.
449
Authorized licensed use limited to: UNIVERSIDAD DE SANTIAGO DE CHILE. Downloaded on April 19,2023 at 22:01:22 UTC from IEEE Xplore. Restrictions apply.