Stylus Snake

Overview

Stylus controlled snake game is similar to classical snake game but differs in the way we control it which is done by a Stylus. A stylus refers to an object of any color that is first detected and then later can be used to control the motion of the snake.

Abstract

PictureFor the stylus, the camera feed is taken, Gaussian blur is applied, frames are converted from BGR to HSV, morphological transformations are applied to remove noise, then thresholded to find the required part of the stylus.

Approaches used for stylus detection

Using trackbars to find the HSV values of the stylus, then creating a mask that hides all HSV colors other than the color of the stylus. We use contours to detect the stylus and its centroid which will help in controlling the snake later in the game.
​Applying HSV backpropagation: Taking a small region of 10 x 10 pixels, we capture the stylus in that region then, backpropagate the HSV values and taking the average of the 100 HSV values of the individual pixels, we use the average HSV value obtained for the stylus detection by making a mask and thus isolating the stylus from the background. With the mask created and using various edge detections like Canny edges, we use contours to detect the stylus and hence the centroid of the contours detected which will be the controller of the snake in the game.


Approaches used for in-game snake movementsMake a list and append 10 consecutive coordinates of stylus moving. Find the maximum difference of consecutive x coordinates in the list and if it is greater than 10(significant movement in that particular direction) then the snake is assigned that direction.
If the stylus moves more than 40 pixels, then using the starting and initial point, the slope ‘m’ is calculated and the next coordinate of the snake is determined using the parametric equation of line [(x-x1)/cosθ = (y-y1)/sinθ = r] from the current location of the snake as (x1,y1) and r as the current speed of the snake thus allowing dynamic movement of the snake in all directions.
If the stylus moves more than 40 pixels, then using the starting and initial point, the slope ‘m’ is calculated and the next coordinate of the snake is determined using the parametric equation of line [(x-x1)/cosθ = (y-y1)/sinθ = r] from the current location of the snake as (x1,y1) and r as the current speed of the snake thus allowing dynamic movement of the snake in all directions.
Divide the screen into 4 regions that demarcate the movement directions. The region in which the stylus is present is then detected and the snake moves according to the direction allotted to that specific region. video:- drive.google.com/file/d/1nCrvaIU630CwWT4bjs9g17-60CQr-s-b/view
Picture Picture

Result

Picture

Tools and Libraries used

Picture

python

Picture
Picture

Our Team

Members
Lovesh Goyal
Aditya Jivoji
Aditya Rudra
Soumyadeep Ghosh
Gunjan Paliwal
Sneha Tabitha
Prasenjeet Kapse
Aaradhy Jain
Mentors
Diksha Bagade
Parees Pathak
Sushlok Shah
Bipasha Parui
Karthik Raman

GitHub Repository