This week, I used KNN classifier to developed the classical snake game based on webcam image matches with pre-recorded gestures with four classifiers. This image match could be further used to involve in other games that requires multiple inputs. This assignment would start with taking four snapshots, each matches one direction (left, right, up and down) that the snake would go. Then the snake game would start, where the user would used gestures to control the movement of the snake.
I started with KNN classification. I used keyPressed to take snapshots. And an array was used to store the four snapshots and calculate the difference of the snapshots with the current webcam image. Then the snapshot with the smallest difference from the current image would be selected and used as the output. Here is a video demo of this process.
I then referred to the example code of snake game provided by P5 reference and added it into my code of KNN. The KNN was used to keep four screenshots to define the direction of the snake as neurons and constantly compare webcam image with the screenshots to find the one with the least difference and update the snake.
Future Development
This KNN could be involved with a wide variety of games. However, this demo could not sensitively detect the change of image and their matches. More input as neurons should implemented for further development.