# Orthofacade-Based Assisted Inspection Method for Buildings
## 2 Materials and Methods
### Crack Inspection  
The final AIM phase refers to the crack inspection performed on the generated orthofacade using the methods contained in the OpenCV library. The phase includes the following activities: (i) crack detection, (ii) determination of crack location and (iii) determination of geometrical parameters of crack. The process of _crack detection_ begins with the selection of a repeating rectangular facade element of interest at the generated orthofacade. The selection is made with a simple tool that takes over the coordinates of the corners of the rectangle representing the observed block. It is envisaged that the selection of the observed block is reduced to the upper orthofacade block, while all other blocks are vertically below. After that, based on the orthofacade's raster properties, the offset between the blocks in pixels is calculated and individual blocks are extracted. Each individual block is saved in a separate directory with a name that uniquely addresses the position of the block on the grid, so that in case of a detected crack, it is possible to reconstruct the precise location of the element and cracks. The number of files corresponds to the number of blocks viewed on the selected vertical. This concludes the observation of the facade as a whole and proceeds to the analysis of individual segments. The next step is pixel segmentation in the selected block. Each individual file is accessed and a pixel analysis is performed taking into account a subset of adjacent pixels at the same time, calculating a threshold for that specific local region, and then performing segmentation. The aim is to separate the potential crack from the background, based on the difference in pixel intensity of each region. For the purpose of this action, the following was used: adaptive thresholding with OpenCV (_cv2.adaptiveThreshold_). Thresholding types are:  
1. cv.THRESH_BINARY
2. cv.THRESH_BINARY_INV
3. cv.THRESH_TRUNC
4. cv.THRESH_TOZERO
5. cv.THRESH_TOZERO_INV  
Thresholding types are used according to OpenCV documentation:  
void cv::adaptiveThreshold(cv::InputArray src, cv::OutputArray dst, double maxValue, int adaptiveMethod, int thresholdType, int blockSize, double C)  
The AIM code applies an adaptive threshold to an array. The function transforms a grayscale image into a binary image according to the formula: **THRESH_BINARY**  
The function parameters are:  
src--Source 8-bit single-channel image. dst--Destination image of the same size and the same type as src. maxValue--Non-zero value assigned to the pixels for which the condition is satisfied  
adaptiveMethod--Adaptive thresholding algorithm to use, see #AdaptiveThresholdTypes. The #BORDER_REPLICATE | #BORDER_ISOLATED is used to process boundaries. thresholdType--Thresholding type that must be either #THRESH_BINARY or #THRESH_BINARY_INV, see #ThresholdTypes. blockSize--Size of a pixel neighbourhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on. C--Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well. As a result of this activity, a new set of rasters is obtained that corresponds to the observed blocks. Within each individual raster, the potential crack is separated from the background based on the difference in the pixel intensity of the individual regions. After the rasters were processed in this way, the function was applied in order to facilitate identification:  
int cv::floodFill(cv::InputOutputArray image, cv::Point seedPoint, cv::Scalar newVal, cv::Rect *rect = (cv::Rect *)0, cv::Scalar loDiff = cv::Scalar(), cv::Scalar upDiff = cv::Scalar(), int flags = 4)  
This feature uses and updates the mask and initializes the mask content. Based on OpenCV documentation, functions floodFill fill a connected component starting from the seed point with the specified colour.