House type drawing concave-convex angle determination method and device based on region growing algorithm
The method for determining concave and convex corners in floor plans based on a region growth algorithm solves the problem of automatic segmentation of concave and convex corners in floor plans. It achieves efficient and accurate segmentation of concave and convex corners and calculation of center points, adapts to different user needs, and reduces analysis time and labor costs.
Patent Information
- Application Number
- CN202411586544.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2044-11-08
AI Technical Summary
Existing technologies struggle to accurately and efficiently segment concave and convex corners in floor plans. Traditional methods, relying on manual annotation and simple image processing techniques, cannot meet the demands of large-scale, high-precision applications. Furthermore, conventional geometric discrimination methods are insufficient to handle the diverse representations of complex floor plans.
A method for determining concave and convex corners in floor plans based on a region growing algorithm is adopted. Through steps such as edge smoothing, Hough line detection, maximum inscribed rectangle calculation, convolution kernel processing, and counterclockwise scanning, the method achieves accurate segmentation of concave and convex corners.
It achieves accurate and efficient segmentation of the outlines of most types of floor plans, reduces manual intervention, lowers analysis time costs, adapts to different user needs, and is easy to iterate and combine with deep learning models.
Smart Images

Figure CN119672053B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of image processing, and particularly relates to a house type drawing concave-convex angle determination method and device based on a region growing algorithm. BACKGROUND
[0002] In a house type drawing, the outer contour usually refers to the overall framework structure of a house, including walls, room boundaries, windows, etc., and the inner contour refers to various interiors of the house type drawing, such as bathrooms, bedrooms, kitchens, etc. Although the outer contour and the inner contour in the house type drawing mostly have obvious structural features, different house type drawings bring challenges to the automatic segmentation task due to differences in design styles, differences in image quality of different data sources, and possible noise information (such as annotations, symbols, etc.) in the house type drawing. The traditional house type drawing processing method relies on manual annotation and simple image processing technology, and is difficult to meet the large-scale and high-precision requirements. In recent years, the rapid development of image segmentation models based on deep learning in the field of computer vision provides a more accurate and efficient solution for the automatic segmentation of the outer contour and the inner contour of the house type drawing.
[0003] In a house type drawing, a concave-convex angle refers to a block around the main body of a house that meets the conditions of convexity or concavity, and is usually present at positions such as balconies, corners, and corners. Due to different needs and business scenarios of different enterprises, the demand for concave-convex angle discrimination algorithms will also differ. Conventional angle discrimination methods usually rely on geometric analysis, but in complex house type drawings, simple geometric discrimination may not be sufficient to cope with diversified image manifestations. The present application specially designs a house type drawing concave-convex angle determination method for a certain specific condition, which realizes accurate and rapid segmentation of concave angles and convex angles in the house type drawing. SUMMARY
[0004] The main purpose of the present application is to overcome the shortcomings and deficiencies of the prior art, and to provide a house type drawing concave-convex angle determination method and device based on a region growing algorithm. The present application is based on a region growing algorithm to obtain a house type drawing concave-convex angle that meets the requirements. This method is the first method in this direction that solves real-world needs based on image processing, and can process most types of house type drawing contours to accurately and efficiently segment concave-convex angles.
[0005] In order to achieve the above purpose, the technical scheme adopted by the present application is as follows:
[0006] In a first aspect, the present application provides a house type drawing concave-convex angle determination method based on a region growing algorithm, comprising the following steps:
[0007] (1) Obtain the edge smooth contour mask image, perform Hough line detection on the input rough outer contour mask image, retain the vertical and horizontal lines, retain the line segment part on the contour, remove the extended straight line part, then fill the area surrounded by the straight line, and then perform image processing on the mask image using a specific convolution kernel to remove small burrs in the mask image to obtain the edge smooth reconstruction contour image;
[0008] (2) Calculate the maximum inscribed rectangle of the reconstruction contour image as the initial main body and initial detection area of the house type diagram, and calculate the maximum inscribed rectangle of the reconstruction contour, extract the vertical and horizontal line segments of the reconstruction contour using Hough line detection, and sort the vertical line segments and the horizontal line segments from left to right and from top to bottom, respectively;
[0009] (3) Starting from above the current detection area, scan the detection area in a counterclockwise direction, specifically: find the line segment closest to the detection area in the current direction, calculate the rectangle between the detection area and the closest line segment, i.e. the exploration area, find the rectangle with a pixel value of 255 in the exploration area according to the reconstruction contour, i.e. the discrimination block, if there are multiple discrimination blocks with a pixel value of 255 in the exploration area, sort them in descending order of length, and then perform concave-convex angle discrimination in order; if the length of the discrimination block is greater than or equal to one-third of the side of the minimum circumscribed rectangle corresponding to the direction, all the discrimination blocks are regarded as the main body, the area of the exploration area excluding all the discrimination blocks is regarded as the missing corner and saved, and the detection area and the main body are expanded along the direction to the closest line segment; if the length of the discrimination block is less than one-third of the side of the minimum circumscribed rectangle corresponding to the direction, all the discrimination blocks are regarded as convex corners and saved, and the detection area is expanded along the direction to the closest line segment; finally, stop traversing when there is no closest line segment in the four directions of the detection area;
[0010] (4) By analyzing and utilizing the geometric properties of the rectangle, according to the coordinates of the four vertices of the final main body, an accurate house type diagram main body center point coordinate is finally obtained;
[0011] (5) Generate two binary images with the same size as the reconstruction contour image and all values of 0, draw the convex corner contour and the missing corner contour on the two binary images, design a vertical sensing convolution kernel and a horizontal sensing convolution kernel for the task of merging similar convex corner blocks and missing corner blocks, perform two convolution operations on the two binary images using the custom convolution kernel to merge adjacent blocks, and then extract the blocks in the binary images. Finally, the merged convex corner and missing corner contour information.
[0012] As a preferred technical solution, in step (1), the edge smooth reconstruction contour image is obtained, specifically:
[0013] (1-1) Canny edge detection is performed on the input rough outer contour mask image to obtain a binary image of the contour edge, and Hough line detection is performed on the binary image to obtain r and theta of all straight lines in the contour, where r and theta represent the length and radian of the straight line in polar coordinates, respectively, and the angle of all straight lines is calculated according to the formula Screen out horizontal and vertical straight lines;
[0014] (1-2) The end point coordinates of all horizontal and vertical straight lines are calculated according to r and theta, respectively;
[0015] (1-3) The horizontal straight lines are extracted and sorted in ascending order of the starting point vertical coordinate, and the vertical straight lines are extracted and sorted in ascending order of the starting point horizontal coordinate; the starting point horizontal coordinate and the ending point horizontal coordinate of the horizontal straight lines are limited to between the starting point horizontal coordinates of the first and last vertical straight lines, and the starting point vertical coordinate and the ending point vertical coordinate of the vertical straight lines are limited to between the starting point vertical coordinates of the first and last horizontal straight lines;
[0016] (1-4) Each line segment in the grid, which is cut by all vertical and horizontal straight lines, is determined whether it belongs to the boundary inner line segment, specifically: the two end points and the midpoint of the line segment are determined whether they are within the boundary, if there are non-zero pixel values on the AxB rectangle centered at the two end points, i.e. there are pixels belonging to the contour, the line segment is retained; if there are non-zero pixel values on the rectangle centered at one end point and the midpoint, the line segment is retained; finally, all line segments belonging to the boundary are left;
[0017] (1-5) The retained line segments are drawn on a binary image whose size is equal to the rough contour image and whose value is all 0, i.e. the position of the line segment is assigned a value of 255; the outer contour of the binary image is extracted using the contour detection algorithm of opencv, and the outer contour extracted is drawn on the binary image using the contour filling algorithm of opencv to obtain the reconstructed contour;
[0018] (1-6) The custom convolution operation of opencv is used to eliminate the outwardly extending small burrs to obtain the accurate reconstructed contour, specifically: the vertical noise reduction convolution kernel is used for convolution operation, then binaryzation is performed, and finally the vertical restoration convolution kernel is used for convolution operation; the horizontal noise reduction convolution kernel is used for convolution operation, then binaryzation is performed, and finally the horizontal restoration convolution kernel is used for convolution operation;
[0019] (1-7) The opencv library is used to binaryzation the accurate reconstructed contour, and the pixels with values other than 255 and 0 caused by convolution operation are classified into two categories.
[0020] As a preferred technical solution, in step (2), the maximum inscribed rectangle of the reconstructed contour is calculated, specifically:
[0021] (2-1) Considering that the boundary of the part of the reconstructed contour image is fitted with the contour boundary, which leads to the edge being unable to be recognized, the constant edge expansion method of opencv is used to expand the boundary with pixel value 0;
[0022] (2-2) Based on the opencv method, the edge image of the reconstructed contour is extracted by using the canny edge detection algorithm, and then the straight line of the reconstructed contour is extracted by using the Hough straight line detection;
[0023] (2-3) All vertical line segments and horizontal line segments are traversed to calculate the coordinates of the intersection points, and then it is judged whether there is a pixel point with pixel value 255 in a preset rectangle centered on the intersection point. If there are multiple, the coordinates of the pixel point closest to the intersection point with pixel value 255 are returned;
[0024] (2-4) The areas of the rectangles with all intersection points and contour points as opposite corners are calculated and sorted from large to small. Next, the largest rectangle area is selected as the starting point to judge whether the condition is met. Specifically, the minimum and maximum x values of the current two intersection points are x min and x max , and it is judged whether there is a pixel point with value 0 between x min and x max on the y1 and y2 lines of the reconstructed contour, that is, whether the upper and lower sides of the rectangle formed by the two intersection points are inside the reconstructed contour. If there is a pixel point with value 0, it means that the current rectangle is not the maximum inscribed rectangle. The minimum and maximum y values of the current two intersection points are y min and y max , and it is judged whether there is a pixel point with value 0 between y min and y max on the x1 and x2 lines of the reconstructed contour, that is, whether the left and right sides of the rectangle formed by the two intersection points are inside the reconstructed contour. If there is a pixel point with value 0, it means that the current rectangle is not the maximum inscribed rectangle. If there is no pixel point with value 0 on the four sides of the rectangle, the current rectangle is the maximum inscribed rectangle of the reconstructed contour. If there is a pixel point with value 0 on the four sides of the rectangle, the current rectangle is not the maximum inscribed rectangle of the reconstructed contour. The above operation steps are performed on the next rectangle;
[0025] (2-5) Since the constant edge expansion is used in (2-1), the coordinates of the two intersection points corresponding to the final maximum inscribed rectangle are subtracted by the expanded constant value. The maximum inscribed rectangle is stored as [x1, y1, x2, y2], that is, the coordinate list of the two opposite corners. The maximum inscribed rectangle is used as the initial main body and the initial detection area, and the storage format is the same.
[0026] As a preferred technical scheme, in step (3), the setting conditions of the concave-convex angle discrimination are as follows:
[0027] When the current search direction is upward, if the width of the discrimination block is greater than or equal to one third of the width of the minimum enclosing rectangle of the contour, the discrimination block belongs to the main body part, and the area of the exploration region excluding the discrimination block is a concave angle; if the width of the discrimination block is less than one third of the width of the minimum enclosing rectangle of the contour, the discrimination block is a convex angle.
[0028] When the current search direction is leftward, if the height of the discrimination block is greater than or equal to one third of the height of the minimum enclosing rectangle of the contour, the discrimination block belongs to the main body part, and the area of the exploration region excluding the discrimination block is a concave angle; if the height of the discrimination block is less than one third of the height of the minimum enclosing rectangle of the contour, the discrimination block is a convex angle.
[0029] When the current search direction is downward, if the width of the discrimination block is greater than or equal to one third of the width of the minimum enclosing rectangle of the contour, the discrimination block belongs to the main body part, and the area of the exploration region excluding the discrimination block is a concave angle; if the width of the discrimination block is less than one third of the width of the minimum enclosing rectangle of the contour, the discrimination block is a convex angle.
[0030] When the current search direction is rightward, if the height of the discrimination block is greater than or equal to one third of the height of the minimum enclosing rectangle of the contour, the discrimination block belongs to the main body part, and the area of the exploration region excluding the discrimination block is a concave angle; if the height of the discrimination block is less than one third of the height of the minimum enclosing rectangle of the contour, the discrimination block is a convex angle.
[0031] As a preferred technical solution, in step (3), the detection region is circularly scanned in a counterclockwise direction, specifically:
[0032] (3-1) constructing a direction list, the initial direction being upward, and then sequentially traversing the direction list, that is, sequentially traversing the four sides of the main body in a counterclockwise direction;
[0033] (3-2) finding the line segment closest to the detection region in the current direction, specifically: if the current direction is upward, sequentially traversing the horizontal line segment sequence, when the first line segment in the sequence and the first line segment not in the sequence satisfy the condition that the line segment falls on the upper side of the detection region or below the detection region after being translated downward by a set value, then the current line segment is the closest straight line, and the line segment before the current line segment in the sequence is the closest straight line; if the current direction is leftward, when the first line segment in the sequence and the first line segment not in the sequence satisfy the condition that the line segment falls on the left side of the detection region or to the right of the detection region after being translated rightward by a set value, then the current line segment is the closest straight line, and the line segment before the current line segment in the sequence is the closest straight line; if the current direction is downward, when the first line segment satisfies the condition that the line segment falls below the lower side of the detection region after being translated upward by a set value, then the current line segment is the closest straight line; if the current direction is rightward, when the first line segment satisfies the condition that the line segment falls to the right of the right side of the detection region after being translated rightward by a set value, then the current line segment is the closest straight line.
[0034] (3-3) Then, the rectangle between the current body and the nearest line segment found by the current direction is calculated as the exploration area of this time, and the single or multiple rectangles with pixel value of 255 in the exploration area are obtained by using the pixel-wise XOR method of the opencv library, that is, the discrimination block;
[0035] (3-4) Design several convolution kernels for the burr conditions encountered in the discrimination block of the four orientations, and the convolution kernel shape is the same as that in step (1-6); when the orientation is upward and downward, the vertical denoising convolution kernel is used for convolution operation, then the binaryzation of opencv is used, and finally the vertical restoration convolution kernel is used for convolution operation; when the orientation is left and right, the horizontal denoising convolution kernel is used for convolution operation, then the binaryzation of opencv is used, and finally the horizontal restoration convolution kernel is used for convolution operation;
[0036] (3-5) After obtaining the single or multiple discrimination blocks, the discrimination blocks are sorted first; when the orientation is upward and downward, the discrimination blocks are sorted in descending order according to the width of the discrimination blocks; when the orientation is left and right, the discrimination blocks are sorted in descending order according to the height of the discrimination blocks;
[0037] (3-6) Traverse the sorted discrimination block sequence, when the discrimination block meets the set condition of the concave corner, use the queue method to construct the discrimination block queue, and the remaining area will be left after the first discrimination block is subtracted from the exploration area, then judge which remaining area the following discrimination block belongs to according to the coordinate information, and then subtract the following discrimination block from the corresponding remaining area, until the discrimination block queue is empty, the remaining area is the missing corner, and the body and the detection area are extended to the position of the nearest line segment along the current direction; when the discrimination block meets the set condition of the convex corner, all the discrimination blocks are the convex corner, and the detection area is extended to the position of the nearest line segment along the current direction;
[0038] (3-7) Repeat step (3-6) until there is no nearest straight line in the four orientations according to step (3-2).
[0039] As a preferred technical scheme, in step (4), the calculation of the center point coordinates of the body is specifically:
[0040] (4-1) Calculate the center point coordinates of the body according to the coordinate information of the last body;
[0041]
[0042] Wherein, [x lt ,y lt ] is the left upper corner coordinate point of the body, and [x rb ,y rb ] is the right lower corner coordinate point of the body.
[0043] As a preferred technical solution, in step (5), whether the convex corner or the concave corner is merged is to meet one of the following conditions:
[0044] The concave corner block or the convex corner block is connected;
[0045] The distance between the concave corner block or the convex corner block is different by a set threshold;
[0046] The two convolution operations using the custom convolution kernel on the two binary images are specifically:
[0047] (5-1) generating two binary images with the same size as the rough contour image and with all pixel values being 0;
[0048] (5-2) using the method of the opencv library to draw the convex corner contour and the concave corner contour into two binary images respectively, and filling the pixels inside the contour with 255;
[0049] (5-3) using the preset horizontal fusion convolution kernel and the vertical fusion convolution kernel for the horizontal relationship and the vertical relationship, and using the custom convolution kernel convolution operation of the opencv library to fuse the concave corner block or the convex corner block meeting the set condition;
[0050] (5-4) after obtaining the fused binary image, using the binarization function of the opencv library to perform binary classification on the pixel points with pixel values other than 255 or 0 due to the convolution operation and convert them into a gray image, and finally using a contour extraction function to extract the fused concave corner and convex corner information.
[0051] In a second aspect, the application provides a house type drawing concave-convex corner determination system based on a region growing algorithm, comprising a contour reconstruction module, an initial dynamic region positioning module, a concave-convex corner determination module, a main body center calculation module and a concave-convex corner fusion module.
[0052] The contour reconstruction module is used to obtain a contour mask image with smooth edge lines, perform Hough straight line detection on the input rough outer contour mask image, retain the vertical and horizontal straight lines and the line segment parts on the contour, remove the straight line parts that are not extended, then fill the areas surrounded by the straight lines, and finally use a specific convolution kernel to perform image processing to remove small burrs in the mask image, to obtain a reconstructed contour image with smooth edges.
[0053] The initial dynamic region positioning module is used to calculate the maximum inscribed rectangle of the reconstructed contour image as an initial main body and an initial detection area of the house type drawing, calculate the maximum inscribed rectangle of the reconstructed contour, extract the vertical and horizontal line segments of the reconstructed contour using Hough straight line detection, and sort the vertical line segments and the horizontal line segments from left to right and from top to bottom respectively.
[0054] The concave-convex angle determination module is used to start from above the current detection area and scan around the detection area in a counterclockwise direction, specifically: finding the line segment closest to the detection area in the current direction, calculating the rectangle between the detection area and the closest line segment, i.e. the exploration area, finding the rectangle with a pixel value of 255 in the reconstruction contour, i.e. the discrimination block, if there are multiple discrimination blocks with a pixel value of 255 in the exploration area, sorting them in descending order of length, and then sequentially determining the concave-convex angle; if the length of the discrimination block is greater than or equal to one-third of the side corresponding to the direction of the minimum circumscribed rectangle, all the discrimination blocks are regarded as the main part, the area of the exploration area excluding all the discrimination blocks is regarded as the missing angle and saved, and the detection area and the main part are expanded to the closest line segment along the direction; if the length of the discrimination block is less than one-third of the side corresponding to the direction of the minimum circumscribed rectangle, all the discrimination blocks are regarded as convex angles and saved, and the detection area is expanded to the closest line segment along the direction; and finally the traversal stops when there is no closest line segment in the four directions of the detection area.
[0055] The main body center calculation module is used to finally obtain an accurate house type drawing main body center point coordinate according to the coordinates of the four vertices of the last main body by analyzing and utilizing the geometric properties of the rectangle.
[0056] The concave-convex angle fusion module is used to generate two binary images with the same size as the reconstruction contour image and with all values being 0, draw the convex angle contour and the missing angle contour on the two binary images respectively, design a vertical sensing convolution kernel and a horizontal sensing convolution kernel for the task of merging similar convex angle blocks and missing angle blocks, perform two convolution operations on the two binary images using the custom convolution kernels to merge adjacent blocks, extract the blocks in the binary images, and finally merge the convex angle and missing angle contour information.
[0057] In a third aspect, the present application provides an electronic device, which comprises:
[0058] at least one processor; and
[0059] a memory connected to the at least one processor in communication; wherein
[0060] The memory stores computer program instructions executable by the at least one processor, and the computer program instructions are executed by the at least one processor to enable the at least one processor to execute the house type drawing concave-convex angle determination method based on the region growing algorithm.
[0061] In a fourth aspect, the present application provides a computer readable storage medium storing a program, which is executed by a processor to implement the house type drawing concave-convex angle determination method based on the region growing algorithm according to any one of claims 1-7.
[0062] Compared with the prior art, the present application has the following advantages and beneficial effects:
[0063] (1) The application provides a house type drawing concave-convex angle determination method and device based on a region growing algorithm. The application is based on a region growing algorithm, and a house type drawing concave-convex angle meeting requirements is obtained. The method is the first method in this direction based on image processing to solve real needs, can process most types of house type drawing contours, and accurately and efficiently segments the concave-convex angle.
[0064] (2) The application is the first algorithm for determining the concave-convex angle in this direction, has a low maintenance cost, is easy to iterate, and a same set of systems can easily use multiple algorithms and be combined with a deep learning model.
[0065] (3) The application provides a house type drawing concave-convex angle determination method and device based on a region growing algorithm, which can greatly reduce manual participation and shorten house type drawing analysis time. Since the algorithm can batch process multiple house type drawings, the human and time costs required by users in the design and evaluation stage will be significantly reduced, thereby accelerating the project advancement speed.
[0066] (4) The application can be customized and developed according to the needs of different users. For example, different users have different requirements for house type drawings, and the determination standards of the concave-convex angle are also different. Through the design of flexible parameter configuration, the system can easily adapt to different house type drawing analysis requirements. BRIEF DESCRIPTION OF DRAWINGS
[0067] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0068] Figure 1 The flowchart of the house type drawing concave-convex angle determination method based on the region growing algorithm of the embodiment of the present application.
[0069] Fig. 2(a) and Fig. 2(b) are house type drawing original drawings and outer contour mask images according to the embodiment of the present application.
[0070] Fig. 2(c) is an optimized contour image reconstructed based on the outer contour mask image according to the embodiment of the present application.
[0071] Figure 3 The effect diagram of the boundary line after optimization in the reconstructed contour module according to the embodiment of the present application.
[0072] Fig. 4(a) is the first nearest line segment matched upward by the initial main body according to the embodiment of the present application.
[0073] Figure 4(b) is the first line segment closest to the initial subject downward matching of the embodiment of the present application.
[0074] Figure 5 The determination block binary graph in the exploration area of the current initial subject downward matching of the embodiment of the present application.
[0075] Figure 6 The concave-convex angle discrimination result graph of the embodiment of the present application (blue for concave angle and orange for convex angle).
[0076] Figure 7 The structural schematic diagram of the concave-convex angle discrimination system of the house type graph based on the region growing algorithm of the embodiment of the present application.
[0077] Figure 8 The structural schematic diagram of the electronic device of the present application. DETAILED DESCRIPTION
[0078] In order for those skilled in the art to better understand the scheme of the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0079] In the present application, "embodiment" means that the specific features, structures or characteristics described in conjunction with the embodiment can be contained in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily mean the same embodiment, nor is it an independent or alternative embodiment to other embodiments. Those skilled in the art understand explicitly and implicitly that the embodiments described in the present application can be combined with other embodiments.
[0080] As Figure 1 shown, the concave-convex angle discrimination method of the house type graph based on the region growing algorithm of the present embodiment includes the following steps:
[0081] (1) Obtain the edge line smooth contour mask graph, perform Hough line detection on the input rough outer contour mask graph, retain the vertical and horizontal straight lines, retain the line segment part on the contour, remove the straight line part of the outer extension, then fill the area surrounded by the straight line, and then use a specific convolution kernel to process the image to remove the small burrs in the mask graph, to obtain the reconstructed contour image with smooth edges, as Figures 2(a)-2(c) shown.
[0082] Further, the Hough line detection and opencv method are used in the reconstructed contour module, specifically:
[0083] (1-1) Canny edge detection is performed on the input rough outer contour mask image to obtain a binary image of the contour edge, and Hough line detection is performed on the binary image to obtain r and θ of all straight lines in the contour, i.e. the length and radian of the straight line in polar coordinates. According to all the angles of the straight lines Screen out horizontal and vertical straight lines;
[0084] (1-2) The end point coordinates of all horizontal and vertical straight lines are calculated according to the r and θ of the straight lines, respectively, and represented as [x1, y1, x2, y2], i.e. the x and y coordinates of the starting point and the x and y coordinates of the end point of the straight line:
[0085] Horizontal straight line:
[0086] Vertical straight line:
[0087] Where image_width and image_height represent the height and width of the rough contour image, respectively, a is a fixed value greater than the height and width of all rough contour images in the data set, and a is set to 4000 in this embodiment;
[0088] (1-3) The horizontal straight lines are extracted and sorted in ascending order according to y1 (the vertical coordinate of the starting point), and the vertical straight lines are extracted and sorted in ascending order according to x1 (the horizontal coordinate of the starting point). The x1 (the horizontal coordinate of the starting point) and x2 (the horizontal coordinate of the end point) of the horizontal straight lines are limited to be between the x1 (the horizontal coordinate of the starting point) of the first and last vertical straight lines, and the y1 (the vertical coordinate of the starting point) and y2 (the vertical coordinate of the end point) of the vertical straight lines are limited to be between the y1 (the vertical coordinate of the starting point) of the first and last horizontal straight lines.
[0089] (1-4) Each line segment in the grid, which is cut by all the vertical and horizontal straight lines, is determined whether it belongs to the boundary inner line segment. Specifically, the two end points and the midpoint of the line segment are determined whether they are within the boundary. If there are non-zero pixel values in the AxB rectangle centered on the two end points, i.e. there are pixels belonging to the contour, the line segment is retained. In this embodiment, A and B are both taken as 14. If there are non-zero pixel values in the rectangle centered on one end point and the midpoint, the line segment is retained. Finally, all the line segments belonging to the boundary are left, as shown in Figure 3 .
[0090] (1-5) The retained line segments are drawn on a binary image whose size is equal to that of the rough contour image and whose value is all 0, i.e. the position of the line segment is assigned a value of 255. The outer contour of the binary image is extracted using the contour detection algorithm of opencv, and the outer contour extracted is drawn on the binary image using the contour filling algorithm of opencv to obtain the reconstructed contour.
[0091] (1-6) The reconstructed contour obtained above may have some small burrs. In order to remove the burrs, a contour thinning convolution kernel is designed, and the custom convolution operation of opencv is used to eliminate the small burrs extending outward, so as to obtain an accurate reconstructed contour. Specifically, a vertical noise reduction convolution kernel is used for convolution operation, and then binarization processing is performed, and finally a vertical restoration convolution kernel is used for convolution operation; a horizontal noise reduction convolution kernel is used for convolution operation, and then binarization processing is performed, and finally a horizontal restoration convolution kernel is used for convolution operation.
[0092] Vertical noise reduction convolution kernel Vertical restoration convolution kernel
[0093] Horizontal noise reduction convolution kernel Horizontal restoration convolution kernel
[0094] (1-7) The opencv library is used to binarize the accurate reconstructed contour, and the pixels of part 255 and 0 caused by convolution operation are classified.
[0095] (2) The maximum inscribed rectangle of the reconstructed contour is calculated as the initial main body and the initial detection area of the house type diagram. The maximum inscribed rectangle of the reconstructed contour is calculated by using the opencv algorithm, and the vertical and horizontal line segments of the reconstructed contour are extracted by using the Hough line detection, and the vertical and horizontal line segments are sorted from left to right and from top to bottom respectively.
[0096] Further, the maximum inscribed rectangle of the reconstructed contour is calculated by using a straight line intersection point cyclic reconstruction algorithm based on Hough line detection, which is specifically as follows:
[0097] (2-1) Considering that the edge cannot be recognized due to the adhesion of the image boundary to the contour boundary of part of the reconstructed contour, the constant edge expansion method of opencv is used to expand the boundary with pixel value 0. In this embodiment, the expansion length is 10.
[0098] (2-2) Based on the opencv method, the edge image of the reconstructed contour is first extracted by using the canny edge detection algorithm, and then the straight lines of the reconstructed contour are extracted by using the Hough line detection. The method is similar to step (1) of screening out horizontal and vertical line segments and sorting.
[0099] (2-3) All vertical and horizontal line segments are traversed, the coordinates of the intersection points are calculated, and then it is judged whether there is a pixel point with pixel value 255 in the 5*5 rectangle centered on the intersection point. If there are multiple, the coordinates of the pixel point closest to the intersection point with pixel value 255 are returned.
[0100] I1 horizontal I2 vertical (|x4-x3|≤1):
[0101] ι1 vertical (|x2-x1|≤1) ι2 horizontal:
[0102] ι1 pseudo horizontal ι2 pseudo vertical (2≤|x4-x3|≤5):
[0103]
[0104] wherein ι1 is the first line segment, represented by [x1,y2,x2,y2], i.e. the coordinates of the two end points of the line segment [x1,y1] and [x2,y2] (x1≤x2, y1≤y2), ι2 is the second line segment, represented by [x3,y3,x4,y4], i.e. the coordinates of the two end points of the line segment [x3,y3] and [x4,y4] (x3≤x4, y3≤y4);
[0105] (2-4) Calculate all intersection points and the area of the rectangle with the two intersection points as opposite corners, and sort them in descending order of the area. Then, start with the largest area and judge one by one whether the condition is met. Specifically, let the minimum and maximum x values of the current two intersection points be x min and x max , traverse the straight line between x min and x max on the y1 and y2 rows of the reconstructed contour to determine whether there is a pixel point with a value of 0, i.e. whether the upper and lower sides of the rectangle formed by the two intersection points are both inside the reconstructed contour. If there is a pixel point with a value of 0, it means that the current rectangle is not the largest inscribed rectangle. Let the minimum and maximum y values of the current two intersection points be y min and y max , traverse the straight line between y min and y max on the x1 and x2 rows of the reconstructed contour to determine whether there is a pixel point with a value of 0, i.e. whether the left and right sides of the rectangle formed by the two intersection points are both inside the reconstructed contour. If there is a pixel point with a value of 0, it means that the current rectangle is not the largest inscribed rectangle. If there is no pixel point with a value of 0 on the four sides of the rectangle, the current rectangle is the largest inscribed rectangle of the reconstructed contour. If there is a pixel point with a value of 0 on the four sides of the rectangle, the current rectangle is not the largest inscribed rectangle of the reconstructed contour. The above operation steps are performed on the next rectangle.
[0106] (2-5) Since a constant edge expansion is used in (2-1), the coordinates of the two intersection points corresponding to the largest inscribed rectangle obtained finally are reduced by the expanded constant value, which is 10 in this embodiment. The largest inscribed rectangle is stored in the form of [x1,y1,x2,y2], i.e. the coordinate list of the two opposite corners. The largest inscribed rectangle is used as the initial main body and the initial detection area, and the storage format is the same.
[0107] (3) Starting from above the current detection area, scan around the detection area in a counterclockwise direction, specifically: find the line segment closest to the detection area in the current direction, calculate the rectangle between the detection area and the closest line segment, that is, the exploration area, find the rectangle with a pixel value of 255 in the reconstructed contour, that is, the discrimination block, if there are multiple discrimination blocks with a pixel value of 255 in the exploration area, sort them in descending order of length, then perform concave-convex angle discrimination in order; if the length of the discrimination block is greater than or equal to one-third of the side corresponding to the direction of the minimum circumscribed rectangle, all discrimination blocks are regarded as the main part, the area of the exploration area excluding all discrimination blocks is regarded as a missing corner and saved, and the detection area and the main part are expanded along the direction to the closest line segment; if the length of the discrimination block is less than one-third of the side corresponding to the direction of the minimum circumscribed rectangle, all discrimination blocks are regarded as convex corners and saved, and the detection area is expanded along the direction to the closest line segment; finally, stop traversing when there is no closest line segment in the four directions of the detection area.
[0108] Further, the scanning around the main body and judging concave-convex angles, specifically:
[0109] (3-1) Construct a direction list, the initial direction is upward, then traverse the direction list in order, that is, traverse around the main body in a counterclockwise direction;
[0110] (3-2) Find the line segment closest to the detection area in the current direction, specifically: if the current direction is upward, traverse the horizontal line segment sequence in order, when the first line segment in the sequence and the first line segment in the sequence satisfy that the first line segment falls on the upper side of the detection area or below when it is translated downward by a set value, then the current line segment is the closest straight line; if the current direction is left, when the first line segment in the sequence and the first line segment in the sequence satisfy that the first line segment falls on the left side of the detection area or to the right when it is translated to the right by a set value, then the current line segment is the closest straight line; if the current direction is downward, when the first line segment satisfies that it falls below the lower side of the detection area when it is translated upward by a set value, then the current line segment is the closest straight line; if the current direction is right, when the first line segment satisfies that it falls to the right of the right side of the detection area when it is translated to the right by a set value, then the current line segment is the closest straight line; the above set value is 5 in this embodiment, as shown in Figures 4(a)-4(b) ;
[0111] (3-3) Then, through the closest line segment found in the current direction and the current main body, calculate the rectangle between the main body and the line segment as the exploration area this time, and then use the pixel exclusive OR method of the opencv library to obtain a single or multiple rectangles with a pixel value of 255 in the exploration area, that is, the discrimination block, as shown in Figure 5 ;
[0112] (3-4) The discrimination block obtained by the pixel-by-pixel XOR method using opencv may have some burrs, so in order to eliminate the burrs in the discrimination block and avoid affecting the discrimination of the concave-convex angle, several convolution kernels are specially designed for the burr conditions encountered in the discrimination block of the four orientations, and the convolution kernel shape is the same as that in step (1-6); when the orientation is upward and downward, a vertical noise reduction convolution kernel is used for convolution operation, then opencv binarization is used, and finally a vertical restoration convolution kernel is used for convolution operation; when the orientation is left and right, a horizontal noise reduction convolution kernel is used for convolution operation, then opencv binarization is used, and finally a horizontal restoration convolution kernel is used for convolution operation;
[0113] (3-5) After obtaining the refined single or multiple discrimination blocks, the discrimination blocks are sorted first; when the orientation is upward and downward, the discrimination blocks are sorted in descending order according to the width; when the orientation is left and right, the discrimination blocks are sorted in descending order according to the height;
[0114] (3-6) The sorted discrimination block sequence is traversed, and when the discrimination block meets the following concave angle setting conditions, a queue method is used to construct a discrimination block queue, and after the first discrimination block is removed from the exploration area, one or two remaining areas are left, then according to the coordinate information, it is judged which remaining area the following discrimination block belongs to, and then the corresponding remaining area is subtracted from the following discrimination block, until the discrimination block queue is empty, and the remaining area is the missing angle, and the main body and the detection area are extended to the position of the nearest line segment in the current direction; when the discrimination block meets the following convex angle setting conditions, all discrimination blocks are convex angles, and the detection area is extended to the position of the nearest line segment in the current direction, such as Figure 6 ; The setting conditions for discriminating convex (concave) angles refer to the following conditions:
[0115] When the current search orientation is above the main body, if the width of the discrimination block is greater than or equal to one third of the width of the minimum bounding rectangle of the contour, the discrimination block belongs to the main body, and the area of the exploration area excluding the discrimination block is a concave angle; if the width of the discrimination block is less than one third of the width of the minimum bounding rectangle of the contour, the discrimination block is a convex angle;
[0116] When the current search orientation is left of the main body, if the height of the discrimination block is greater than or equal to one third of the height of the minimum bounding rectangle of the contour, the discrimination block belongs to the main body, and the area of the exploration area excluding the discrimination block is a concave angle; if the height of the discrimination block is less than one third of the height of the minimum bounding rectangle of the contour, the discrimination block is a convex angle;
[0117] When the current search orientation is below the main body, if the width of the discrimination block is greater than or equal to one third of the width of the minimum bounding rectangle of the contour, the discrimination block belongs to the main body, and the area of the exploration area excluding the discrimination block is a concave angle; if the width of the discrimination block is less than one third of the width of the minimum bounding rectangle of the contour, the discrimination block is a convex angle;
[0118] When the current search direction is right of the main body, if the height of the block is greater than or equal to one third of the height of the minimum enclosing rectangle of the contour, the block belongs to the main body part, and the area of the exploration zone excluding the block is a concave corner; if the height of the block is less than one third of the height of the minimum enclosing rectangle of the contour, the block is a convex corner.
[0119] (3-7) Repeat step (3-6) until there is no nearest straight line according to the four directions determined in step (3-2).
[0120] (4) According to the coordinates of the four vertices of the last main body, an accurate center point coordinate of the house type drawing main body is finally obtained by analyzing and utilizing the geometric properties of the rectangle.
[0121] Further, the calculation of the main body center point coordinate is specifically:
[0122] (4-1) According to the last main body coordinate information, the main body center point coordinate can be calculated;
[0123]
[0124] where [x lt , y lt ] is the coordinate point of the upper left corner of the main body, and [x rb , y rb ] is the coordinate point of the lower right corner of the main body.
[0125] (5) Using opencv, numpy and other libraries, two binary images with the same size as the reconstructed contour and all pixel values of 0 are generated, and the convex corner contour and the missing corner contour are drawn on the two binary images. For the task of merging similar convex corner blocks and missing corner blocks, we designed a vertical sensing convolution kernel and a horizontal sensing convolution kernel. Two convolution operations are performed on the two binary images using the custom convolution kernel to merge adjacent blocks, and then the blocks in the binary image are extracted, that is, the final merged convex corner and missing corner contour information.
[0126] Further, the saved all scattered concave corner blocks and convex corner blocks are respectively merged, which is specifically:
[0127] (5-1) Generate two binary images with the same size as the rough contour image and all pixel values of 0;
[0128] (5-2) Use the method of opencv library to draw the convex corner contour and the concave corner contour into the two binary images, and fill the pixels inside the contour with 255;
[0129] (5-3) In order to combine the concave or convex corner blocks satisfying the above setting conditions, two fusion convolution kernels are designed in this embodiment for the horizontal and vertical relationship cases, and the concave or convex corner blocks satisfying the setting conditions are fused by using the custom convolution kernel convolution operation of the opencv library;
[0130] vertical fusion convolution kernel horizontal fusion convolution kernel
[0131] (5-4) After obtaining the fused binary image, the opencv library binary function is used to perform binary classification and convert to a gray image for the pixel points with pixel values other than 255 or 0 due to the convolution operation, and finally the fused concave and convex corner information is extracted using the contour extraction function.
[0132] It should be noted that, for the foregoing method embodiments, in order to facilitate description, they are all described as a series of action combinations, but those skilled in the art should know that the present application is not limited by the action sequence described, because according to the present application, certain steps can be performed in other sequences or simultaneously.
[0133] Based on the same idea as the house type drawing concave-convex corner determination method based on the region growing algorithm in the above embodiment, the present application also provides a house type drawing concave-convex corner determination system based on the region growing algorithm, which can be used to execute the house type drawing concave-convex corner determination method based on the region growing algorithm. For the convenience of description, in the structural schematic diagram of the house type drawing concave-convex corner determination system embodiment based on the region growing algorithm, only the part related to the embodiment of the present application is shown, and those skilled in the art can understand that the illustrated structure does not constitute a limitation on the device, and can include more or fewer components than the illustrated, or combine certain components, or different component arrangements.
[0134] Please refer to Figure 7 In another embodiment of the present application, a house type drawing concave-convex corner determination system 100 based on the region growing algorithm is provided, which comprises a contour reconstruction module 101, an initial dynamic region positioning module 102, a concave-convex corner determination module 103, a main body center calculation module 104 and a concave-convex corner fusion module 105;
[0135] The contour reconstruction module 101 is used to obtain a contour mask image with smooth edge lines, perform Hough straight line detection on the input rough outer contour mask image, retain the vertical and horizontal straight lines and the line segment part on the contour, remove the straight line part that is not extended, then fill the area surrounded by the straight lines, and finally use a specific convolution kernel to process the image to remove the small burrs in the mask image, to obtain a reconstructed contour image with smooth edges;
[0136] The initial dynamic region positioning module 102 is configured to calculate a maximum inscribed rectangle of a reconstructed contour image as an initial main body and an initial detection area of a house type diagram, and calculate a maximum inscribed rectangle of the reconstructed contour, extract vertical and horizontal line segments of the reconstructed contour by using a Hough line detection, and sort the vertical and horizontal line segments in a left-to-right and top-to-bottom manner, respectively.
[0137] The concave-convex angle determination module 103 is configured to start from above a current detection area, and cyclically scan around the detection area in a counterclockwise direction, specifically: find a line segment closest to the detection area in a current direction, calculate a rectangle between the detection area and the closest line segment, that is, an exploration area, find a rectangle with a pixel value of 255 in the exploration area according to the reconstructed contour, that is, a discrimination block, if there are multiple discrimination blocks with a pixel value of 255 in the exploration area, sort the discrimination blocks in a descending order of length, and then sequentially determine concave-convex angles; if the length of the discrimination block is greater than or equal to one-third of a side corresponding to the direction of the minimum circumscribed rectangle, all the discrimination blocks are regarded as a main body part, an area of the exploration area except all the discrimination blocks is regarded as a missing angle and saved, and the detection area and the main body are expanded to the closest line segment along the direction; if the length of the discrimination block is less than one-third of the side corresponding to the direction of the minimum circumscribed rectangle, all the discrimination blocks are regarded as a convex angle and saved, and the detection area is expanded to the closest line segment along the direction; and finally, the traversal is stopped until there is no closest line segment in four directions of the detection area.
[0138] The main body center calculation module 104 is configured to finally obtain an accurate house type diagram main body center point coordinate according to four vertex coordinates of the last main body by analyzing and utilizing geometric properties of the rectangle.
[0139] The concave-convex angle fusion module 105 is configured to generate two binary images with the same size as the reconstructed contour image and with all values being 0, draw the convex angle contour and the missing angle contour on the two binary images respectively, design a vertical sensing convolution kernel and a horizontal sensing convolution kernel for the task of merging similar convex angle blocks and missing angle blocks, perform twice convolution operations on the two binary images by using the self-defined convolution kernel to merge adjacent blocks, extract the blocks in the binary images, and finally merge the convex angle and missing angle contour information.
[0140] It should be noted that the house type diagram concave-convex angle determination system based on the region growing algorithm of the present application corresponds to the house type diagram concave-convex angle determination method based on the region growing algorithm of the present application, and the technical features and advantages described in the embodiment of the house type diagram concave-convex angle determination method based on the region growing algorithm are applicable to the embodiment of the house type diagram concave-convex angle determination based on the region growing algorithm, and the specific content can be referred to the description in the method embodiment of the present application, which will not be repeated here, and hereby declared.
[0141] In addition, in the implementation of the house type drawing concave-convex angle determination system based on the region growing algorithm in the above embodiment, the logical division of each program module is only illustrative. In actual application, the above-mentioned function allocation can be completed by different program modules according to needs, for example, for the configuration requirements of corresponding hardware or the convenience of software implementation, that is, the internal structure of the house type drawing concave-convex angle determination system based on the region growing algorithm is divided into different program modules to complete all or part of the functions described above.
[0142] Please refer to Figure 8 In one embodiment, an electronic device implementing a house type drawing concave-convex angle determination method based on a region growing algorithm is provided. The electronic device 200 can include a first processor 201, a first memory 202, and a bus, and can further include a computer program stored in the first memory 202 and executable on the first processor 201, such as a house type drawing concave-convex angle determination program 203.
[0143] The first memory 202 includes at least one type of readable storage medium, including a flash memory, a mobile hard disk, a multimedia card, a card-type memory (such as an SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the first memory 202 can be an internal storage unit of the electronic device 200, such as a mobile hard disk of the electronic device 200. In other embodiments, the first memory 202 can also be an external storage device of the electronic device 200, such as a plug-in mobile hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. Further, the first memory 202 can include both an internal storage unit and an external storage device of the electronic device 200. The first memory 202 can be used not only to store application software and various data installed on the electronic device 200, such as the code of the house type drawing concave-convex angle determination program 203, but also to temporarily store data that has been or will be output.
[0144] The first processor 201 may, in some embodiments, be composed of integrated circuits, for example, may be composed of a single packaged integrated circuit, or may be composed of multiple packaged integrated circuits of the same function or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips, etc. The first processor 201 is the control unit of the electronic device, connects various components of the entire electronic device through various interfaces and lines, and executes various functions and processes data of the electronic device 200 by running or executing programs or modules stored in the first memory 202 and calling data stored in the first memory 202.
[0145] Figure 8 Only the electronic device with components is shown, and those skilled in the art can understand that, Figure 8 The structure shown does not constitute a limitation on the electronic device 200, and can include fewer or more components than shown, or combine certain components, or different component arrangements.
[0146] The floor plan concave-convex angle determination program 203 stored in the first memory 202 in the electronic device 200 is a combination of multiple instructions, which, when running in the first processor 201, can achieve:
[0147] (1) Obtain an edge line smooth contour mask image, perform Hough line detection on the input rough outer contour mask image, retain the vertical and horizontal lines, retain the line segment part on the contour, remove the straight line part of the outer extension, then fill the area surrounded by the straight line, and then use a specific convolution kernel to process the image to remove small burrs in the mask image, to obtain a reconstructed contour image with smooth edges;
[0148] (2) Calculate the maximum inscribed rectangle of the reconstructed contour image as the initial main body and the initial detection area of the floor plan, and calculate the maximum inscribed rectangle of the reconstructed contour, extract the vertical and horizontal line segments of the reconstructed contour using Hough line detection, and sort the vertical and horizontal line segments from left to right and from top to bottom, respectively;
[0149] (3) Starting from the top of the current detection area, scan the detection area in a counterclockwise direction, specifically: find the line segment closest to the detection area in the current direction, calculate the rectangle between the detection area and the closest line segment, that is, the exploration area, find the rectangle with a pixel value of 255 in the reconstructed contour, that is, the discrimination block, if there are multiple discrimination blocks with a pixel value of 255 in the exploration area, sort them in descending order of length, and then perform concave-convex angle discrimination in order; if the length of the discrimination block is greater than or equal to one-third of the side corresponding to the direction of the minimum circumscribed rectangle, all discrimination blocks are regarded as the main part, the area of the exploration area excluding all discrimination blocks is regarded as the missing angle and saved, and the detection area and the main part are expanded to the nearest line segment along the direction; if the length of the discrimination block is less than one-third of the side corresponding to the direction of the minimum circumscribed rectangle, all discrimination blocks are regarded as convex angles and saved, and the detection area is expanded to the nearest line segment along the direction; finally, stop traversing when there is no nearest line segment in the four directions of the detection area;
[0150] (4) By analyzing and utilizing the geometric properties of the rectangle, according to the coordinates of the four vertices of the last main body, an accurate house type diagram main body center point coordinate is finally obtained;
[0151] (5) Generate two binary images with the same size as the reconstructed contour image and all values of 0, draw the convex angle contour and the missing angle contour on the two binary images respectively, design vertical and horizontal sensing convolution kernels for the task of merging similar convex angle blocks and missing angle blocks, and use the custom convolution kernels to do twice convolution operation on the two binary images to merge adjacent blocks, then extract the blocks in the binary image, and finally merge the convex angle and missing angle contour information.
[0152] Further, the modules / units of the electronic device 200, if implemented in the form of software function units and sold or used as independent products, can be stored in a non-volatile computer readable storage medium. The computer readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory).
[0153] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The program can be stored in a non-volatile computer readable storage medium, and when the program is executed, the processes of the above-mentioned embodiment methods can be included. Any reference to memory, storage, database or other medium used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0154] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist, it should be considered as the scope of the present application.
[0155] The above embodiments are the preferred embodiments of the present application, but the embodiments of the present application are not limited to the above embodiments, and any changes, modifications, substitutions, combinations and simplifications made without departing from the spirit and principles of the present application should be equivalent replacement methods, and are included in the protection scope of the present application.
Claims
1. A method for determining concave-convex angles of a house type drawing based on a region growing algorithm, characterized in that, The method comprises the following steps: (1) obtaining an edge line smooth contour mask image, performing Hough straight line detection on an input rough outer contour mask image, retaining vertical and horizontal straight lines, retaining line segment parts on the contour, removing extended straight line parts, subsequently filling areas surrounded by the straight lines, and then performing image processing using a specific convolution kernel to remove small burrs in the mask image to obtain a reconstructed contour image with smooth edges; (2) calculating a maximum inscribed rectangle of the reconstructed contour image as an initial main body and an initial detection area of the house type image, and calculating a maximum inscribed rectangle of the reconstructed contour, extracting vertical and horizontal line segments of the reconstructed contour using Hough straight line detection, and sorting the vertical and horizontal line segments from left to right and from top to bottom respectively; (3) starting from above the current detection area, circularly scanning the detection area in a counterclockwise direction, specifically: finding the line segment closest to the detection area in the current direction, calculating a rectangle between the detection area and the closest line segment, i.e. an exploration area, finding a rectangle with a pixel value of 255 in the exploration area according to the reconstructed contour, i.e. a discrimination block, if there are multiple discrimination blocks with a pixel value of 255 in the exploration area, sorting them in descending order of length, and then sequentially discriminating convex and concave corners; if the length of the discrimination block is greater than or equal to one-third of the side of the minimum circumscribed rectangle corresponding to the direction, all discrimination blocks are regarded as main bodies, the area of the exploration area excluding all discrimination blocks is regarded as a missing corner and saved, and the detection area and the main body are expanded to the closest line segment along the direction; if the length of the discrimination block is less than one-third of the side of the minimum circumscribed rectangle corresponding to the direction, all discrimination blocks are regarded as convex corners and saved, and the detection area is expanded to the closest line segment along the direction; finally, stop traversing when there is no closest line segment in the four directions of the detection area; (4) finally obtaining an accurate house type image main body center point coordinate according to the coordinates of the four vertices of the last main body by analyzing and utilizing the geometric properties of the rectangle; (5) generating two binary images with the same size as the reconstructed contour image and a value of 0, drawing the convex corner contour and the missing corner contour on the two binary images respectively, designing a vertical sensing convolution kernel and a horizontal sensing convolution kernel for the task of merging adjacent convex corner blocks and missing corner blocks, performing two convolution operations on the two binary images using the custom convolution kernel to merge adjacent blocks, extracting the blocks in the binary images, and finally merging the convex corner and missing corner contour information.
2. The method according to claim 1, wherein, In step (1), the reconstructed contour image with smooth edges is obtained, specifically: (1-1) Canny edge detection is performed on the input rough outer contour mask image to obtain a binary image of the contour edge, and Hough line detection is performed on the binary image to obtain r and θ of all straight lines in the contour, where r and θ represent the length and radian of the straight line in polar coordinates, respectively. According to all the angles of the straight lines Horizontal and vertical straight lines are screened out; (1-2) calculating the end point coordinates of all horizontal and vertical straight lines according to r and θ of the straight lines respectively; (1-3) extracting the horizontal straight lines and sorting them in ascending order of the starting point vertical coordinate, extracting the vertical straight lines and sorting them in ascending order of the starting point horizontal coordinate, limiting the starting point horizontal coordinate and the ending point horizontal coordinate of the horizontal straight lines to be between the starting point horizontal coordinates of the first and last vertical straight lines, and limiting the starting point vertical coordinate and the ending point vertical coordinate of the vertical straight lines to be between the starting point vertical coordinates of the first and last horizontal straight lines; (1-4)Judge whether each line segment intersected by all vertical and horizontal straight lines in the grid belongs to the boundary inner line segment, specifically: judge the two endpoints and the midpoint of the line segment, if there is a pixel value that is not 0 on the AxB rectangle centered on the two endpoints, that is, there is a pixel belonging to the contour, the line segment is retained; if there is a pixel value that is not 0 on the rectangle centered on one of the endpoints and the midpoint, the line segment is retained; finally, all line segments belonging to the boundary are left; (1-5)Draw the retained line segments on a binary image whose size is equal to the rough contour image and whose value is all 0, that is, the position of the line segment is assigned a value of 255; use the contour detection algorithm of opencv to extract the outer contour of the binary image, and then use the contour filling algorithm of opencv to draw the extracted outer contour to the binary image to obtain the reconstructed contour; (1-6)Use the custom convolution operation of opencv to eliminate the small and thin protruding burrs to obtain the accurate reconstructed contour, specifically: use the vertical noise reduction convolution kernel for convolution operation, then perform binaryzation processing, and finally use the vertical restoration convolution kernel for convolution operation; use the horizontal noise reduction convolution kernel for convolution operation, then perform binaryzation processing, and finally use the horizontal restoration convolution kernel for convolution operation; (1-7)Use the opencv library to perform binaryzation on the accurate reconstructed contour, and perform two classifications on the pixel points that are not 255 and 0 due to convolution operation.
3. The method according to claim 1, wherein, In step (2), the maximum inscribed rectangle of the reconstructed contour is calculated, specifically: (2-1)Considering that the edge cannot be recognized due to the adhesion of the boundary of the reconstructed contour image to the contour boundary, first use the constant edge expansion method of opencv to expand the boundary with pixel value 0; (2-2)Based on the opencv method, first use the canny edge detection algorithm to extract the edge image of the reconstructed contour, and then use the hough straight line detection to extract the straight lines of the reconstructed contour; (2-3)Iterate all vertical and horizontal line segments to calculate the coordinates of the intersection points, and then judge whether there are pixel points with pixel value 255 in the preset rectangle centered on the intersection point, if there are multiple, return the coordinates of the pixel point with pixel value 255 closest to the intersection point; (2-4)Calculate all intersection points and the area of the rectangle with the opposite points as the corners and sort them from large to small. Then, start with the largest area and determine whether it meets the conditions. Specifically, let the minimum and maximum x values of the current two intersection points be x min and x max . Check whether there is a pixel point with a value of 0 on the straight line between x min and x max on the reconstructed contour, that is, whether the upper and lower sides of the rectangle formed by the two intersection points are both inside the reconstructed contour. If there is a pixel point with a value of 0, it means that the current rectangle is not the largest inscribed rectangle. Let the minimum and maximum y values of the current two intersection points be y min and y max . Check whether there is a pixel point with a value of 0 on the straight line between y min and y max on the reconstructed contour, that is, whether the left and right sides of the rectangle formed by the two intersection points are both inside the reconstructed contour. If there is a pixel point with a value of 0, it means that the current rectangle is not the largest inscribed rectangle. If there is no pixel point with a value of 0 on the four sides of the rectangle, the current rectangle is the largest inscribed rectangle of the reconstructed contour. If there is a pixel point with a value of 0 on the four sides of the rectangle, the current rectangle is not the largest inscribed rectangle of the reconstructed contour. Perform the above operation steps on the next rectangle. (2-5)Since the constant edge expansion is used in (2-1), the two intersection point coordinates corresponding to the final maximum inscribed rectangle are subtracted by the constant value of expansion; the maximum inscribed rectangle is stored as [x1, y1, x2, y2], that is, the coordinate list of the two opposite corners; the maximum inscribed rectangle is used as the initial main body and the initial detection area, and the storage format is the same.
4. The method according to claim 1, wherein, In step (3), the setting conditions for concave and convex angle discrimination are as follows: When the current search direction is above the main body, if the width of the discrimination block is greater than or equal to one third of the width of the minimum circumscribed rectangle of the contour, the discrimination block belongs to the main body part, and the area of the exploration area excluding the discrimination block is a concave angle; If the width of the discrimination block is less than one third of the width of the minimum circumscribed rectangle of the contour, the discrimination block is a convex angle; When the current search direction is left, if the height of the block is greater than or equal to one third of the height of the minimum bounding rectangle of the contour, the block belongs to the main body, and the area of the exploration region excluding the block is a concave corner; if the height of the block is less than one third of the height of the minimum bounding rectangle of the contour, the block is a convex corner. When the current search direction is below, if the width of the block is greater than or equal to one third of the width of the minimum bounding rectangle of the contour, the block belongs to the main body, and the area of the exploration region excluding the block is a concave corner. If the width of the block is less than one third of the width of the minimum bounding rectangle of the contour, the block is a convex corner. When the current search direction is right, if the height of the block is greater than or equal to one third of the height of the minimum bounding rectangle of the contour, the block belongs to the main body, and the area of the exploration region excluding the block is a concave corner; if the height of the block is less than one third of the height of the minimum bounding rectangle of the contour, the block is a convex corner.
5. The method according to claim 2, wherein, In step (3), the detection region is scanned in a counterclockwise direction, specifically: (3-1) Construct a direction list, the initial direction is upward, and then sequentially traverse the direction list, that is, traverse the main body in a counterclockwise direction; (3-2) Find the line segment closest to the detection region in the current direction, specifically: if the current direction is upward, sequentially traverse the horizontal line segment sequence, and when the first line segment in the sequence and the first line segment in the sequence satisfy that the line segment falls on the upper side of the detection region or below when it is translated downward by a certain value, then the current line segment is the closest straight line to the previous line segment in the sequence; if the current direction is left, when the first line segment in the sequence and the first line segment in the sequence satisfy that the line segment falls on the left side of the detection region or to the right, then the current line segment is the closest straight line to the previous line segment in the sequence; if the current direction is downward, when the first line segment satisfies that the line segment falls below the lower side of the detection region when it is translated upward by a certain value, then the current line segment is the closest straight line; if the current direction is right, when the first line segment satisfies that the line segment falls to the right of the right side of the detection region when it is translated to the right by a certain value, then the current line segment is the closest straight line; (3-3) Then, based on the closest line segment found in the current direction and the current main body, a rectangle between the main body and the line segment is calculated as the exploration region for this time, and the opencv library is used to obtain a single or multiple rectangles with pixel values of 255 in the exploration region, i.e., the block for discrimination; (3-4) Design several convolution kernels for the burr conditions encountered in the discrimination blocks of the four directions, and the convolution kernel shape is the same as in step (1-6); when the direction is upward and downward, a vertical noise reduction convolution kernel is used for convolution operation, then opencv is used for binarization, and finally a vertical restoration convolution kernel is used for convolution operation; when the direction is left and right, a horizontal noise reduction convolution kernel is used for convolution operation, then opencv is used for binarization, and finally a horizontal restoration convolution kernel is used for convolution operation; (3-5) After obtaining the refined single or multiple discriminant blocks, the discriminant blocks are sorted first; when the orientation is upward and downward, the discriminant blocks are sorted in descending order according to the width; when the orientation is left and right, the discriminant blocks are sorted in descending order according to the height; (3-6) The sorted discriminant block sequence is traversed, when the discriminant block meets the set condition of the concave corner, a queue method is used to construct a discriminant block queue, after the first discriminant block is subtracted, one or two remaining areas are left, then according to the coordinate information, it is judged which remaining area the following discriminant block belongs to, and then the corresponding remaining area is subtracted from the following discriminant block, until the discriminant block queue is empty, the remaining area is the missing corner, and the main body and the detection area are extended to the position of the nearest line segment along the current direction; when the discriminant block meets the set condition of the convex corner, all the discriminant blocks are the convex corner, and the detection area is extended to the position of the nearest line segment along the current direction; (3-7) Repeat step (3-6) until there is no nearest straight line according to step (3-2) in four directions.
6. The method according to claim 1, wherein, In step (4), the main body center point coordinate is calculated as follows: (4-1) The main body center point coordinate is calculated according to the last main body coordinate information; Wherein, [x lt ,y lt ] is the left upper corner coordinate point of the main body, [x rb ,y rb ] is the right lower corner coordinate point of the main body.
7. The method according to claim 1, wherein, In step (5), whether the convex corner or the concave corner is merged is one of the following conditions: The concave corner block or the convex corner block is connected; The distance between the concave corner block or the convex corner block is different by a set threshold; The two convolution operations on the two binary images using the custom convolution kernel are as follows: (5-1) Generate two binary images with the same size as the rough contour image, and the pixel value is all 0; (5-2) Draw the convex corner contour and the concave corner contour into the two binary images respectively using the method of opencv library, and fill the pixels inside the contour with 255; (5-3) For horizontal and vertical relationships, use the preset horizontal fusion convolution kernel and vertical fusion convolution kernel to fuse the concave corner blocks or convex corner blocks that meet the set conditions using the custom convolution kernel convolution operation of opencv library; (5-4) After obtaining the fused binary image, use the binaryzation function of opencv library to classify and convert the pixel points with pixel values other than 255 or 0 to grayscale image, and finally use the contour extraction function to extract the fused concave corner and convex corner information.
8. A house type drawing concave-convex angle determination system based on a region growing algorithm, characterized by, The contour reconstruction module, the initial dynamic region positioning module, the concave-convex corner judgment module, the main body center calculation module and the concave-convex corner fusion module are included. The contour reconstruction module is used to obtain a contour mask image with smooth edge lines, perform Hough straight line detection on the input rough outer contour mask image, retain the vertical and horizontal straight lines, retain the line segment part on the contour, remove the straight line part that is not extended, then fill the area surrounded by the straight line, and then use a specific convolution kernel to perform image processing to remove small burrs in the mask image, to obtain a reconstructed contour image with smooth edges. The initial dynamic region positioning module is configured to calculate a maximum inscribed rectangle of a reconstructed contour image as an initial main body and an initial detection area of a house type diagram, and calculate a maximum inscribed rectangle of the reconstructed contour, extract vertical and horizontal line segments of the reconstructed contour by using a Hough line detection, and sort the vertical and horizontal line segments in a left-to-right and top-to-bottom manner, respectively. The concave-convex angle determination module is configured to start from above a current detection area, and cyclically scan around the detection area in a counterclockwise direction, specifically: find a line segment closest to the detection area in a current direction, calculate a rectangle between the detection area and the closest line segment, i.e., an exploration area, find a rectangle with a pixel value of 255 in the exploration area according to the reconstructed contour, i.e., a determination block, if there are multiple determination blocks with a pixel value of 255 in the exploration area, sort the determination blocks in a descending order of length, and then determine concave-convex angles in sequence, if a length of the determination block is greater than or equal to one-third of a side corresponding to the direction of the minimum circumscribed rectangle, regard all the determination blocks as a main body, regard an area of the exploration area excluding all the determination blocks as a missing angle and save it, and expand the detection area and the main body to the closest line segment along the direction, if the length of the determination block is less than one-third of the side corresponding to the direction of the minimum circumscribed rectangle, regard all the determination blocks as convex angles and save them, and expand the detection area to the closest line segment along the direction, and finally stop traversing when there is no closest line segment in four directions of the detection area. The main body center calculation module is configured to finally obtain an accurate house type diagram main body center point coordinate according to four vertex coordinates of the last main body by analyzing and utilizing geometric properties of the rectangle. The concave-convex angle fusion module is configured to generate two binary images with the same size as the reconstructed contour image and with all values being 0, draw the convex angle contour and the missing angle contour on the two binary images, respectively, design a vertical sensing convolution kernel and a horizontal sensing convolution kernel for the task of merging similar convex angle blocks and missing angle blocks, perform two convolution operations on the two binary images using the custom convolution kernels to merge adjacent blocks, extract the blocks in the binary images, and finally merge the convex angle and missing angle contour information.
9. An electronic device, comprising: The electronic device includes: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores computer program instructions executable by the at least one processor, and the computer program instructions are executed by the at least one processor to enable the at least one processor to execute the house type diagram concave-convex angle determination method based on the region growing algorithm as claimed in any one of claims 1-7.
10. A computer-readable storage medium storing a program, characterized in that, The program is executed by the processor to implement the house type diagram concave-convex angle determination method based on the region growing algorithm as claimed in any one of claims 1-7.
Citation Information
Patent Citations
Method and device for reconstructing house type image contour and electronic equipment
CN111145293A
Automatic region division method and system, robot walking control method and system, equipment and medium
CN113744329A