A method for identifying the number of floors of traditional residential buildings based on deep neural network
Through a deep neural network-based method, the yolov8x model is used to identify the layers of traditional residential buildings, which solves the problems of low accuracy in traditional residential building identification and complex data collection, achieving fast and accurate layer identification and improving data collection efficiency.
Patent Information
- Application Number
- CN202410221956.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-28
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2044-02-28
AI Technical Summary
There is a lack of image data sets and recognition methods for traditional residential buildings in the existing technology, resulting in low accuracy in identifying the number of floors of traditional residential buildings. Moreover, the existing methods are complex and require a large amount of calculation work. The importance of the number of floors to architectural research is not fully realized. sex.
Using a method based on deep neural networks, the yolov8x pre-training model is used to train the traditional residential building recognition model. Through image collection, format processing, training set production, model training and recognition result processing, the relative height of the building's front facade wall and door is calculated. Ratio to estimate the number of building floors.
It achieves rapid and accurate identification of the layers of traditional residential buildings, simplifies data collection, reduces labor and material costs, and improves identification accuracy and comprehensiveness.
Smart Images

Figure CN117975160B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image-based building detection technology, and specifically designs a method for identifying the number of floors of traditional residential buildings based on a deep neural network. Background Art
[0002] my country's traditional residential buildings are characterized by wide distribution and multiple types. They embody distinct national and regional characteristics, and are rich in historical and cultural connotations as well as significant practical and artistic value. The number of building floors is an important morphological feature of traditional residential buildings, which directly affects the structure, performance and function of the building. At present, the collection of architectural data related to traditional residential buildings in my country is mainly obtained through manual field surveys. This process requires a great deal of manpower, financial resources, time and energy, which makes the collection of relevant information on traditional residential buildings complicated and difficult, and is not conducive to efficient statistical analysis of the architectural characteristics of traditional residential buildings, which in turn affects the protection and development of traditional residential buildings. The main problems with the current identification of the number of floors of traditional residential buildings are:
[0003] (1) No requirements for traditional residential building datasets have been proposed. The current building recognition datasets are mainly modern buildings. There is no image dataset for traditional residential buildings. There is a lack of consideration of the characteristics of traditional residential buildings, which leads to low accuracy in traditional residential building recognition.
[0004] (2) The existing recognition technology requires complex conditions and huge computational workload. The recognition content mainly revolves around the building height. It is required that the image must have the building shadow characteristics, and then the shadow length and illumination angle of the remote sensing image are measured. The number of building floors cannot be directly obtained.
[0005] (3) Existing research is not comprehensive enough and does not recognize the importance of the number of floors to the study of traditional residential architecture: Current research in the field of traditional residential architecture mainly focuses on aspects such as building form, building function and building distribution, but does not recognize the importance of the number of floors to building functions and forms. As a result, there is a lack of exploration of methods for obtaining floor number data. There is still room for research on construction science and technology from the perspective of the number of floors of traditional residential buildings. Summary of the invention
[0006] The purpose of the present invention is to solve the above-mentioned defects in the prior art and provide a method for identifying the number of floors of traditional residential buildings based on a deep neural network. The method is based on the traditional residential building recognition model optimized by the yolov8x pre-training model training. After obtaining the recognition result, the obtained recognition mask pixel coordinate file is processed and calculated to obtain the number of floors. The method can be used for the rapid identification of the number of floors of the front facade image of the traditional residential building, and the recognition result data can be used for the census and collection of relevant parameters of traditional residential buildings.
[0007] The purpose of the present invention can be achieved by adopting the following technical solutions:
[0008] A method for identifying the number of floors of traditional residential buildings based on a deep neural network, the positioning method comprises the following steps:
[0009] S1. Image collection: Using the front and side images of historical buildings published on the Internet as the basic image source, we collect images of target traditional dwellings;
[0010] S2. Image format processing: Convert the collected image format into .jpg format to form a collection of collected images J
[0011] S3. Create a training set and a validation set: In the collected image set J, select and annotate images that completely display the front facade wall of a traditional residential building and the door on the same side, annotate the front facade shape as WALL, and annotate the door shape as DOOR, to form a training set T and a validation set Y, and save the generated json annotation file;
[0012] S4. Training recognition model: Use the training set T produced in the previous step to train on the basis of the yolov8x pre-trained model, and verify on the verification set Y to obtain the traditional residential building facade wall and door recognition model wall_door_best.pt;
[0013] S5. Recognition of the front facade wall and door of traditional residential buildings: Input the image to be recognized, recorded as the image set to be recognized U, and input it into the model wall_door_best.pt for recognition. Suppose that after the i-th image in the image set to be recognized U is recognized, the corresponding mask pixel coordinate file P of the front facade wall and door recognition of traditional residential buildings is obtained. i ;
[0014] S6, recognition result pixel coordinate processing: pixel coordinate set P i Read as a list, perform judgment and classification storage, and obtain the pixel coordinate list W of the recognition mask of the building facade wall i AND gate identifies mask pixel coordinate list D i ;
[0015] S7, building facade wall recognition mask contour drawing: from list W i Extract the recognition mask pixel coordinate points of the front facade wall of the traditional residential building, and draw the recognition mask polygon contour line of the front facade wall of the traditional residential building according to the pixel coordinate points, and record the contour line as α;
[0016] S8. Extract the pixel coordinates of the highest point of the gate recognition mask: from list D i Extract the pixel coordinates of the traditional residential building door recognition mask point in the pixel coordinate system and find the minimum value y on the y axis a The corresponding pixel coordinate point di (x a ,y a ), and determine the pixel coordinate point d i The x-axis pixel in the pixel coordinate x a Whether it is within the range of pixel coordinate x of the recognition mask of the building's front facade wall, the highest point of the final target door recognition mask is obtained through analysis value;
[0017] S9. Generate pixel coordinates of intersection points of the mask contour line and vertical line for the front facade wall of traditional residential buildings: Draw x=x in the pixel coordinate system of the recognition image. a A vertical line perpendicular to the x-axis is denoted as β. This line intersects with the contour line α to form multiple intersection points. The set of pixel coordinate values on the y-axis of the generated intersection points is denoted as R. i ;
[0018] S10. Calculation of the relative height between the front wall and the door: The relative height of the wall is the vertical distance from the ground to the cornice wall of the building front facade in the image. It can be obtained by calculating the difference between the y-axis pixel coordinates of the highest point and the lowest point at the intersection of the contour line α and the vertical line β, that is, the set R i The maximum value y c With the minimum value y b The relative height of the wall is h wall The relative height of the door is the vertical distance from the ground to the door eaves on the front facade of the building in the image. It can be obtained by calculating the difference between the y-axis pixel coordinate value of the lowest point in the intersection of the contour line α and the vertical line β and the y-axis pixel coordinate value of the highest point of the door element, that is, the set R i The maximum value y c With y a The relative height of the door is h. door ;
[0019] S11. Calculation of the relative height ratio of the front wall to the door: The ratio of the relative height of the front wall to the relative height of the door is Q i , the ratio of the relative height of the front wall to the relative height of the door
[0020] S12. Obtaining the floor value: According to the conversion relationship between the ratio of the relative height of the front wall and the relative height of the door and the floor value, first calculate Q i Round up and record the integer result as E i , extract Q through mathematical formula i The decimal part is denoted as G i , for G i After numerical judgment, the final layer value floor_num is obtained.
[0021] Furthermore, since the calculation of the number of building floors needs to be performed through the relative height values of the walls and doors of traditional residential buildings, the image collected in step S1 is required to clearly and completely display the front facade walls and door elements of the traditional residential buildings, so as to facilitate the preparation of training sets to increase the accuracy of recognition and calculation.
[0022] Furthermore, since the input image in the Labelme annotation tool requires the number of image channels to be three and the bit depth to be 24, and the conventional image in the file suffix .jpg format generally has a depth of 24 and three channels, the image format is uniformly converted to .jpg in step S2 to facilitate batch annotation in the Labelme image annotation tool;
[0023] Furthermore, since there is no public traditional residential building data set for use in the present invention, in order to ensure that the inventive method is applicable to the calculation of the storey height of traditional residential buildings across the country, the present invention widely collects a large number of different types of traditional residential images and produces relevant traditional residential building training sets T and verification sets Y. In step S3, the total number of samples in the training set T is ≥ 600. The marking method of the verification set Y is consistent with that of the training set T, and the total number of samples in the verification set is ≥ 300.
[0024] Furthermore, the traditional residential image in step S3 is annotated by using the Labelme image annotation tool. The storage file paths of the training set T and the validation set Y are read in the Labelme tool, and the front facade walls and doors on the same side of the traditional residential building in the image are annotated with the annotation labels "WALL" and "DOOR" respectively, and the corresponding generated json file is saved.
[0025] Furthermore, the yolov8x pre-trained segmentation model selected in step S4 is a powerful and high-precision object segmentation model open sourced by Ultralytics on January 10, 2023. The network structure of the yolov8 model includes 3 sequentially connected input ends, Backbone backbone network, Neck network and Head output end. The process of inputting the training set T, the verification set Y and the image set U to be identified into the yolov8 network model for model training is as follows:
[0026] (1) Image preprocessing: The labeled dataset is sent to the input of the model, which preprocesses the images in the training set. The preprocessing includes mosaic data enhancement and adaptive anchor box calculation.
[0027] (2) Feature extraction: The preprocessed image enters the Backbone network, including the BottleneckCSP module and the Focus module, and three feature maps of different sizes are obtained after one convolution;
[0028] (3) Feature fusion: The three feature maps of different sizes obtained in the previous step are input into the Neck network for feature fusion. The features extracted by the feature extraction module are used by FPN+PAN to enable the model to obtain feature maps of three scales.
[0029] (4) Prediction output: The feature map obtained in the previous step is input into the Head output terminal to obtain the position, category and confidence of the prediction box. In the training phase, the prediction box is matched with the real box to obtain positive and negative samples, and then the weight parameters are adjusted by calculating the loss function. In the verification phase, the prediction box is screened by weighted non-maximum suppression, and the model parameters are continuously optimized by calculating the accuracy and average precision.
[0030] Furthermore, the training process of the transfer learning model for training and obtaining the model wall_door_best.pt in step S4 is as follows:
[0031] (1) Custom configuration file: Customize the coco8-seg.yaml dataset configuration file, modify the dataset root directory path, the training set image path train, the validation set image path val, and the test set image path test, and rename the file to coco8-seg for floors.yaml.
[0032] (2) Adjust the training model parameters: Import the custom file coco8-seg for floors.yaml, load the yolov8x pre-trained model, set the number of training iterations to 300, and start training.
[0033] (3) Model acquisition: During the training process, the result data of the validation set Y is observed in real time. After the training is completed, the optimal model wall_door_best.pt is saved. The optimal model is shown in the following figure. Figure 2 shown.
[0034] Furthermore, in step S5, there is a recognition result pixel coordinate system, which is established with the upper left corner of the result image as the origin, the right as the positive direction of the x-axis, and the downward as the positive direction of the y-axis, such as Figure 3 As shown, it is recorded as pixel coordinate system F, pixel coordinate file P i The data is based on the pixel coordinate system F and is the pixel coordinate value of the front facade wall and door recognition mask of the traditional residential building;
[0035] Furthermore, in step S5, the images in the image set U to be identified are input into the model wall_door_best.pt for calculation, wherein the image set U to be identified is an image set formed by selecting images of only one building and clearly and completely showing the front facade wall and door elements of traditional residential buildings. The recognition result is as follows: Figure 4As shown; set the confidence threshold conf-thres to 0.80, the intersection-union ratio iou-thres to 0.6, and save the classification results and confidence scores, specifically:
[0036] Assume that the i-th image corresponds to the recognition result, which includes the following contents:
[0037] The pixel coordinate file of the front wall and door recognition mask of traditional residential buildings is in txt format. This file is established based on the pixel coordinate system F and is recorded as pixel coordinate file P i , where the pixel coordinate file P i There are two categories in it: the first digit 0 corresponds to wall, that is, the pixel coordinates of the mask corresponding to the wall recognition of the building facade; the first digit 1 corresponds to door, that is, the pixel coordinates of the mask corresponding to the door recognition of the building facade;
[0038] Confidence: denoted as conf i , when conf i ≥0.80, the recognition result is considered reliable;
[0039] Furthermore, in step S6, the pixel coordinate file P i The judgment classification storage operation is: through Python, the pixel coordinate file P corresponding to the i-th image is i The content is read as a list, where the list contains k i Segment data, k i ≥2;
[0040] Judge each segment of data:
[0041] If the first digit of the segment is 0, it is the pixel coordinate point data of the building facade wall recognition mask. The first digit "0" is removed, and the remaining pixel coordinate data are paired into groups, and each group is separated by a comma and stored in the building facade wall recognition mask pixel coordinate list corresponding to the i-th image, which is recorded as list W i ;
[0042] If the first digit of the segment is 1, it is the recognition mask pixel coordinate point data of the building front facade door. The first digit "1" is removed, and the remaining pixel coordinate data are paired into groups, and each group is separated by a comma and stored in the building front facade door recognition mask pixel coordinate list corresponding to the i-th image, which is recorded as list D i ;
[0043] Among them, list W i With D i The form is (x1,y1 x2,y2 x3,y3......x n ,y n );
[0044] Furthermore, since the data stored in the pixel coordinate list Wi is a coordinate point, there is a possibility that the coordinate point cannot intersect with the vertical line β corresponding to the pixel coordinate x value of the highest point of the door recognition mask established in the subsequent step, and the vertical wall relative height value cannot be accurately calculated, so it is necessary to construct a corresponding contour line. The specific steps of drawing the recognition mask contour line in step S7 are as follows: Read the list W i The pixel coordinate data in the image is connected with line segments in sequence, and the ends are closed to draw the identification mask polygon contour line of the front facade wall of the traditional residential building, such as Figure 5 As shown, the contour line is denoted as α.
[0045] Furthermore, in step S8, the highest point of the gate recognition mask is extracted based on the pixel coordinate system F, such as Figure 6 As shown, in the pixel coordinate system F, downward is the positive direction of the y-axis, so the pixel coordinate of the highest point of the gate recognition mask in the image is The value corresponds to the minimum value y of the pixel coordinate of the gate recognition mask pixel point on the y-axis in the pixel coordinate system F. a , through y a The value obtains the corresponding pixel coordinate point d i (x a ,y a ), where y a Make a comparative judgment. The specific judgment method is as follows:
[0046] If y a The number of pixel coordinate points corresponding to the value is n (n>1), that is, d1(x1,y a )、d2(x2,y a )...d n (x n ,y a ), then the corresponding coordinate point d i The x coordinate value in y a The average x-coordinate value of the pixel coordinate point corresponding to the value, that is
[0047] If y a If there is one pixel coordinate point corresponding to the y value, extract the a The pixel coordinate point corresponding to the value d i (x a ,y a ).
[0048] Furthermore, in step S8, the pixel coordinate point d is determined i Whether the x-axis position is within the x-axis position range of the pixel coordinates of the building facade wall recognition mask, the specific operation is: iExtract the x-values of the pixel coordinate points of the building facade wall recognition mask and store them in a list, and sort the list in ascending order to generate the x-axis pixel coordinate value set V of the pixel coordinate points of the building facade wall recognition mask i , extract the set V i Maximum x ig With the minimum value x ih , d i Pixel coordinate x a Value and x ig That is x ih For comparison and judgment, the if statement is used in Python to judge the pixel coordinates. The specific judgment method is:
[0049] If x is not satisfied ih <x a <x ig , then point d i (x a ,y a ) does not meet the judgment condition, it proves that the door does not belong to the front facade wall, so the value is discarded;
[0050] If x is satisfied ih <x a <x ig , then point d i (x a ,y a ) satisfies the judgment condition, it is proved that the door belongs to the front facade wall, and step S9 is performed.
[0051] Furthermore, due to the perspective relationship in the image, the wall height and the door height need to be calculated in the same dimension to ensure that the vertical relative length ratio of the two corresponds to the actual situation. Therefore, in step S9, x=x is drawn in the pixel coordinate system F. a A perpendicular line perpendicular to the x-axis is denoted as β. This line intersects α to produce n intersection points, where n ≥ 2, such as Figure 7 As shown, the intersection point is g1(x a ,y w1 ), g2(x a ,y w2 )......g n (x a ,y wn ), extract the pixel coordinate set of the intersection point and convert it into a list, extract the y value in the list, and arrange it in ascending order to generate the y-axis pixel coordinate value set R of the intersection point i .
[0052] Furthermore, since only the relative height values of the wall and the door based on the image pixel coordinates can be obtained in the image, but the mathematical relationship between the relative height values of the wall and the door corresponds to the real height value, the relative height values of the wall and the door are used for mathematical calculation in this method. wall , is the relative height value of the building facade wall in the recognition image, that is, the relative height value from the building facade cornice to the ground, the relative height value of the door h door , is the relative height of the door on the front facade of the building in the image, that is, the relative height from the eaves of the front facade of the building to the ground, h wall With h door The relationship is as Figure 8 As shown;
[0053] h wall By calculating the set R i The maximum value y c With the minimum value y b The specific calculation method is:
[0054] h wall =y c -y b
[0055] h door By calculating the set R i The maximum value y c With y a The specific calculation method is:
[0056] h door =y c -y a .
[0057] Furthermore, since the height of the door is similar to the height of a single-story space, the height of the door can be used in the calculation to estimate the vertical size of the average space per floor of the building. Therefore, the relative height value of the wall and the relative height value of the door are ratioed. The relative height value of the wall h in step S11 is wall The relative height value h of the door door Ratio Q i The calculation method is:
[0058]
[0059] Furthermore, since there is a corresponding mathematical relationship between the ratio of the relative height of the wall to the relative height of the door and the number of floors, based on a large amount of practice and expert opinions, the following conversion relationship between the ratio of the relative height of the front wall to the relative height of the door and the number of floors is determined. In step S12, Q i Round to get an integer result E i , the calculation method is:
[0060] E i =[Q i ]
[0061] Decimal part G i The formula for obtaining is:
[0062] G i =Q i -E i
[0063] For H i Perform numerical judgment and finally obtain the layer value floor_num. The numerical judgment condition is:
[0064] If 0≤G i <0.51495, then floor value floor_num=E i ;
[0065] If 0.51495≤G i <1, then the floor value floor_num=E i +1.
[0066] Compared with the prior art, the present invention has the following advantages and effects:
[0067] (1) The method of the present invention adopts the yolov8 training model. On the one hand, the model training method is simple, the customized configuration file data is easy to use, and the operability is strong; on the other hand, by training the neural network with a large number of samples, it can quickly and accurately identify the front facade walls and doors of traditional residential buildings, avoiding the occurrence of detection errors.
[0068] (2) The training data set of the method of the present invention contains traditional residential building categories across the country, with a large sample size and a wide range of types. The trained model has strong generalization and adaptability and is suitable for different residential types, which improves the accuracy of traditional residential building recognition while improving the comprehensiveness of recognition.
[0069] (3) The method of the present invention uses the relative distance value between pixel coordinates in the image pixel coordinate system to calculate the ratio of the relative height value between the front facade wall and the door of the traditional residential building in the image, thereby estimating the number of building floors in the image. During the process, no field measurement is required, and the number of building floors can be quickly and accurately obtained only through the image, which can simplify the collection of basic data of various types of traditional residential buildings and greatly reduce the cost of manpower and material resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0071] Figure 1 It is a flowchart of the steps of a method for identifying the number of floors of traditional residential buildings based on a deep neural network image recognition algorithm disclosed in the present invention;
[0072] Figure 2 This is a schematic diagram of the optimal model obtained by the present invention after multiple tests;
[0073] Figure 3 It is a schematic diagram of the pixel coordinate system for image recognition in the present invention;
[0074] Figure 4 It is a schematic diagram of the identification result of traditional residential buildings disclosed in the present invention;
[0075] Figure 5 This is a schematic diagram of the polygonal contour line α of the identification mask of the front facade wall of a traditional residential building in the present invention;
[0076] Figure 6 It is a schematic diagram of the highest point of the pixel coordinates of the gate recognition mask in the present invention;
[0077] Figure 7 It is a schematic diagram of the intersection of the polygonal contour line α and the vertical line β of the identification mask of the front facade wall of the traditional residential building in the present invention;
[0078] Figure 8 It is a schematic diagram of the relative height values of the wall and the relative height values of the door in the present invention;
[0079] Fig. 9 It is a schematic diagram of some recognition results in Example 1 of the present invention;
[0080] Fig.10 It is a schematic diagram of some recognition results in Example 2 of the present invention. DETAILED DESCRIPTION
[0081] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0082] Example 1
[0083] Figure 1 This is a flowchart of the steps of a method for identifying the number of floors of traditional residential buildings based on a deep neural network disclosed in the present invention. Figure 1 As shown, a method for identifying the number of floors of traditional residential buildings based on a deep neural network includes the following steps:
[0084] S1. Image collection: Using the front and side images of historical buildings publicly available on the Internet as the basic image source, collect images of target traditional dwellings;
[0085] In the above step S1, images of traditional dwellings across the country that can clearly and completely display the facade walls and door elements of the buildings are downloaded and collected;
[0086] S2, image format processing: converting the collected image format into .jpg format to form a collected image set J;
[0087] In the above step S2, the collected image formats are uniformly converted into .jpg format to facilitate image annotation in Labelme.
[0088] S3. Create a training set and a validation set: In the collected image set J, select and annotate images that completely display the front facade wall of a traditional residential building and the door on the same side, that is, annotate the front facade as WALL and the door as DOOR, to form a training set T and a validation set Y, and save the generated json annotation file;
[0089] In the above step S3, in order to ensure that the calculation of the storey height of traditional residential buildings across the country is applicable to the method of the invention, the training set T and the verification set Y contain a large number of images of traditional residential buildings of different types, of which the number of samples in the training set T is 1350 and the number of samples in the verification set Y is 270.
[0090] S4. Training recognition model: Use the training set T produced in the previous step to train on the basis of the yolov8x pre-trained model, and verify on the verification set Y to obtain the traditional residential building facade wall and door recognition model wall_door_best.pt;
[0091] In this embodiment, the specific process of step S4 is as follows:
[0092] S401 Customized configuration file: In this embodiment, the coco8-seg.yaml dataset configuration file is customized, and the dataset root directory path, training set image path train, validation set image path val, and test set image path test are modified to the corresponding paths in this example, and the file is renamed coco8-seg for floors.yaml.
[0093] S402 adjusts the training model parameters: import the custom file coco8-seg for floors.yaml, load the yolov8x pre-trained model, set the number of training iterations to 300 generations, and start training.
[0094] S403 Model acquisition: The training result data of the validation set has a Precision of 0.954, a Recall of 0.855, a mAP of 0.905, and a mAP50-95 of 0.655. After the training, the optimal model wall_door_best.pt is saved. The Precision value represents the precision, the Recall value represents the recall rate, the mAP value represents the average precision value, and the mAP50-95 value represents the average mAP value at different interaction ratio thresholds.
[0095] S5. Recognition of the front facade walls and doors of traditional residential buildings: In this embodiment, 100 samples of enclosed traditional residential buildings are input, which are recorded as the image set U to be recognized. 1 , input the model wall_door_best.pt for recognition, some recognition results are as follows Fig. 9 As shown, suppose that after the i-th image in the image set U1 to be identified is identified, the corresponding traditional residential building front facade wall and door identification mask pixel coordinate file P is obtained i .
[0096] In the above step S5, the confidence threshold conf-thres is set to 0.80, the intersection-over-union ratio iou-thres is set to 0.6, and the classification result and confidence score are saved, specifically:
[0097] Assume that the i-th image corresponds to the recognition result, which includes the following contents:
[0098] The pixel coordinate file of the front wall and door recognition mask of traditional residential buildings is in txt format. This file is established based on the pixel coordinate system F and is recorded as pixel coordinate file P i , where the pixel coordinate file P i There are two categories in it: the first digit 0 corresponds to wall, that is, the pixel coordinates of the mask corresponding to the wall recognition of the building facade; the first digit 1 corresponds to door, that is, the pixel coordinates of the mask corresponding to the door recognition of the building facade;
[0099] Confidence: denoted as conf i , when conf i ≥0.80, the recognition result is considered reliable;
[0100] S6, recognition result pixel coordinate processing: pixel coordinate set P i Read as a list, perform judgment and classification storage, and obtain the pixel coordinate list W of the recognition mask of the building facade wall i AND gate identifies mask pixel coordinate list D i ;
[0101] In the above step S6, the pixel coordinate file P iThe judgment classification storage operation is: through Python, the pixel coordinate file P corresponding to the i-th image is i The content is read as a list, where the list contains k i Segment data, k i ≥2;
[0102] Judge each segment of data:
[0103] If the first digit of the segment is 0, it is the pixel coordinate point data of the building facade wall recognition mask. The first digit "0" is removed, and the remaining pixel coordinate data are paired into groups, and each group is separated by a comma and stored in the building facade wall recognition mask pixel coordinate list corresponding to the i-th image, which is recorded as list W i ;
[0104] If the first digit of the segment is 1, it is the recognition mask pixel coordinate point data of the building front facade door. The first digit "1" is removed, and the remaining pixel coordinate data are paired into groups, and each group is separated by a comma and stored in the building front facade door recognition mask pixel coordinate list corresponding to the i-th image, which is recorded as list D i ;
[0105] Among them, list W i With D i The form is (x1,y1 x2,y2 x3,y3......x n ,y n );
[0106] S7, building facade wall recognition mask contour drawing: from list W i Extract the recognition mask pixel coordinate points of the front facade wall of the traditional residential building, and draw the recognition mask polygon contour line of the front facade wall of the traditional residential building according to the pixel coordinate points, and record the contour line as α;
[0107] In the above step S7, the list W is read i The pixel coordinate data in is used to connect the pixel coordinate points with line segments in sequence, close the ends, and draw the identification mask polygon contour line of the front facade wall of the traditional residential building. The contour line is recorded as α.
[0108] S8. Extract the pixel coordinates of the highest point of the gate recognition mask: from list D i Extract the pixel coordinates of the traditional residential building door recognition mask point in the pixel coordinate system and find the minimum value y on the y axis a The corresponding pixel coordinate point d i (x a ,y a ), and determine the pixel coordinate point d i The x pixel coordinate in aWhether it is within the interval of the pixel coordinate x of the building facade wall recognition mask;
[0109] In the above step S8, the positive direction of the y-axis is downward in the pixel coordinate system F, so the highest pixel coordinate y value of the gate recognition mask in the image corresponds to the minimum y value y of the pixel coordinate point of the gate recognition mask in the pixel coordinate system F. a , through y a The value obtains the corresponding pixel coordinate point d i (x a ,y a ), where y a Make a comparative judgment. The specific judgment method is as follows:
[0110] If y a The number of pixel coordinate points corresponding to the value is n (n>1), that is, d1(x1,y a )、d2(x2,y a )...d n (x n ,y a ), then the x-coordinate value of the corresponding coordinate point di is the average x-coordinate value of the pixel coordinate points corresponding to the ya value, that is
[0111] If y a If there is one pixel coordinate point corresponding to the y value, extract the a The pixel coordinate point corresponding to the value d i (x a ,y a );
[0112] In the above step S8, the pixel coordinate point d is determined i Whether the x-axis position is within the x-axis position range of the pixel coordinates of the building facade wall recognition mask, the specific operation is: i Extract the x-values of the pixel coordinate points of the building facade wall recognition mask and store them in a list, and sort the list in ascending order to generate the x-axis pixel coordinate value set V of the pixel coordinate points of the building facade wall recognition mask i , extract the set V i Maximum x ig With the minimum value x ih , d i Pixel coordinate x a Value and x ig That is x ih For comparison and judgment, the if statement is used in Python to judge the pixel coordinates. The specific judgment method is:
[0113] If x is not satisfied ih <x a <x ig , then point di (x a ,y a ) does not meet the judgment condition, it proves that the door does not belong to the front facade wall, so the value is discarded;
[0114] If x is satisfied ih <x a <x ig , then point d i (x a ,y a ) satisfies the judgment condition, it is proved that the door belongs to the front facade wall, and the operation of step S9 is performed;
[0115] S9. Generate pixel coordinates of intersection points of the mask contour line and vertical line for the front facade wall of traditional residential buildings: Draw x=x in the pixel coordinate system of the recognition image. a A vertical line perpendicular to the x-axis is denoted as β. This line intersects with the contour line α to form multiple intersection points. The set of pixel coordinate values on the y-axis of the generated intersection points is denoted as R. i ;
[0116] In the above step S9, x=x is drawn in the pixel coordinate system F. a A vertical line perpendicular to the x-axis is denoted as β. This line intersects with the contour line α to produce n intersection points, where n ≥ 2. The intersection point is denoted as g1(x a ,y w1 ), g2(x a ,y w2 )......g n (x a ,y wn ), extract the pixel coordinate set of the intersection point and convert it into a list, extract the y value in the list, and arrange it in ascending order to generate the y-axis pixel coordinate value set R of the intersection point i ;
[0117] S10. Calculation of the relative height between the front wall and the door: The relative height of the wall is the vertical distance from the ground to the cornice wall of the building front facade in the image. It can be obtained by calculating the difference between the y-axis pixel coordinates of the highest point and the lowest point at the intersection of the contour line α and the vertical line β, that is, the set R i The maximum value y c With the minimum value y b The relative height of the wall is h wall The relative height of the door is the vertical distance from the ground to the door eaves on the front facade of the building in the image. It can be obtained by calculating the difference between the y-axis pixel coordinate value of the lowest point in the intersection of the contour line α and the vertical line β and the y-axis pixel coordinate value of the highest point of the door element, that is, the set R i The maximum value y c With y a The relative height of the door is h. door ;
[0118] In the above step S10, the relative height value h of the wall wall , is the relative height value of the building facade wall in the recognition image, that is, the relative height value from the building facade cornice to the ground, the relative height value of the door h i门 , is the relative height of the door on the front facade of the building in the image, that is, the relative height from the eaves of the front facade of the building to the ground;
[0119] h wall By calculating the set R i The maximum value y c With the minimum value y b The specific calculation method is:
[0120] h wall =y c -y b
[0121] h door By calculating the set R i The maximum value y c With y a The specific calculation method is:
[0122] h door =y c -y a
[0123] S11. Calculation of the relative height ratio of the front wall to the door: The ratio of the relative height of the front wall to the relative height of the door is Q i , the ratio of the relative height of the front wall to the relative height of the door
[0124] In the above step S11, the relative height value h of the wall wall The relative height value h of the door door Ratio Q i The calculation method is:
[0125]
[0126] S12. Obtaining the floor value: According to the conversion relationship between the ratio of the relative height of the front wall and the relative height of the door and the floor value, first calculate Q i Round up and record the integer result as E i , extract Q through mathematical formula i The decimal part is denoted as G i , for H i After numerical judgment, the final layer value floor_num is obtained.
[0127] In the above step S12, based on a large amount of practice and expert opinions, the following conversion relationship between the ratio of the relative height value of the front wall and the relative height value of the door and the floor value is determined. In the above step S12, Q i Round to get an integer result E i , the calculation method is:
[0128] E i =[Q i ]
[0129] Decimal part G i The formula for obtaining is:
[0130] G i =Q i -E i
[0131] For H i Perform numerical judgment and finally obtain the layer value floor_num. The numerical judgment condition is:
[0132] If 0≤G i <0.51495, then floor value floor_num=E i ;
[0133] If 0.51495≤G i <1, then the floor value floor_num=E i +1;
[0134] The results of the number of floors of 100 samples of enclosed traditional residential buildings input in this embodiment 1 are shown in Table 1:
[0135] Table 1. Data table of the identification results of the number of floors of traditional enclosed residential buildings (partial)
[0136]
[0137] It can be seen from the result table that the recognition accuracy of the enclosed traditional residential buildings in this embodiment reaches 91%, which proves that the method can accurately identify the number of floors of enclosed traditional residential buildings.
[0138] Example 2
[0139] The method of this embodiment is roughly the same as that of the above-mentioned embodiment 1, and the main difference is that in step S5, 100 samples of courtyard-style traditional residential buildings are input, recorded as the image set to be identified U2, and input into the model wall_door_best.pt for identification. Some identification results are shown in FIG. Fig.10 shown.
[0140] The results of the number of floors of 100 courtyard-style traditional residential building samples input in this embodiment 2 are shown in Table 2:
[0141] Table 2. Data table of the identification results of the number of floors of courtyard-style traditional residential buildings (partial)
[0142]
[0143]
[0144] From the result table, it can be seen that the recognition accuracy of Example 2 for courtyard-style traditional residential buildings reaches 90%, which proves that the method can accurately identify the number of floors of courtyard-style traditional residential buildings.
[0145] The above two embodiments are implementation cases of the present invention for identifying two types of traditional residential buildings, namely enclosures and courtyards. The results of the two embodiments show that the method can more accurately identify the number of floors of traditional residential buildings. However, the implementation method of the present invention is not limited to the two types of traditional residential buildings in the above embodiments. Other types of traditional residential buildings are still applicable to the inventive method. At the same time, any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.
Claims
1. A method for identifying the number of floors of traditional residential buildings based on a deep neural network image recognition algorithm, characterized in that: The following steps are involved: S1. Image collection: Using the front and side images of historical buildings published on the Internet as the basic image source, we collect images of target traditional dwellings; S2, image format processing: converting the collected image format into .jpg format to form a collected image set J; S3. Create a training set and a validation set: In the collected image set J, select and annotate images that completely display the front facade wall of a traditional residential building and the door on the same side, annotate the front facade shape as WALL, and annotate the door shape as DOOR, to form a training set T and a validation set Y, and save the generated json annotation file; S4. Training recognition model: Use the training set T produced in the previous step to train on the basis of the yolov8x pre-trained model, and verify on the verification set Y to obtain the traditional residential building facade wall and door recognition model wall_door_best.pt; S5. Recognition of the front facade wall and door of traditional residential buildings: Input the image to be recognized, recorded as the image set to be recognized U, and input it into the model wall_door_best.pt for recognition. Suppose that after recognizing the i-th image in the image set to be recognized U, the corresponding mask pixel coordinate set P of the front facade wall and door of the traditional residential building is obtained. i ; S6, recognition result pixel coordinate processing: pixel coordinate set P i Read as a list, perform judgment and classification storage, and obtain the pixel coordinate list W of the recognition mask of the building facade wall i AND gate identifies mask pixel coordinate list D i ; S7. Drawing of mask contour lines for building facade wall recognition: From list W i Extract the recognition mask pixel coordinate points of the front facade wall of the traditional residential building, and draw the recognition mask polygon contour line of the front facade wall of the traditional residential building according to the pixel coordinate points, and record the contour line as α; S8. Extract the pixel coordinates of the highest point of the gate recognition mask: from list D i Extract the minimum value y of the pixel coordinate point of the traditional residential building door recognition mask in the pixel coordinate system a The corresponding pixel coordinate point d i (x a ,y a ), and determine the pixel coordinate point d i The x-axis pixel coordinate x a Whether it is within the range of the x-axis pixel coordinates of the building facade wall recognition mask, the highest point of the final target door recognition mask is obtained through analysis value; S9. Generate pixel coordinates of intersection points of the mask contour line and vertical line for the front facade wall of traditional residential buildings: Draw x=x in the pixel coordinate system of the recognition image. a The vertical line perpendicular to the x-axis is denoted as β. The line intersects with α to form multiple intersections. The set of pixel coordinates on the y-axis of the generated intersections is denoted as R. i ; S10. Calculation of the relative height between the front wall and the door: The relative height of the wall is the vertical distance from the ground to the cornice wall of the building front facade in the image. It can be obtained by calculating the difference between the y-axis pixel coordinates of the highest point and the lowest point at the intersection of the contour line α and the vertical line β, that is, the set R i The maximum value y c With the minimum value y b The relative height of the wall is h wall The relative height of the door is the vertical distance from the ground to the door eaves on the front facade of the building in the image. It can be obtained by calculating the difference between the y-axis pixel coordinate value of the lowest point in the intersection of the contour line α and the vertical line β and the y-axis pixel coordinate value of the highest point of the door element, that is, the set R i The maximum value y c With y a The relative height of the door is h. door ; S11. Calculation of the relative height ratio of the front wall to the door: The ratio of the relative height of the front wall to the relative height of the door is Q i , the ratio of the relative height of the front wall to the relative height of the door S12. Obtaining the floor value: According to the conversion relationship between the ratio of the relative height of the front wall and the relative height of the door and the floor value, first calculate Q i Round up and record the integer result as E i , extract Q i The decimal part is denoted as G i , for G i After numerical judgment, the final layer value floor_num is obtained.
2. The method for identifying the number of floors of traditional dwellings according to claim 1, characterized in that: In step S1, the collected target traditional dwelling image is required to clearly and completely display the front facade wall and door elements of the traditional dwelling; In step S2, the collected image format is converted into .jpg so that it can be read by the image annotation tool Labelme in the subsequent step; In step S3, the number of image samples in the training set T is ≥ 600, and the number of image samples in the validation set Y is ≥ 150; The specific operation of labeling in step S3 is: using the Labelme image labeling tool to label the building front facade wall and the door on the same side in the collected image, labeling them as "WALL" and "DOOR" respectively, and generating a json labeling file after labeling and saving it.
3. The method for identifying the number of floors of traditional dwellings according to claim 1, characterized in that: The process of training and obtaining the recognition model wall_door_best.pt in step S4 includes: loading the yolov8x pre-trained model, and the number of training iterations is 300 generations; testing the trained model on the verification set Y to verify the effectiveness of the model, and finally obtaining the traditional residential building facade wall and door recognition model wall_door_best.pt.
4. The method for identifying the number of floors of traditional dwellings according to claim 1, characterized in that: In step S5, the images in the image set U to be identified are input into the model wall_door_best.pt for calculation, wherein the image set U to be identified is an image set formed by selecting images in which only one building appears and which can clearly and completely display the front facade wall and door elements of traditional residential buildings, setting the confidence threshold conf-thres to 0.80, and setting the interaction ratio threshold iou-thres to 0.60, and obtaining the recognition result of each image, specifically: Assume that the i-th image corresponds to the recognition result, which includes the following: Traditional residential building facade wall and door recognition mask pixel coordinate file, format is txt, recorded as pixel coordinate file P i , where the pixel coordinate file P i There are two categories in it: Category 0, corresponding to the label "WALL", is the pixel coordinates of the mask corresponding to the wall recognition of the building facade; Category 1, corresponding to the label "DOOR", is the pixel coordinates of the mask corresponding to the door recognition of the building facade; Confidence: denoted as conf i , when conf i ≥0.80, the recognition result is considered reliable; In step S5, there is a pixel coordinate system of the recognition result image. The pixel coordinate system is established with the upper left corner of the result image as the origin, the right as the positive direction of the x-axis, and the downward as the positive direction of the y-axis, and is recorded as the pixel coordinate system F. The pixel coordinate file P i The data are pixel coordinate values of the front facade wall and door recognition mask of traditional residential buildings stored based on the pixel coordinate system F.
5. The method for identifying the number of floors of traditional dwellings according to claim 1, characterized in that: In step S6, the pixel coordinate file P i The judgment classification storage operation is: through Python, the pixel coordinate file P corresponding to the i-th image is i The content is read as a list, where the list contains k i Segment data, k i ≥2; Judge each row of data: If the first digit of the segment is 0, it is the pixel coordinate point data of the building facade wall recognition mask. The first digit "0" is removed and converted and stored in the building facade wall recognition mask pixel coordinate list corresponding to the i-th image, recorded as list W i ; If the first digit of the segment is 1, it is the recognition mask pixel coordinate point data of the building front facade door. The first digit "1" is removed and converted and stored in the building front facade door recognition mask pixel coordinate list corresponding to the i-th image, recorded as list D i ; Among them, list W i With D i The form is (x1,y1 x2,y2 x3,y3......x n ,y n ); The step S7 specifically includes: reading the list W i The pixel coordinate data in is used to connect the pixel coordinate points with line segments in sequence, closing the ends and drawing the identification mask polygon contour line of the front facade wall of the traditional residential building. The contour line is recorded as α.
6. The method for identifying the number of floors of traditional dwellings according to claim 1, characterized in that: The step S8 is based on the extraction in the pixel coordinate system, and the gate identifies the highest point of the mask. The value is the minimum value of the y-axis of the pixel coordinate point of the door recognition mask on the front facade of the traditional residential building in the pixel coordinate system. a , through y a The value obtains the corresponding pixel coordinate point d i (x a ,y a ), where y a Make a comparative judgment. The specific judgment method is as follows: If y a The number of pixel coordinate points corresponding to the value is n, n>1, that is, d1(x1,y a )、d2(x2,y a )...d n (x n ,y a ), then the x-coordinate value of the corresponding coordinate point di is the average x-coordinate value of the pixel coordinate points corresponding to the ya value, that is If y a If there is one pixel coordinate point corresponding to the y value, extract the a The pixel coordinate point corresponding to the value d i (x a ,y a ); In step S8, the pixel coordinate point d is determined. i Whether the x-axis position is within the x-axis position range of the pixel coordinates of the building facade wall recognition mask, the specific operation is: i Extract the x-values of the pixel coordinate points of the building facade wall recognition mask and store them in a list, and sort the list in ascending order to generate the x-axis pixel coordinate value set V of the pixel coordinate points of the building facade wall recognition mask i , extract the maximum value x ig With the minimum value x ih , d i Pixel coordinate x a Value and x ig That is x ih Make a comparative judgment. The specific judgment method is as follows: If x is not satisfied ih <x a <x ig , then point d i (x a ,y a ) does not meet the judgment condition, then the value is discarded; If x is satisfied ih <x a <x ig , then point d i (x a ,y a ) satisfies the judgment conditions, proceed to step S9.
7. The method for identifying the number of floors of traditional dwellings according to claim 1, characterized in that: The operation of step S9 is specifically as follows: draw x=x in the pixel coordinate system F a A vertical line perpendicular to the x-axis is denoted as β. This line intersects with α to generate n intersection points, where n ≥ 2. The pixel coordinate set of the intersection points is extracted and converted into a list. The y-axis pixel coordinate values of the intersection points are arranged in ascending order to generate the y-axis pixel coordinate value set R of the intersection points. i .
8. The method for identifying the number of floors of traditional dwellings according to claim 1, characterized in that: In step S10, the relative height value h of the wall wall , in order to identify the relative height value of the building facade wall in the image, that is, the relative height value from the ground to the building facade cornice, by calculating the set R i The maximum value y c With the minimum value y b The specific calculation method is: h wall =y c -y b Door relative height h door , is the relative height of the door on the front facade of the building in the image, that is, the vertical distance from the ground to the door eaves on the front facade of the building. i The maximum value y c With y a The specific calculation method is: h door =y c -y a 。 9. The method for identifying the number of floors of traditional dwellings according to claim 8, characterized in that: In step S11, the relative height value h of the wall wall The relative height value h of the door door Ratio Q i The calculation method is:
10. The method for identifying the number of floors of traditional dwellings according to claim 9, characterized in that: In step S12, based on a large number of examples and verification experiences, the following conversion relationship between the ratio of the relative height value of the front wall and the relative height value of the door and the floor value is determined. First, Q i Round to get an integer result E i , the calculation method is: E i =[Q i ] Decimal part G i The formula for obtaining is: G i =Q i -E i For G i Perform numerical judgment and finally obtain the layer value floor_num. The numerical judgment condition is: If 0≤G i <0.51495, then floor value floor_num=E i ; If 0.51495≤G i <1, then the floor value floor_num=E i +1.
