Summary of the invention
For the problems referred to above, the present invention aims to provide a kind of region segmentation method based on clean robot, which solves the problem that existing clean robot needs repeatedly to build figure, increases substantially the cleaning efficiency of clean robot.
Technical scheme provided by the invention is as follows:
Based on a region segmentation method for clean robot, described region segmentation method specifically comprises the following steps:
S1 builds figure to cleaning ambient, reads in grating map data;
S2 carries out pre-service to described grating map, obtains pre-service grating map f;
S3 is according to default rotation angle range and default anglec of rotation interval d
θ, the number of revolutions N of Calculation Basis grating map; Wherein, in first time rotary course, described pre-service grating map f is reference grid map;
S4 loop initialization parameter k;
S5 judges that whether preset map segmentation condition meets, if meet, then terminates map segmentation; If do not meet, then jump to step S6;
S6 judges whether cycle index k is less than described number of revolutions N, if be less than, then jumps to step S7; If do not meet, then jump to step S10;
S7 rotates k × d to reference grid map
θdegree obtains rotating grating map f
k;
S8 is to rotation grating map f
kcarry out map segmentation respectively in the horizontal direction and the vertical direction, and preserve respectively in the horizontal direction with all map subregions of splitting in vertical direction;
K is added 1 and jumps to step S6 by S9;
S10 Calculation Basis grating map carries out map subregion optimum in all map subregions rotating for N time and obtain after the segmentation of N wheel map;
S11 calculates the principal direction of the map subregion of described optimum, preserves the data of the map subregion of described optimum and in reference grid map, deletes the map subregion of described optimum;
S12 resets described loop parameter k, jumps to step S5.
Preferably, in step S2, pre-service is carried out to described grating map, obtains, in pre-service grating map f, specifically comprising the following steps:
S21 carries out pixel value mapping to the grating map read in, and obtains mapping grating map;
S22 uses the first predetermined threshold value K to carry out binaryzation to described mapping grating map, obtains binaryzation grating map;
S23 actionradius is that the circular configuration unit of R corrodes described binaryzation grating map, obtains corroding grating map;
S24 by described corrosion grating map with clean robot in any one direction all disjunct barrier region delete, obtain four connection grating maps;
S25 actionradius is that the circular configuration unit of R expands to described four connection grating maps, obtains expansion grating map;
S26 calculates the catercorner length of the minimum enclosed rectangle of all barrier regions in described expansion grating map respectively, and barrier region catercorner length being less than the second predetermined threshold value L is deleted;
In the grating map that S27 uses rectangular window to obtain step S26, irrelevant barrier region carries out cutting.
In the technical program, here four are communicated with grating map specifically refers to: the regional ensemble that clean robot can reach in any one direction;
Preferably, in step S23 and step S25, radius is the maximum inscribed circle radius that radius R in R circular configuration unit is specially clean robot chassis.
Preferably, in step S3, according to default rotation angle range and default anglec of rotation interval d
θ, in the number of revolutions N of Calculation Basis grating map:
Towards counterclockwise rotating centered by the cornerwise intersection point of reference grid map, and default rotation angle range is 0 ~ 90 °;
Adjacent two width rotate grating map f
kbetween angle intervals be described default anglec of rotation interval d
θ.
Preferably, in step s 5, described default map segmentation condition is specially: when the area of all map subregions be partitioned in the segmentation of front-wheel map is all less than the 3rd predetermined threshold value T.
Preferably, in step S7, k × d is rotated to reference grid map
θdegree obtains rotating grating map f
kin, specifically comprise the following steps:
S71 determines to rotate grating map f according to the first height value of reference grid map and the first width value
kthe second height value and the second width value;
S72 is according to described first height value, the first width value, the second height value, the second width value and anglec of rotation k × d
θthe pixel obtained in reference grid map is rotating grating map f
kthe coordinate figure of middle pixel, to set up the pixel grating map f rear with rotation in reference grid map
kthe mapping relations of middle pixel coordinate, complete the rotation of reference grid map.
Preferably, in step S8, to rotation grating map f
kcarry out map segmentation respectively in the horizontal direction and the vertical direction, and preserve respectively in the horizontal direction with in all map subregions of splitting in vertical direction, specifically comprise the following steps:
S81 is to rotation grating map f
kcarry out map segmentation in the horizontal direction, and preserve all map subregions split;
S811 calculated level direction is clipped in the idle line segment between the adjacent stain of this row two in every a line, and records every starting point of bar line segment and the coordinate of terminal respectively;
S812 judges the neighborhood that arbitrary neighborhood two line is intersegmental and finds out the line segment aggregate that can be merged into region;
S813, according to the relation that can merge between adjacent segments, is merged into new map subregion;
S82 is to rotation grating map f
kcarry out map segmentation in vertical direction, and preserve all map subregions split;
S821 calculating vertical direction is clipped in the idle line segment between the adjacent stain of this row two in every a line, and records every starting point of bar line segment and the coordinate of terminal respectively;
S822 judges the neighborhood that arbitrary neighborhood two line is intersegmental and finds out the line segment aggregate that can be merged into region;
S823, according to the relation that can merge between adjacent segments, is merged into new map subregion.
Preferably, in step S812, judge the neighborhood that arbitrary neighborhood two line is intersegmental and find out can be merged in the line segment aggregate in region, specifically comprise the following steps:
If any two line segments coordinate in the horizontal direction has overlap, then judge that these two line segments are as adjacent segments, and the Duplication of these two line segments of coincidence length computation according to these two line segments;
If the Duplication of these two line segments is greater than default anti-eclipse threshold, then these two line segments are merged;
In step S822, judge the neighborhood that arbitrary neighborhood two line is intersegmental and find out can be merged in the line segment aggregate in region, specifically comprise the following steps:
If any two line segments coordinate in vertical direction has overlap, then judge that these two line segments are as adjacent segments, and the Duplication of these two line segments of coincidence length computation according to these two line segments;
If the Duplication of these two line segments is greater than default anti-eclipse threshold, then these two line segments are merged.
Preferably, in step S10, Calculation Basis grating map carries out, in map subregion optimum in all map subregions rotating for N time and obtain after the segmentation of N wheel map, specifically comprising the following steps:
S101 calculates all areas of map subregion and the catercorner length of minimum enclosed rectangle that obtain after the segmentation of front-wheel map terminates;
S102 is normalized each area of map subregion and the catercorner length of minimum enclosed rectangle;
S103 gives a mark to each map subregion respectively according to the area of each map subregion after the normalization obtained in the ratio in the catercorner length summation of catercorner length minimum enclosed rectangle in all map subregions of the ratio of the area of each map subregion in all map subregion area summations, each map subregion minimum enclosed rectangle, step S102 and the catercorner length of minimum enclosed rectangle;
S104 calculates the map subregion of the highest map subregion of marking as optimum using splitting when front-wheel map in all map subregions obtained.
Preferably, in step S11, calculate the principal direction of the map subregion of described optimum, preserve the data of the map subregion of described optimum and delete in reference grid map in the map subregion of described optimum, specifically comprising the following steps:
S111 calculates the deflection of optimum map subregion according to the anglec of rotation of reference grid map;
The pixel value of pixel corresponding in reference grid map for the map subregion of this optimum sets to 0 by S112, completes the optimum deletion of map subregion in reference grid map.
By the region segmentation method based on clean robot provided by the invention, following at least one beneficial effect can be brought:
In the present invention, it allows clean robot build figure to cleaning ambient at the beginning and reads in corresponding grating map data, then pre-service and map segmentation is carried out, afterwards the map subregion split is analyzed, like this, the overall consciousness that allowed clean robot have, solves the problem that existing clean robot needs repeatedly to build figure, increases substantially the sweeping efficiency of clean robot;
Have again, in the present invention, the grating map read in is carried out to the pretreatment operation such as burn into expansion, eliminate the idle burr in grating map border, and to delete with clean robot all disconnected barrier region on any one direction, so namely, eliminate the region that clean robot can not arrive, obtain the accessible barrier region of clean robot, substantially increase the sweeping efficiency of clean robot equally:
In addition, in the present invention, map subregion optimum in all map subregions is confirmed while clean robot is partitioned into map subregion, and obtain the principal direction of the map subregion of this optimum, like this, clean robot can clean along this principal direction, improves the sweeping efficiency of clean robot;
Finally, in the present invention, we preset anglec of rotation interval d to each process
θthe rotation grating map f obtained after rotation
kall split, and each segmentation is not subject to the impact of map angle of inclination and region shape, strengthens the confidence level of region segmentation method provided by the invention.
Embodiment
In order to be illustrated more clearly in the embodiment of the present invention or technical scheme of the prior art, contrast accompanying drawing is illustrated the specific embodiment of the present invention below.Apparently, accompanying drawing in the following describes is only some embodiments of the present invention, for those of ordinary skill in the art, under the prerequisite not paying creative work, other accompanying drawing can also be obtained according to these accompanying drawings, and obtain other embodiment.
Be illustrated in figure 1 clean robot 101 structural representation in the present invention, as can be seen from the figure, clean robot front-wheel 104, clean robot off hind wheel 102 and clean robot left rear wheel 103 is comprised at this clean robot 101, whole frame in this structural representation is clean robot chassis size, and wherein R (unit: pixel) represents the maximum inscribed circle radius on clean robot chassis.In a particular embodiment, the laser radar that clean robot 101 uses model to be UTM-30LX realizes building figure to cleaning ambient, the figure resolution of building of this laser radar is 5cm, the 5cm in the corresponding cleaning ambient of width of each pixel in the grating map namely read in; In addition, in the present embodiment, the chassis length 150cm of clean robot 101, width 50cm, thus, the value of building maximum inscribed circle radius in the grating map after figure is R=(50/5)/2=5 pixel.Certainly, in other embodiments, the laser radar of other models can be adopted, clean robot 101 also can adopt chassis length and the width of other sizes, we are here not specifically limited, as long as can realize object of the present invention, are all included in content of the present invention.
Be illustrated in figure 2 the region segmentation schematic flow sheet based on above-mentioned clean robot 101 in the present invention, specifically, this region segmentation method comprises the following steps:
S1 builds figure to cleaning ambient, reads in grating map data.Specifically, in this step, the laser radar in clean robot 101 is adopted to realize building figure to around cleaning ambient, and the pixel value in the grating map read in comprises 0,254 and 255, wherein, 0 represents clear area, 254 represent barrier region, and 255 represent zone of ignorance.
S2 carries out pre-service to grating map, obtains pre-service grating map f.Specifically, further comprising the steps in this step:
S21 carries out pixel value mapping to the grating map read in, and obtains mapping grating map.Be in embodiment the schematic diagram mapping grating map as shown in Figure 3, specifically, in this mapping process, pixel value in grating map after mapping comprises 0,220 and 254, and wherein, 0 represents barrier region, 220 represent zone of ignorance, and 254 represent clear area.
S22 uses the first predetermined threshold value K to carry out binaryzation to mapping grating map, obtains binaryzation grating map.Specifically, in this step, binaryzation grating map adopts g
binarizationrepresent, binarization is as follows:
Wherein (i, j) represents binaryzation grating map g
binarizationin a certain pixel, in this pixel, horizontal ordinate is i, and ordinate is j.As can be seen from the above description, when the pixel value mapping a certain pixel in grating map is greater than the first predetermined threshold value K, then after binaryzation, the pixel value of this pixel is changed to 255; When the pixel value mapping a certain pixel in grating map is less than the first predetermined threshold value K, then after binaryzation, the pixel value of this pixel is changed to 0; Thus, at binaryzation grating map g
binarizationin only have two kinds of pixel values: 255 and 0, wherein, 255 represent clear area, and 0 represents barrier region.In a particular embodiment, the first predetermined threshold value K is chosen to be 230, then uses above-mentioned binarization method to carry out binaryzation grating map that binaryzation obtains as shown in Figure 4 to mapping grating map in Fig. 3.Certainly, here, we do not limit the first predetermined threshold value K equally, as long as can realize object of the present invention, as being chosen to be 225,235 etc., are all included in content of the present invention.
S23 actionradius is that the circular configuration unit of R is to binaryzation grating map g
binarizationcorrode, obtain corroding grating map.Specifically, in this step, radius R is the maximum inscribed circle radius on above-mentioned clean robot chassis, and we know in the embodiment in figure 1, and radius R is 5 pixels; Therefore in this embodiment, we adopt radius to be that the circular configuration unit of 5 pixels is to the binaryzation grating map g obtained in step S22
binarizationcorrode.Further, to binaryzation grating map g
binarizationcarry out corrosion to comprise the following steps:
S231 is at binaryzation grating map g
binarizationsurrounding boundary carry out mirror-extended.Specifically, extension width is selected but is not limited to above-mentioned radius R; Here we select above-mentioned radius R to be extension width, are the carrying out for the ease of following etching operation.In concrete the present embodiment, assuming that the grating map width read is 640 pixels, highly is 480 pixels, then actionradius to be the width of the grating map obtained after the circular configuration unit of 5 pixels expands be W1=650 pixel, be highly H1=490 pixel.
S232 adopts radius to be that R circular configuration unit corrodes the binaryzation grating map after above-mentioned expansion.Specifically, assuming that the width of binaryzation grating map after expansion is W1, highly is H1; Etching operation is carried out in perform region then in binaryzation grating map after expansion, here perform region to be specially in the binaryzation grating map after above-mentioned expansion horizontal ordinate at [R, H1-R] scope, ordinate is in the region of the scope of [R, W1-R].More particularly, in the process of corrosion, the center of circle of circular configuration unit is successively placed on each pixel in perform region; If entirely for pixel value is the pixel of 255 in the region that circular configuration unit covers, then the result of corroding output is 255, otherwise the result that corrosion exports is 0, the image g after corrosion
corrosionrepresent.In addition, as can be seen from the process of corrosion, after corrosion, the size of grating map is still the size of grating map before corrosion; As in step S231, the width of grating map after expansion is W1=650 pixel, highly is H1=490 pixel, then the width of the grating map after step S232 corrosion and be highly still W2=650 pixel, be highly H2=490 pixel.
S24 will corrode grating map g
corrosionin with clean robot 101 in any one direction all disjunct barrier region delete, namely delete isolated region, obtain four connection grating map g
deleting.
S25 actionradius is that the circular configuration unit of R is communicated with grating map g to four
deletingexpand, obtain expansion grating map.Specifically, radius R is here similarly the maximum inscribed circle radius on above-mentioned clean robot 101 chassis, is specifically 5 pixels in an embodiment.More particularly, the concrete steps that four connection grating maps after expansion expand are comprised:
S251 is communicated with grating map g four
deletingsurrounding boundary carry out mirror-extended.With in step S231 similarly, extension width is here selected but is not limited to above-mentioned radius R, is convenient to the carrying out of following expansive working.In concrete the present embodiment, assuming that the grating map width read is 640 pixels, highly is 480 pixels, then actionradius to be the width of the grating map obtained after the circular configuration unit of 5 pixels expands be W3=650 pixel, be highly H3=490 pixel.
S252 adopts radius to be that R circular configuration unit expands to four connection grating maps after above-mentioned expansion, obtains expansion grating map.Specifically, assuming that four after expansion is communicated with the width of grating maps is W3, highly is H3; Then carry out expansive working in four perform regions being communicated with in grating maps after expansion, here perform region is specially four after above-mentioned expansion and is communicated with in grating maps horizontal ordinate at [R, H3-R] scope, ordinate is in the region of the scope of [R, W3-R].More particularly, in the process expanded, the center of circle of circular configuration unit is successively placed on each pixel in perform region; If entirely for pixel value is the pixel of 0 in the region that circular configuration unit covers, then the result exported that expands is 0, otherwise the result exported that expands is 255, expansion grating image g
inflationrepresent.In addition, as can be seen from the process expanded, after expanding, the size of grating map is still the size of grating map before expansion; As in step S251, the width of grating map after expansion is W3=650 pixel, highly is H3=490 pixel, then the width of the grating map after step S252 expands and be highly still W4=650 pixel, be highly H5=490 pixel.
S26 calculate expansion respectively after four be communicated with grating map (i.e. expansion grating map g
inflation) in the catercorner length of minimum enclosed rectangle of all barrier regions, barrier region catercorner length being less than the second predetermined threshold value L is deleted.Specifically, in this step, expansion grating map g
inflationin all four be communicated with barrier regions after; Calculate each barrier region minimum enclosed rectangle in the horizontal direction, the minimum enclosed rectangle specifically said here refers to the minimum boundary rectangle of area; Then, the catercorner length of the minimum enclosed rectangle that each barrier region calculated is corresponding is using the length as current barrier region; Finally, respectively the length of each barrier region and the second predetermined threshold value L are compared, if the length of current barrier region is less than the second predetermined threshold value L, current barrier region will be deleted, otherwise retain current barrier region.In concrete enforcement, the second predetermined threshold value L is set as the twice of chassis maximum inscribed circle radius R, e.g., in above-mentioned specific embodiment, radius R is chosen to be 5 pixels, then the second predetermined threshold value L is set as 10 pixels here.
In the grating map that S27 uses rectangular window to obtain step S26, irrelevant barrier region carries out cutting.Specifically, in this step, through the grating map of step S21 ~ step S26 process, there is a large amount of irrelevant barrier region in the surrounding of clear area, therefore needs to carry out cutting to it.Here, we adopt a rectangular window to carry out cutting to map, and this rectangular window selects each barrier region minimum enclosed rectangle in the horizontal direction (with similar in step S26), this minimum enclosed rectangle same refers to the minimum boundary rectangle of area, preserves the data of the left upper apex coordinate of rectangle frame, the width of rectangle frame and height and rectangle frame interior zone after cutting.Grating map after using step S23 ~ step S27 to process the binaryzation grating map shown in Fig. 4 as shown in Figure 5.
S3 is according to default rotation angle range and default anglec of rotation interval d
θ, the number of revolutions N of Calculation Basis grating map; Wherein, in first time rotary course, described pre-service grating map f is reference grid map.Specifically, in this step, carry out rotating (certainly, also can rotate towards clockwise direction, determine according to actual conditions) towards counter clockwise direction centered by the cornerwise intersection point of reference grid map; And above-mentioned default rotation angle range is 0 ~ 90 ° by we.In a particular embodiment, default anglec of rotation interval d is used
θin rotation angle range, carry out N time to reference grid map rotate, each rotation obtains rotating grating map f
k, can find out, adjacent two width rotate grating map f
kbetween angle intervals for preset anglec of rotation interval d
θ.In addition, we are described above-mentioned reference grid map, in the present invention, above-mentioned N rotation all with reference grid map for benchmark rotates, but each rotation is all pre-service grating map f after the map subregion deleting the optimum that the post analysis through over-rotation, map segmentation obtains is reference grid map, furthermore, in step s3, first time rotate with pre-service grating map f for benchmark (here using pre-service grating map f for reference grid map as rotate before grating map) rotate 1 × d
θdegree obtains the first rotation grating map; And then rotate grating map to obtain first to carry out map segmentation and preserve splitting all map subregions of obtaining in the horizontal direction with in vertical direction; Map subregion optimum in map subregions all in this map cutting procedure is obtained with post analysis; The last map subregion deleting this optimum in pre-service grating map f obtains the first process grating map.Afterwards, second time rotate with rotates for the first time obtain first process grating map for benchmark (here using first process grating map for reference grid map as rotation before grating map) rotate 2 × d
θdegree, equally map segmentation is carried out to the grating map after rotation and obtain map subregion optimum in this map segmentation, the map subregion deleting this optimum again in the first process grating map obtains the second process grating map, afterwards with this second process grating map for benchmark (here using the first process grating map for reference grid map is as the grating map before rotating) rotates 3 × d
θspend the last map subregion deleting the optimum this time obtained through map segmentation and analysis in the second grating map again and obtain the 3rd process grating map, by that analogy, until have passed through N rotation, the condition met in step S6 terminates map segmentation, can find out, in this process, each reference grid map is all different, and each rotation all deletes optimum map subregion in original reference grid map, like this, finally completes the region segmentation of whole grating map.Have again, in the process rotated, assuming that the catercorner length of grating map (reference grid map) before rotating is len (unit: pixel), then the height of postrotational grating map and width are all len, e.g., in a particular embodiment, if the width of pre-service grating map f is 303 pixels, be highly 267 pixels, then len=403 pixel, then the height and the width that pass through first time postrotational grating map are all 403 pixels; In addition, if preset anglec of rotation interval d
θbe 1 degree, the anglec of rotation is 90 degree, then can obtain out number of revolutions N=90/1=90.Certainly, in other embodiments, rotation angle range and default anglec of rotation interval d
θother value can be selected, determine as the case may be.
S4 loop initialization parameter k; Specifically, 0 is set to by loop parameter k.
S5 judges that whether preset map segmentation condition meets, if meet, then terminates map segmentation; If do not meet, then jump to step S6.Specifically, in this step, preset map segmentation condition to be specially: when the area of all map subregions be partitioned in the segmentation of front-wheel map is all less than the 3rd predetermined threshold value T; Do not meet, reenter the cycling of step S6 ~ step 11, until all map subregions that map splits meet preset map segmentation condition.Here, we do not limit the 3rd predetermined threshold value T, determine according to actual conditions.
S6 judges whether cycle index k is less than number of revolutions N, if be less than, then jumps to step S7; If do not meet, then jump to step S10;
S7 rotates k × d to reference grid map
θdegree obtains rotating grating map f
k.Specifically, in step, specifically comprise the following steps:
S71 determines to rotate grating map f according to the first height value of reference grid map and the first width value
kthe second height value and the second width value, specifically, in this step, the first height value and the first width value to be respectively in reference grid map height height and width width, and the second height value and the second width value are respectively and rotate grating map f
kheight new_width and width new_height.In a particular embodiment, assuming that the height of reference grid map is height, width is width (unit all: pixel), then can obtain height new_width and the width new_height of postrotational grating map according to following formula:
half_height=height/2.0
half_width=width/2.0
half_new_width=half_new_height=new_width/2.0
Wherein, half_height and half_width is respectively the half of reference grid map (the front grating map of rotation) height and width, new_width and new_height is respectively postrotational grating map and (rotates grating map f
k) height and width, half_new_width and half_new_height is respectively and rotates grating map f
kheight and the half of width.
In a particular embodiment, assuming that the height of reference grid map is height=267 pixel, width is width=303 pixel, then this height and width is brought into above formula and can obtain the height of postrotational grating map and width is all 403 pixels:
S72 is according to the first height value, the first width value, the second height value, the second width value and anglec of rotation k × d
θthe pixel obtained in reference grid map is rotating grating map f
kthe coordinate figure of middle pixel, to set up the pixel grating map f rear with rotation in reference grid map
kthe mapping relations of middle pixel coordinate, complete the rotation of reference grid map.Specifically, in this step, assuming that, (i
1, j
1) for rotating grating map f
kin certain pixel coordinate, (i
0, j
0) be (i
1, j
1) pixel coordinate in corresponding reference grid map, then can obtain pixel (i in reference grid map according to following rotation formula
0, j
0) and rotate grating map f
kmiddle pixel (i
1, j
1) between basic mapping relations:
i
0=(i
1-half_new_height)*cos(k×d
θ)-(j
1-half_new_width)*sin(k×d
θ)+half_height
J
0=(j
1-half_new_width) * cos (k × d
θ)+(i
1-half_new_height) * sin (k × d
θ)+half_width and then, to pixel (i in reference grid map
0, j
0) carry out rounding up and according to following formula to the pixel (i after rounding up
0, j
0) revise:
Now establish pixel (i in reference grid map completely
0, j
0) and rotate grating map f
kmiddle pixel (i
1, j
1) between mapping relations, with the rotation of this full baseline grating map.
S8 is to rotation grating map f
kcarry out map segmentation respectively in the horizontal direction and the vertical direction, and preserve respectively in the horizontal direction with all map subregions of splitting in vertical direction.Specifically in this step, to rotation grating map f
kcarry out map segmentation respectively in the horizontal direction and the vertical direction, and preserve respectively in the horizontal direction with in all map subregions of splitting in vertical direction, specifically comprise the following steps:
S81 is to rotation grating map f
kcarry out map segmentation in the horizontal direction, and preserve all map subregions split, specifically comprise the following steps:
S811 calculated level direction is clipped in the idle line segment between the adjacent stain of this row two in every a line, and records every starting point of bar line segment and the coordinate of terminal respectively.
S812 judges the neighborhood that arbitrary neighborhood two line is intersegmental and finds out the line segment aggregate that can be merged into region.Specifically, in this step, specifically comprise the following steps:
If any two line segments coordinate in the horizontal direction has overlap, then judge that these two line segments are as adjacent segments, and the Duplication of these two line segments of coincidence length computation according to these two line segments, if the Duplication of these two line segments is greater than default anti-eclipse threshold, then these two line segments are merged.
In a particular embodiment, assuming that in two adjacent segments, the length of the first line segment is L1, and the second line segment length is L2, and two line segment overlap lengths are L
common, then:
overlapping_rate=2*L
common/(L
1+L
2)
Wherein, overlapping_rate is the Duplication between adjacent segments, specifically in this embodiment, this Duplication overlapping_rate_thresh=0.7, if then overlapping_rate > overlapping_rate_thresh, then two line segments are for can merge line segment, otherwise can not merge.
S813, according to the relation that can merge between adjacent segments, is merged into new map subregion.
After S82 has carried out map segmentation to horizontal direction, immediately to rotation grating map f
kcarry out map segmentation in vertical direction, and preserve all map subregions split, specifically comprise the following steps:
S821 calculating vertical direction is clipped in the idle line segment between the adjacent stain of this row two in every a line, and records every starting point of bar line segment and the coordinate of terminal respectively.
S822 judges the neighborhood that arbitrary neighborhood two line is intersegmental and finds out the line segment aggregate that can be merged into region.Specifically, in this step, judge the neighborhood that arbitrary neighborhood two line is intersegmental and find out can be merged in the line segment aggregate in region, specifically comprise the following steps:
If any two line segments coordinate in vertical direction has overlap, then judge that these two line segments are as adjacent segments, and the Duplication of these two line segments of coincidence length computation according to these two line segments; If the Duplication of these two line segments is greater than default anti-eclipse threshold, then these two line segments are merged.In a particular embodiment, determination methods is identical with step S812, does not specifically repeat.
S823, according to the relation that can merge between adjacent segments, is merged into new map subregion.Use institute in step S8 to carry out rotation 0 degree to reference grid map in steps for the pre-service grating map shown in Fig. 5 and split schematic diagram as shown in Fig. 6 (a), 6 (b), 7 (a), 7 (b) with the map after a certain angle, wherein, in Fig. 6 (a), be rotation grating map f when the anglec of rotation is 0 degree
kcarry out the schematic diagram of map segmentation in the horizontal direction, the map subregion split is region 601,602 ..., 612 as illustrated in the drawing; For rotating grating map f when the anglec of rotation is 0 degree in Fig. 6 (b)
kcarry out the schematic diagram of map segmentation in vertical direction, the map subregion split is region 701,702 ..., 710 as illustrated in the drawing; For rotating grating map f when the anglec of rotation is certain angle in Fig. 7 (a)
kcarry out the schematic diagram of map segmentation in the horizontal direction, the map subregion split is region 801,802 ..., 814 as illustrated in the drawing; For rotating grating map f when the anglec of rotation is certain angle in Fig. 7 (b)
kcarry out the schematic diagram of map segmentation in vertical direction, the map subregion split is region 901,902 ..., 911 as illustrated in the drawing.
K is added 1 and jumps to step S6 by S9.
S10 Calculation Basis grating map carries out map subregion optimum in all map subregions rotating for N time and obtain after the segmentation of N wheel map.Specifically, in this step, comprise the following steps:
S101 calculates the area S of all map subregions obtained after the segmentation of front-wheel map terminates
iwith the catercorner length L of minimum enclosed rectangle
i, wherein, i represents i-th map subregion.
S102 is normalized each area of map subregion and the catercorner length of minimum enclosed rectangle.Specifically, assuming that, if to split the total number of subregion obtained be sumN when front-wheel, as follows the average length of every sub regions and area are normalized:
Wherein, L_Normalized
irepresent the catercorner length after the normalization of i-th map subregion, S_Normalized
irepresent the area after the normalization of i-th map subregion.
S103 gives a mark to each map subregion respectively according to the area of each map subregion after the normalization obtained in the ratio in the catercorner length summation of catercorner length minimum enclosed rectangle in all map subregions of the ratio of the area of each map subregion in all map subregion area summations, each map subregion minimum enclosed rectangle, step S102 and the catercorner length of minimum enclosed rectangle.Specifically, in a particular embodiment, by following formula, each map subregion is given a mark:
Score
i=per_L*L_Normalized
i+per_S*S_Normalized
i
Wherein, when per_L represents marking catercorner length minimum enclosed rectangle in all map subregions of each map subregion minimum enclosed rectangle catercorner length summation in ratio, the ratio of area in all map subregion area summations of each map subregion when per_S represents marking.
S104 calculates the map subregion of the highest map subregion of marking as optimum using splitting when front-wheel map in all map subregions obtained.
S11 calculates the principal direction of optimum map subregion, preserves the data of optimum map subregion and in reference grid map, deletes optimum map subregion.Specifically, in this step, comprise the following steps:
S111 calculates the deflection of optimum map subregion according to the anglec of rotation of reference grid map.In a particular embodiment, assuming that, the image rotation angle that optimum map subregion is corresponding is θ, then the deflection of this principal direction is direction_angle, wherein, direction_angle is the angle of principal direction and vertical direction, is just counterclockwise, can obtains direction_angle according to following formula:
The pixel value of pixel corresponding in reference grid map for the map subregion of this optimum sets to 0 by S112, completes the optimum deletion of map subregion in reference grid map.In a particular embodiment, assuming that the height of reference grid map be height, width is width (unit all: pixel), then with step S71 in similarly:
half_height=height/2.0
half_width=width/2.0
half_new_width=half_new_height=new_width/2.0
Wherein, half_height and half_width is respectively the half of reference grid map (the front grating map of rotation) height and width, new_width and new_height is respectively postrotational grating map and (rotates grating map f
k) height and width, half_new_width and half_new_height is respectively and rotates grating map f
kheight and the half of width.
And then, assuming that, (i
1, j
1) for rotating grating map f
kin certain pixel coordinate, (i
0, j
0) be (i
1, j
1) pixel coordinate in corresponding reference grid map, then can obtain pixel (i in reference grid map according to following rotation formula
0, j
0) and rotate grating map f
kmiddle pixel (i
1, j
1) between mapping relations:
i
0=(i
1-half_new_height)*cos(k×d
θ)-(j
1-half_new_width)*sin(k×d
θ)+half_height
j
0=(j
1-half_new_width)*cos(k×d
θ)+(i
1-half_new_height)*sin(k×d
θ)+half_width
And then, to pixel (i in reference grid map
0, j
0) carry out rounding up and according to following formula to the pixel (i after rounding up
0, j
0) revise:
Now establish pixel (i in reference grid map completely
0, j
0) and rotate grating map f
kmiddle pixel (i
1, j
1) between mapping relations, obtain rotating grating map f
kmiddle pixel (i
1, j
1) value, if this pixel is positioned at optimal region, in f, the pixel value at place is set to 0, the deletion of optimum map subregion is completed with this, be illustrated in figure 8 the schematic diagram using step S11 to the grating map deleted by the map subregion of optimum rotated through first time and after map segmentation, wherein, the map subregion had most that in grating map, black part is deleted after being the first rotation in default grating map f.
(namely S12 resets loop parameter k, again k is set to 0), jump to step S5, until the map subregion split through map meets the condition in step S5, stop segmentation, complete the region segmentation of whole grating map, as Fig. 9 is the schematic diagram after above step carries out complete area segmentation, the region split comprise 1101,1102 ..., 1108.
It should be noted that above-described embodiment all can independent assortment as required.The above is only the preferred embodiment of the present invention; it should be pointed out that for those skilled in the art, under the premise without departing from the principles of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.