I am trying to identify the T-rex and obstacles (cactus and bird) from Google's no-internet game.
What I have done is:
- Apply GaussianBlur filter
- Apply Canny
- Apply Dilate
- Apply erode
- findContours that returns all external contours, RETR_EXTERNAL
My approach generally works, except that when there is a small bump on the ground next to a cactus, my script will consider the T-rex, the bump on the ground and the cactus as a giant horizontal contour, how do I filter out this horizon? The blue box is the outline of the contour I found.
- I tried reducing the size of the image I am taking vertically so that the horizon would be left out, but it introduced a different problem: T-rex legs would be cut off and occasionally, T-rex would not be considered as a contour as it is not closed.
When there is no bump on the ground next to a cactus, my script produces the expected result.