Robot map rotating method based on line segment information
Technical Field
The invention relates to the technical field of intelligent robots, in particular to a robot map rotating method based on line segment information.
Background
Before moving, the mobile robot firstly maps and positions the position of the mobile robot, and then moves according to the established topographic map and the position of the mobile robot, because the initial pose of the sweeping robot is random, the map obtained by mapping cannot be ensured to be in a horizontal state visually, namely, the angle of a line segment with a longer length is horizontal or vertical, while the line segment is in a zigzag state in a non-horizontal state, if the map is not in the horizontal state visually, the robot cannot be effectively positioned during working, and the robot cannot effectively plan a route.
Disclosure of Invention
In order to solve the problems, the invention discloses a robot map rotating method based on segment information, which is characterized in that the rotating angle of a map is quickly acquired through the segment information on the map, the map is rotated to be in a horizontal state visually, and the robot can quickly and accurately position and plan a route in the working process. The specific technical scheme is as follows:
a robot rotating map method based on line segment information comprises the following steps: s1: carrying out binarization processing on the grid map to obtain a binarization map, and marking pixels where obstacles and non-obstacles are located in the binarization map; s2: acquiring the gradient of a pixel where the barrier edge is located according to the marking information, and acquiring the direction of the barrier edge of the pixel according to the direction of the gradient; s3: acquiring a plurality of pixel sets according to the gradient of the pixels and the direction of the edge of the obstacle, and then acquiring line segments from each pixel set; s4: selecting an optimal line segment from the line segments, obtaining a rotation angle according to the optimal line segment, and rotating the grid map according to the rotation angle. Compared with the prior art, the method and the device have the advantages that the line segments are extracted according to the gradient of the pixel where the edge of the obstacle is located in the binary map and the edge direction, then the optimal line segment is selected from the line segments, the map is rotated according to the optimal line segment, the map is in a horizontal state visually, and the robot can be quickly and accurately positioned and plan a route in the working process.
Further, in step S1, the grid map is a probability grid map, and pixels where the obstacle and the non-obstacle are located in the binary map are respectively marked as a maximum value and a minimum value of a map storage format, so that the obstacle edge generates a gradient in value. The grid map is binarized and marked, so that the map is simplified and simple in calculation.
Further, in step S2, before acquiring the gradient of the pixel where the edge of the obstacle is located, the image is subjected to gaussian blur to enhance the edge feature. The edge characteristics are enhanced through Gaussian blur, and the accuracy of data is improved.
Further, in step S2, the obtaining the gradient of the pixel where the obstacle edge is located includes the following steps: and determining the position of the pixel where the edge of the obstacle is located on the grid map, and performing volume integration on the upper, lower, left and right four pixels of the pixel to obtain the gradient of the pixel where the edge of the obstacle is located.
Further, after the gradient of the pixel where the obstacle edge is located is obtained, the direction of the gradient is obtained through an arctangent function, and then the direction of the obstacle edge is obtained according to the direction of the gradient; wherein the direction of the gradient is perpendicular to the direction of the obstacle edge.
Further, in step S3, acquiring several pixel sets according to the gradient of the pixels and the direction of the obstacle edge includes the following steps: and sorting the gradients exceeding the set threshold value from large to small, and then, starting from the pixel where the maximum gradient is located, taking the pixel as the center, and forming a pixel set by the pixels within the set range and with the angle between the directions of the edges of the obstacles within the set value to obtain a plurality of pixel sets. The pixels are sorted from large to small to form a set, so that the condition of missing pixels is prevented.
Further, in step S3, the step of obtaining the line segment from the pixel set includes the following steps: and acquiring the minimum external rectangle of the pixel set, then extracting a line segment obtained by intersecting the minimum external rectangle with the central axis of the longer rectangle, and recording the end point and angle information of the line segment.
Further, the method for obtaining the minimum circumscribed rectangle includes that the edge direction of each pixel in the pixel set is weighted and averaged by taking the distance as an inverse proportion to obtain the length direction of the minimum circumscribed rectangle, then parallel lines are made in the length direction of the minimum circumscribed rectangle to obtain the length of the minimum circumscribed rectangle, and the length of the minimum circumscribed rectangle is made as a vertical line to obtain the width of the minimum circumscribed rectangle.
Further, in step S4, the selecting the optimal line segment includes the following steps: step S11: selecting one line segment from the obtained line segments as a current reference edge, obtaining the length of the current reference edge, and entering step S12; step S12: projecting the rest N-1 line segments in the direction of the current reference edge to obtain N-1 first projection values corresponding to the rest N-1 line segments, projecting the rest N-1 line segments in the direction of ninety degrees from the current reference edge to obtain N-1 second projection values corresponding to the rest N-1 line segments, and entering step S13; step S13: taking the product of the larger value of the first projection value and the second projection value corresponding to the same line segment and the first preset parameter b as a third projection value corresponding to the line segment, obtaining N-1 third projection values corresponding to the rest N-1 line segments, and entering step S14; step S14: calculating the sum of the length of the current reference edge and the N-1 third projection values corresponding to the rest of N-1 line segments, taking the sum of the length of the current reference edge and the N-1 third projection values corresponding to the rest of N-1 line segments as the total length of the line segment corresponding to the current reference edge, and entering the step S15; step S15: repeating the steps S11 to S15 until the N line segments are traversed, acquiring the total length of the N line segments corresponding to the N line segments, and entering the step S16, and the step S16: and selecting the line segment corresponding to the maximum value in the total length of the N line segments as the optimal line segment. By comparison, the optimal line segment selected from the plurality of line segments is more accurate.
Further, in step S4, the obtaining of the rotation angle includes: and calculating the minimum included angle between the optimal line segment and the x axis or the y axis, wherein the included angle is the rotation angle of the map.
Drawings
Fig. 1 is a flowchart of a method for rotating a map by a robot based on line segment information according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be described and illustrated below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the present application. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments provided in the present application without any inventive step are within the scope of protection of the present application.
Referring to fig. 1, a robot rotation map method based on line segment information includes the following steps: s1: carrying out binarization processing on the grid map to obtain a binarization map, and marking pixels where obstacles and non-obstacles are located in the binarization map; s2: acquiring the gradient of a pixel where the barrier edge is located according to the marking information, and acquiring the direction of the barrier edge of the pixel according to the direction of the gradient; s3: acquiring a plurality of pixel sets according to the gradient of the pixels and the direction of the edge of the obstacle, and then acquiring line segments from each pixel set; s4: selecting an optimal line segment from the line segments, obtaining a rotation angle according to the optimal line segment, and rotating the grid map according to the rotation angle. Compared with the prior art, the method and the device have the advantages that the line segments are extracted according to the gradient of the pixel where the edge of the obstacle is located in the binary map and the edge direction, then the optimal line segment is selected from the line segments, the map is rotated according to the optimal line segment, the map is in a horizontal state visually, and the robot can be quickly and accurately positioned and plan a route in the working process.
As an example, in step S1, the grid map is a probability grid map, and pixels where the obstacle and the non-obstacle are located in the binary map are respectively marked as a maximum value and a minimum value in a map storage format, so that the obstacle edge generates a gradient in value. The grid map is binarized and marked, so that the map is simplified and simple in calculation. In step S2, before the gradient of the pixel where the edge of the obstacle is located is obtained, the image is subjected to gaussian blur to enhance the edge feature. The edge characteristics are enhanced through Gaussian blur, and the accuracy of data is improved. In step S2, the step of obtaining the gradient of the pixel where the obstacle edge is located includes the following steps: and determining the position of the pixel where the edge of the obstacle is located on the grid map, and performing volume integration on the upper, lower, left and right four pixels of the pixel to obtain the gradient of the pixel where the edge of the obstacle is located. After the gradient of a pixel where an obstacle edge is located is obtained, obtaining the direction of the gradient through an arctangent function, and then obtaining the direction of the obstacle edge according to the direction of the gradient; wherein the direction of the gradient is perpendicular to the direction of the obstacle edge. The image gradient is the rate of change of a certain pixel of an image in the X and Y directions (compared with adjacent pixels), is a two-dimensional vector and consists of 2 components, and the change of the X axis and the change of the Y axis. Where the change in the X-axis is the pixel value to the right of the current pixel (X plus 1) minus the pixel value to the left of the current pixel (X minus 1). Similarly, the change in the Y-axis is the pixel value below the current pixel (Y plus 1) minus the pixel value above the current pixel (Y minus 1). The 2 components are calculated to form a two-dimensional vector, and the image gradient of the pixel is obtained. The gradient angle can be obtained by taking the inverse tangent arctan.
As an example, in step S3, acquiring several pixel sets according to the gradient of the pixels and the direction of the obstacle edge includes the following steps: and sorting the gradients exceeding the set threshold value from large to small, and then, starting from the pixel where the maximum gradient is located, taking the pixel as the center, and forming a pixel set by the pixels within the set range and with the angle between the directions of the edges of the obstacles within the set value to obtain a plurality of pixel sets. The pixels are sorted from large to small to form a set, so that the condition of missing pixels is prevented.
As an embodiment, in step S3, the step of obtaining the line segment from the pixel set includes the following steps: the minimum circumscribed rectangle of the pixel set is obtained, then a line segment obtained by intersecting the minimum circumscribed rectangle with the central axis of the longer rectangle is extracted, the line segment is a connecting line between two wide middle points of the minimum circumscribed rectangle, and the end points and the angle information of the line segment are recorded. The method for obtaining the minimum circumscribed rectangle comprises the steps of weighting and averaging the edge direction of each pixel in the pixel set by taking the distance as an inverse proportion to obtain the length direction of the minimum circumscribed rectangle, then making parallel lines in the length direction of the minimum circumscribed rectangle to obtain the length of the minimum circumscribed rectangle, and making a vertical line in the length direction of the minimum circumscribed rectangle to obtain the width of the minimum circumscribed rectangle. The minimum circumscribed rectangle can also be obtained by a minareaRect function, and various methods for obtaining the minimum circumscribed rectangle exist, and are prior art, and are not described in detail herein. The end points of the line segments are the wide middle points of the minimum circumscribed rectangle, corresponding coordinates can be directly obtained according to the positions of the line segments on the probability grid map, the line segments are parallel to the length of the minimum circumscribed rectangle, and the angle information is the direction of the length of the minimum circumscribed rectangle.
As an example, in step S4, the selecting the optimal line segment includes the following steps: step S11: selecting one line segment from the obtained line segments as a current reference edge, obtaining the length of the current reference edge, and entering step S12; step S12: projecting the rest N-1 line segments in the direction of the current reference edge to obtain N-1 first projection values corresponding to the rest N-1 line segments, projecting the rest N-1 line segments in the direction of ninety degrees from the current reference edge to obtain N-1 second projection values corresponding to the rest N-1 line segments, and entering step S13; step S13: taking the product of the larger value of the first projection value and the second projection value corresponding to the same line segment and the first preset parameter b as a third projection value corresponding to the line segment, obtaining N-1 third projection values corresponding to the rest N-1 line segments, and entering step S14; step S14: calculating the sum of the length of the current reference edge and the N-1 third projection values corresponding to the rest of N-1 line segments, taking the sum of the length of the current reference edge and the N-1 third projection values corresponding to the rest of N-1 line segments as the total length of the line segment corresponding to the current reference edge, and entering the step S15; step S15: repeating the steps S11 to S15 until the N line segments are traversed, acquiring the total length of the N line segments corresponding to the N line segments, and entering the step S16, and the step S16: and selecting the line segment corresponding to the maximum value in the total length of the N line segments as the optimal line segment. By comparison, the optimal line segment selected from the plurality of line segments is more accurate. The method mainly aims to obtain the line segments representing the direction of the map, and the length of the line segments is as long as possible, and the number of the line segments close to the direction of the line segments is as large as possible.
As one example, in step S4, the obtaining of the rotation angle includes: and calculating the minimum included angle between the optimal line segment and the x axis or the y axis, wherein the included angle is the rotation angle of the map. And calculating the included angle between the optimal line segment and the x axis when the included angle between the optimal line segment and the x axis is smaller than the included angle between the optimal line segment and the y axis, and rotating the corresponding angle to enable the optimal line segment to be parallel to the x axis, thereby completing the rotation of the map. Similarly, if the included angle between the optimal line segment and the y axis is smaller than the included angle between the optimal line segment and the x axis, the included angle between the optimal line segment and the y axis is calculated, and corresponding rotation is performed.
The features of the above embodiments may be arbitrarily combined, and for the sake of brevity, all possible combinations of the above embodiments are not described, but should be considered as within the scope of the present specification as long as there is no contradiction between the combinations of the features.
The above embodiments only express a few embodiments of the present invention, and the description thereof is specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application.