ucfai / knightros-gambit

Knightr0's Gambit is a partnership between the UCF student chapter of the Institute of Electrical and Electronics Engineers and the UCF Artificial Intelligence club to create an automatic chessboard (similar to Harry Potter's Wizard Chess with less violence) powered by a custom chess AI.
https://ucfai.github.io/knightros-gambit/
2 stars 3 forks source link

Figure out how to detect corners of board #100

Open nashirj opened 2 years ago

nashirj commented 2 years ago

We have three main options: 1) Hard code the image corners into our game loop code based on inspection 2) Make the corners distinct colors and identify them with CV 3) Use some 3rd approach to detect corners (e.g. Harris Corner detector)

My preference is option 2, but we need to discuss with hardware team if we're doing that approach.

ColonelToad commented 2 years ago

Would using a Harris Corner not be the most accurate way to detect corners? Or is there another reason it's not necessarily the preferred option?

nashirj commented 2 years ago

image image

ColonelToad commented 2 years ago

So you can see the results of running all the tests, overall Canny has the best accuracy however I was surprised to see Shi-Tomasi spotted pieces off the board as well. Canny Shi-Tomasi Sobel

nashirj commented 2 years ago

This looks great! Nice progress. It looks like lighting is the biggest issue here, since the top left and bottom right corners are detected, and the difference in lighting is largest at the bottom left and top right corners. Once we have consistent lighting, we should be able to get good results, and then we can select the corners at the extreme x and y positions to get the four outer corners!

ColonelToad commented 2 years ago

So when using the new board image I'm getting much different results. I'll play around with the values more but Shi-Tomasi is not giving me anything at all. Canny is showing some of the edges on the area of the board where the board isn't under the light, and the gradients from the sobel so the same thing. I actually tried Harris and got some results with it though. canny sobel harris

ColonelToad commented 2 years ago

After resizing the image to 800x800 I definitely saw an improvement with the results. With goodFeaturesToTrack() I used 150 as the parameter and that essentially placed a dot around all the tiles of the board as well as the board edge and the pieces. Granted we can experiment with this value but certainly, 150 is a good maximum for how many features to track. sobel goodFeatures canny