public LMHandWrapper(Hand h) { palmPosition = h.palmPosition(); palmVelocity = h.palmVelocity(); palmNormal = h.palmNormal(); direction = h.direction(); sphereCenter = h.sphereCenter(); sphereRadius = h.sphereRadius(); }
public static void recog(ArrayList<UserGesture> gestureList, Controller controller) throws IOException, InterruptedException, AWTException { System.out.println("started recog"); long[] timer = new long[gestureList.size()]; int[] matched = new int[gestureList.size()]; int[] matched_attributes = new int[100]; String[] gestureStatus = new String[100]; while (MapperGUI.statusRecognizing == true) { Thread.sleep(5); frame = controller.frame(); currentHand = frame.hands().get(0); for (int gestureIterator = 0; gestureIterator < gestureList.size(); gestureIterator++) { if (frame.hands().isEmpty()) break; if (matched[gestureIterator] == 0) { System.out.println("NEW STARTFRAME"); // if((startFrame.get(gestureIterator)))startFrame.remove(gestureIterator); startFrame.add(gestureIterator, frame); timer[gestureIterator] = System.currentTimeMillis(); } // System.out.println("timer start"+timer); // for (int nodeIterator = matched[gestureIterator] + 1; nodeIterator < gestureList // .get(gestureIterator).NodeList.size();) { if (matched[gestureIterator] == gestureList.get(gestureIterator).NodeList.size() - 1) { Robot.execute(gestureIterator); // System.out.println("RECOGNITION SUCCESS for gesture number "+ gestureIterator + " , // action goes here"); if (Recorderv2.gestureList.get(Recorderv2.gestureCount - 1).cont == true) { matched[gestureIterator] = matched[gestureIterator] - 1; timer[gestureIterator] = System.currentTimeMillis(); matched_attributes[gestureIterator] = 0; } else { matched[gestureIterator] = 0; timer[gestureIterator] = 0; matched_attributes[gestureIterator] = 0; } break; } currentNode = Recorderv2.gestureList.get(gestureIterator).NodeList.get(matched[gestureIterator]); if (System.currentTimeMillis() < (timer[gestureIterator] + 200)) { if (gestureList.get(gestureIterator).attributes.contains("XY")) { if ((currentHand.palmPosition().getX() - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX()) < currentNode.hand0_x_denorm + deviationX && (currentHand.palmPosition().getX() - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX()) > currentNode.hand0_x_denorm - deviationX && (currentHand.palmPosition().getY() - startFrame.get(gestureIterator).hands().get(0).palmPosition().getY()) < currentNode.hand0_y_denorm + deviationY && (currentHand.palmPosition().getY() - startFrame.get(gestureIterator).hands().get(0).palmPosition().getY()) > currentNode.hand0_y_denorm - deviationY) { // System.out.println(frame.hands().get(0).palmPosition().normalized()); matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1; } } if (gestureList.get(gestureIterator).attributes.contains("XZ")) { if ((currentHand.palmPosition().getX() - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX()) < currentNode.hand0_x_denorm + deviationX && (currentHand.palmPosition().getX() - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX()) > currentNode.hand0_x_denorm - deviationX && (currentHand.palmPosition().getZ() - startFrame.get(gestureIterator).hands().get(0).palmPosition().getZ()) < currentNode.hand0_z_denorm + deviationZ && (currentHand.palmPosition().getZ() - startFrame.get(gestureIterator).hands().get(0).palmPosition().getZ()) > currentNode.hand0_z_denorm - deviationZ) { // System.out.println(frame.hands().get(0).palmPosition().normalized()); matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1; } } if (gestureList.get(gestureIterator).attributes.contains("frontmost_finger_XY")) { if ((currentHand.fingers().frontmost().tipPosition().getX() - startFrame .get(gestureIterator) .hands() .get(0) .fingers() .frontmost() .tipPosition() .getX()) < currentNode.hand0_frontmost_x + deviationX && (currentHand.fingers().frontmost().tipPosition().getX() - startFrame .get(gestureIterator) .hands() .get(0) .fingers() .frontmost() .tipPosition() .getX()) > currentNode.hand0_frontmost_x - deviationX && (currentHand.fingers().frontmost().tipPosition().getY() - startFrame .get(gestureIterator) .hands() .get(0) .fingers() .frontmost() .tipPosition() .getY()) < currentNode.hand0_frontmost_y + deviationY && (currentHand.fingers().frontmost().tipPosition().getY() - startFrame .get(gestureIterator) .hands() .get(0) .fingers() .frontmost() .tipPosition() .getY()) > currentNode.hand0_frontmost_y - deviationY) { // System.out.println(frame.hands().get(0).palmPosition().normalized()); matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1; } } if (gestureList.get(gestureIterator).attributes.contains("frontmost_finger_XZ")) { if ((currentHand.fingers().frontmost().tipPosition().getX() - startFrame .get(gestureIterator) .hands() .get(0) .fingers() .frontmost() .tipPosition() .getX()) < currentNode.hand0_frontmost_x + deviationX && (currentHand.fingers().frontmost().tipPosition().getX() - startFrame .get(gestureIterator) .hands() .get(0) .fingers() .frontmost() .tipPosition() .getX()) > currentNode.hand0_frontmost_x - deviationX && (currentHand.fingers().frontmost().tipPosition().getZ() - startFrame .get(gestureIterator) .hands() .get(0) .fingers() .frontmost() .tipPosition() .getZ()) < currentNode.hand0_frontmost_z + deviationZ && (currentHand.fingers().frontmost().tipPosition().getZ() - startFrame .get(gestureIterator) .hands() .get(0) .fingers() .frontmost() .tipPosition() .getZ()) > currentNode.hand0_frontmost_z - deviationZ) { // System.out.println(frame.hands().get(0).palmPosition().normalized()); matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1; } } if (gestureList.get(gestureIterator).attributes.contains("roll")) { if ((currentHand.palmNormal().roll() - startFrame.get(gestureIterator).hands().get(0).palmNormal().roll()) < currentNode.hand0_roll + deviationRoll && (currentHand.palmNormal().roll() - startFrame.get(gestureIterator).hands().get(0).palmNormal().roll()) > currentNode.hand0_roll - deviationRoll) { // System.out.println(frame.hands().get(0).palmPosition().normalized()); matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1; } } if (gestureList.get(gestureIterator).attributes.contains("yaw")) { if ((currentHand.palmNormal().yaw() - startFrame.get(gestureIterator).hands().get(0).palmNormal().yaw()) < currentNode.hand0_yaw + deviationYaw && (currentHand.palmNormal().yaw() - startFrame.get(gestureIterator).hands().get(0).palmNormal().yaw()) > currentNode.hand0_yaw - deviationYaw) { // System.out.println(frame.hands().get(0).palmPosition().normalized()); matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1; } } if (gestureList.get(gestureIterator).attributes.contains("pitch")) { if ((currentHand.palmNormal().pitch() - startFrame.get(gestureIterator).hands().get(0).palmNormal().pitch()) < currentNode.hand0_pitch + deviationPitch && (currentHand.palmNormal().pitch() - startFrame.get(gestureIterator).hands().get(0).palmNormal().pitch()) > currentNode.hand0_pitch - deviationPitch) { // System.out.println(frame.hands().get(0).palmPosition().normalized()); matched_attributes[gestureIterator] = matched_attributes[gestureIterator] + 1; } } if (matched_attributes[gestureIterator] == Recorderv2.gestureList.get(gestureIterator).attributes.size() && matched_attributes[gestureIterator] != 0) { matched[gestureIterator] = matched[gestureIterator] + 1; timer[gestureIterator] = System.currentTimeMillis() + 200; matched_attributes[gestureIterator] = 0; System.out.println( "matched node number " + matched[gestureIterator] + " of gesture " + gestureIterator + " with " + gestureList .get(gestureIterator) .NodeList .get(matched[gestureIterator]) .hand0_x_denorm + "with " + (frame.hands().get(0).palmPosition().getX() - startFrame.get(gestureIterator).hands().get(0).palmPosition().getX())); } else { matched_attributes[gestureIterator] = 0; } } else { matched_attributes[gestureIterator] = 0; matched[gestureIterator] = 0; timer[gestureIterator] = 0; } // } } if (MapperGUI.statusRecognizing == false) break; } System.out.println("stopped recog"); // MapperGUI.runningRecognizing = false; return; }
@Override public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.LIGHT_GRAY); g2d.fillRect(0, 0, this.getWidth(), this.getHeight()); g2d.setColor(Color.BLACK); if (SampleListener.frame == null) return; Frame frame = SampleListener.frame; /* for(Gesture gest : frame.gestures()){ Location loc = Location.fromVector(frame.fingers().fingerType(Type.TYPE_INDEX).get(0).tipPosition()); if(OldGesture.contains(gest.id())){ OldGesture og = OldGesture.getGesture(gest.id()); if(gest.state().equals(State.STATE_STOP)){ OldGesture.remove(og.getID()); System.out.println("dddd"); } og.addLocation(Location.fromVector(frame.fingers().fingerType(Type.TYPE_INDEX).get(0).tipPosition())); if(og.getLocations().size() <= 1) continue; Location oldLoc = null; g2d.setColor(Color.BLUE); for(Location currLoc : og.getLocations()){ if(oldLoc == null){ oldLoc = currLoc; continue; } g2d.drawLine(oldLoc.getX()*3 + 800, oldLoc.getZ()*3 + 400, currLoc.getX()*3 + 800, currLoc.getZ()*3 + 400); oldLoc = currLoc; } }else{ new OldGesture(loc, gest.id()); } }*/ Image image = MainFrame.controller.images().get(0); // System.out.println(image.data().length); byte[] data = image.data(); // g2d.setColor(Color.BLACK); // g2d.fillRect(0, 0, image.width(), image.height()); int i = 0; for (int w = 0; w < image.height(); w++) { for (int h = 0; h < image.width(); h++) { int value = data[i]; int rgb = value; rgb = (rgb << 8) + value; rgb = (rgb << 8) + value; g2d.setColor(new Color(rgb)); g2d.drawRect(h + this.getWidth() - image.width(), w, 1, 1); i++; } } g2d.setColor(Color.black); if (frame.hands().isEmpty()) return; for (Hand hand : frame.hands()) { Vector v = hand.palmPosition(); Location loc = Location.fromVector(v); // System.out.println((int) (1.0 * 20/loc.getY()*100)); g2d.fillOval(loc.getX() * 3 + 800, loc.getZ() * 3 + 400, getSize(40, loc), getSize(40, loc)); v = hand.arm().center(); loc = Location.fromVector(v); g2d.fillOval(loc.getX() * 3 + 800, loc.getZ() * 3 + 400, getSize(40, loc), getSize(40, loc)); for (Finger finger : hand.fingers()) { v = finger.tipPosition(); loc = Location.fromVector(v); g2d.fillRect( loc.getX() * 3 + 800, loc.getZ() * 3 + 400, getSize(20, loc), getSize(20, loc)); v = finger.jointPosition(Joint.JOINT_DIP); loc = Location.fromVector(v); g2d.fillRect( loc.getX() * 3 + 800, loc.getZ() * 3 + 400, getSize(10, loc), getSize(10, loc)); v = finger.jointPosition(Joint.JOINT_MCP); loc = Location.fromVector(v); g2d.fillRect( loc.getX() * 3 + 800, loc.getZ() * 3 + 400, getSize(10, loc), getSize(10, loc)); v = finger.jointPosition(Joint.JOINT_PIP); loc = Location.fromVector(v); g2d.fillRect( loc.getX() * 3 + 800, loc.getZ() * 3 + 400, getSize(20, loc), getSize(20, loc)); } } g2d.dispose(); }