-
Notifications
You must be signed in to change notification settings - Fork 1
BallPerceptor
#BallPerceptor
1.Description
2.fitball()
3.classifyBalls2()
The BallPerceptor includes two function mainly: fitball() and classifyBalls2(). The fitball() function finds 24 edge points based on the ballspots and try to fit a circle using those edge points. If success, it saves the ballspot as a possible ball. Then all the possible balls are transferred to the second function called classifyBalls2(). classifyBalls2() is a classifier which uses some criteria to decide whether the possible ball is a valid ball. This classifier also assigns a score to those possible ball that meet the criteria, so that we can choose the most possible ball from them. These two function will be detailed as follow:
## 2.fitball() fitball() is in charge of finding the edge points of a ballspot and trying to fit a circle based on those edge points. If success, it considers the ballspot as a possible ball. This function consists two steps:###First step: choose three points called guesspoint inside the circle whose center is ballspot and radius is calculated in BallSpotProvider. These three guesspoints should not be on a same line, so that the edge points found will not repeat. Then using these three guesspoints as start points to trace from the guesspoint to the region’s extrema. There are eight scan lines and they will finish when finding enough green pixels. The scan lines’ scanning directions and guesspoints are shown by the following figures:
guesspoint_1: guesspoint_2: guesspoint_3:
The edges found is as follows(which are yellow):
###Second step: After the first step, we get 24 edge points of a ballspot. In the second step we use these edge points to try to fit a circle. We use RANSAC algorithm to fit them. Since the method of least squares can be influenced by noise easily and the edge points found in the first step sometimes contain a few noise point, the RANSAC algorithm can get a better performance than the least squares method. Through these two steps descripted above, we get some possible ball. Then we re-calculate their center and radius and transfer them to classifyBalls2().
## 3.classifyBalls2() This function is in charge of deciding whether the possible ball found by fitball() is valid. If valid, save it as a candidate. In the end, it will choose a most possible ball as ballPercept among those candidates according to their scores. In the beginning, it uses OTSU algorithm to find a suitable threshold so as to distinguish the black pixels and white pixels inside the possible ball. With this algorithm we can distinguish correctly in spite of the frequently changing of lighting condition. Then this function goes through all the pixels inside the square whose center is possible ball’s center and side length is the possible ball’s diameter. After that, it can get several statistical data to decide whether it is an valid ball. All the statistical data are listed as follow: *** (1) _**ratioGreen**_: The ratio of green pixels which lie in the square and stay outside the circle among the totality of pixels outside the circle. It is only convinced to be a ball on condition that the ratio is larger than a certain threshold. And if a valid ball is confirmed, there must be a certain quantity of green pixels around since the ball is definitely on the ground. (2) **_ratioTotal_**: the ratio of black or white pixels among the totality of pixels in the circle. (3) **_varY_**: the variance of gray scale provided by the black and white pixels in the circle. This parameter protects the detected possibleball from being wrongly confirmed as a ball. (4) **_whitePercent_**: the proportion of white pixels in the circle. (5) **_ratio_**: the ratio between black and white pixels in the circle. (6) **_meanWhite_**: the average gray scale of white pixels in the circle. (7) **_meanBlack_**: the average gray scale of black pixels in the circle (8) **_Score_**: the score of possibleball can be achieved by : ***Score=tansig(ratio,0.3f)*0.2f + tansig(ratilTotal,1.2f)*0.4f + tansig(ratioGreen,0.7f)*0.4f
The tansig function can be seen in the BallPerceptor.cpp.
It is only confirmed to be a valid ball if all the 7 indexes above meet the requirements and the score exceeds the threshold. Finally, if no valid ball is confirmed, we can simply comprehend that as there’s no ball in the field of vision. If more than one ball is confirmed, we’ll take the one with the highest score as the convincing one.
The performance of this module is as follows:
near_circle_good:
goal_line: