So far we have improved the accuracy of the Kinect, although we still want to put more conditions to make it more accurate. In the beginning, we use an algorithm that set up thresholds for aiming and shooting, after realizing that this algorithm was not enough for the accuracy that we wanted we added the condition where the closest the aiming box will be created in the pixel with the closest distance to the Kinect sensor in that aiming or shooting threshold. The code will be attached below. Now we are currently working to destroy targets once the user shoots at it.
Also, we have been working in what we think will the toughest challenge that is creating the main menu and buttons to store the scores, to show in the screen who has been the best iron man from all the participants during the IM showcase. The code will attach below
import org.openkinect.freenect.*; import org.openkinect.freenect2.*; import org.openkinect.processing.*; import org.openkinect.tests.*; PImage img; float angle; Kinect kinect; boolean shoot; float minShoot; float minThresh; float maxThresh; void setup(){ size(512,484); kinect = new Kinect(this); kinect. initDepth(); kinect.initVideo(); img = createImage(kinect.width, kinect.height,RGB); angle = kinect.getTilt(); shoot = false; minShoot = 610; minThresh = 710; maxThresh = 800; } void draw(){ background(0); shoot = false; img.loadPixels(); PImage dImg = kinect.getDepthImage(); image(dImg,0,0); int[] depth = kinect.getRawDepth(); float sumX = 0; float sumY = 0; float totalPixels = 0; int record = 4500; int rx = 0; int ry = 0; for (int x = 0; x<kinect.width; x++){ for (int y =0; y< kinect.height; y++){ int offset = x + y*kinect.width; int d = depth[offset]; if(d>=minThresh && d<maxThresh){ img.pixels[offset] = color(255,0,150); sumX+= x; sumY+=y; totalPixels++; if(d<record){ record = d; rx = x; ry = y; } } else if(d>=minShoot && d<minThresh){ img.pixels[offset] = color(255,255,0); sumX+= x; sumY+=y; totalPixels++; shoot = true; if(d<record){ record = d; rx = x; ry = y; } } else{ img.pixels[offset] = dImg.pixels[offset] ; } } } img.updatePixels(); image(img,0,0); float avgX = sumX/totalPixels; float avgY =sumY/totalPixels; if(shoot == true){ fill(255,0,0); } else{ fill(150,0,255); } ellipse(rx,ry,64,64); } void keyPressed() { if (key == CODED) { if (keyCode == UP) { angle++; } else if (keyCode == DOWN) { angle--; } angle = constrain(angle, 0, 30); kinect.setTilt(angle); } }
PImage menupic; PImage bpic; PImage spic; import controlP5.*; int state = 0; ControlP5 a; ControlP5 c; ControlP5 d; String output; PFont b; PFont yo; //for Scoreboard text input final int menu = 0; final int game = 1; final int scoreboard = 2; final int options = 3; final int quit = 4; void setup(){ menupic = loadImage("menu.jpg"); //menu picture bpic = loadImage("background.jpg"); //background picture spic = loadImage("scoreboard.jpg"); //scoreboard picture size(1920,1030); //MENU INTERACTIONS a = new ControlP5(this); //a is for menu b = createFont("Verdana",30); //font for menu yo = createFont("Verdana",15); //font for scoreboard form a.addButton("Play") //name .setPosition(100,150) //position .setSize(250,200) //size .setFont(b) //font ; a.addButton("Scoreboard") .setPosition(1500,150) .setSize(250,200) .setFont(b) ; a.addButton("Options") .setPosition(100,750) .setSize(250,200) .setFont(b) ; a.addButton("Quit") .setPosition(1500,750) .setSize(250,200) .setFont(b) ; //C = Back Button c= new ControlP5(this); //c is for back button c.addButton("Back") .setPosition(1500,750) .setSize(250,200) .setFont(b) ; //D = Scoreboard d= new ControlP5(this); //d is for scoreboard screen d.addTextfield("Insert Name Here").setPosition(200,200).setSize(200,50).setAutoClear(false).setFont(yo); d.addBang("Submit").setPosition(400,200).setSize(200,50).setFont(yo); } void draw(){ image(menupic,0,0); if(state == 0){ //Menu runMenu(); c.hide(); a.show(); d.hide(); } else if(state == 1){ //Game runGame(); a.hide(); //c.hide(); c.show(); d.hide(); } else if(state == 2){ //Scoreboard image(spic,0,0); c.show(); a.hide(); d.show(); } else if(state ==4){ //Quit exit(); } } void runMenu(){ textSize(40); text("MENU",50,100); } void runGame(){ image(bpic,0,0); } void Play(){ state = 1; } void Scoreboard(){ state = 2; } void Back(){ state = 0; } void Quit(){ state = 4; } void Submit(){ //Submit form for text input in Scoreboard output = d.get(Textfield.class,"Insert Name Here").getText(); println(output); }