/** * Test * * @param args * @throws KinectException */ public static void main(String[] args) throws KinectException { VideoDisplay.createVideoDisplay(new KinectController(0).videoStream); } }
private void pointCloudOut(FImage depth, String out, int xmin, int ymin, int xmax, int ymax, float xdiv, float ydiv) throws FileNotFoundException { final PrintWriter writer = new PrintWriter(new File(out)); final float stepx = (xmax - xmin) / xdiv; final float stepy = (ymax - ymin) / ydiv; final float[] xyz = new float[3]; final double factor = controller.computeScalingFactor(); for (int y = ymin; y < ymax; y += stepy) { for (int x = xmin; x < xmax; x += stepx) { final int d = (int) depth.pixels[y][x]; if (d > 0) { // double[] xyz = controller.cameraToWorld(x, y, d); controller.cameraToWorld(x, y, d, factor, xyz); writer.printf("%4.2f %4.2f %4.2f\n", xyz[0], xyz[1], xyz[2]); } } writer.flush(); } writer.close(); }
@Override public void keyPressed(KeyEvent e) { if (e.getKeyChar() == 'w') { controller.setTilt(tilt += 1); } else if (e.getKeyChar() == 'x') { controller.setTilt(tilt -= 1); } else if (e.getKeyChar() == 's') { controller.setTilt(tilt = 0); } else if (e.getKeyChar() == 't') { controller.setIRMode(irmode = !irmode); } else if (e.getKeyChar() == 'y') { controller.setRegisteredDepth(rdepth = !rdepth); } else if (e.getKeyChar() == 'p') { printCloud = true; } }
@Override public void keyPressed(KeyEvent e) { if (e.getKeyChar() == 'w') { controller.setTilt(tilt+=1); } else if (e.getKeyChar() == 'x') { controller.setTilt(tilt-=1); } else if (e.getKeyChar() == 's') { controller.setTilt(tilt=0); } else if (e.getKeyChar() == 't') { controller.setIRMode(irmode=!irmode ); } }
depth.drawText("Camera: " + Arrays.toString(new int[] { 100, 100, pixToDraw }), 0, 460, HersheyFont.TIMES_MEDIUM, 16, RGBColour.WHITE); depth.drawText("World: " + Arrays.toString(controller.cameraToWorld(100, 100, pixToDraw)), 0, 480, HersheyFont.TIMES_MEDIUM, 16, RGBColour.WHITE); } else { accel = controller.getAcceleration() + ""; renderer.drawText(accel, 0, 480, HersheyFont.TIMES_MEDIUM, 16, RGBColour.WHITE);
/** * Compute the scaling factor for computing world coordinates. * * @see #cameraToWorld(int, int, int, double) * * @return the scaling factor */ public double computeScalingFactor() { // Struct-by-value isn't currently working in bridj. When it is // we can do: // freenect_registration regInfo = // libfreenectLibrary.freenect_copy_registration(device); // double ref_pix_size = // regInfo.zero_plane_info().reference_pixel_size(); // double ref_distance = regInfo.zero_plane_info().reference_distance(); // return 2 * ref_pix_size / ref_distance; // for now we can work around by calculating the factor from a projected // point final int x = (DEPTH_X_RES / 2) + 1; final double[] xyz = cameraToWorld(x, 0, 1000); return xyz[0] / 1000.0; }
init(); final int cd = connectedDevices(); if (deviceId >= cd || deviceId < 0) { throw new IllegalArgumentException("Invalid device id");
@Override public void finalize() { close(); }
/** * Get the number of connected devices. * * @return the number of devices connected. * @throws KinectException */ public static synchronized int connectedDevices() throws KinectException { init(); return libfreenectLibrary.freenect_num_devices(CONTEXT); }
@Override public void keyPressed(KeyEvent e) { if (e.getKeyChar() == 'w') { controller.setTilt(tilt+=1); } else if (e.getKeyChar() == 'x') { controller.setTilt(tilt-=1); } else if (e.getKeyChar() == 's') { controller.setTilt(tilt=0); } else if (e.getKeyChar() == 't') { controller.setIRMode(irmode=!irmode ); } }
depth.drawText("Camera: " + Arrays.toString(new int[] { 100, 100, pixToDraw }), 0, 460, HersheyFont.TIMES_MEDIUM, 16, RGBColour.WHITE); depth.drawText("World: " + Arrays.toString(controller.cameraToWorld(100, 100, pixToDraw)), 0, 480, HersheyFont.TIMES_MEDIUM, 16, RGBColour.WHITE); } else { accel = controller.getAcceleration() + ""; renderer.drawText(accel, 0, 480, HersheyFont.TIMES_MEDIUM, 16, RGBColour.WHITE);
/** * Compute the scaling factor for computing world coordinates. * * @see #cameraToWorld(int, int, int, double) * * @return the scaling factor */ public double computeScalingFactor() { // Struct-by-value isn't currently working in bridj. When it is // we can do: // freenect_registration regInfo = // libfreenectLibrary.freenect_copy_registration(device); // double ref_pix_size = // regInfo.zero_plane_info().reference_pixel_size(); // double ref_distance = regInfo.zero_plane_info().reference_distance(); // return 2 * ref_pix_size / ref_distance; // for now we can work around by calculating the factor from a projected // point final int x = (DEPTH_X_RES / 2) + 1; final double[] xyz = cameraToWorld(x, 0, 1000); return xyz[0] / 1000.0; }
init(); final int cd = connectedDevices(); if (deviceId >= cd || deviceId < 0) { throw new IllegalArgumentException("Invalid device id");
@Override public void finalize() { close(); }
/** * Get the number of connected devices. * * @return the number of devices connected. * @throws KinectException */ public static synchronized int connectedDevices() throws KinectException { init(); return libfreenectLibrary.freenect_num_devices(CONTEXT); }
/** * Test * * @param args * @throws KinectException */ public static void main(String[] args) throws KinectException { VideoDisplay.createVideoDisplay(new KinectController(0).videoStream); } }
@Override public void keyPressed(KeyEvent e) { if (e.getKeyChar() == 'w') { controller.setTilt(tilt += 1); } else if (e.getKeyChar() == 'x') { controller.setTilt(tilt -= 1); } else if (e.getKeyChar() == 's') { controller.setTilt(tilt = 0); } else if (e.getKeyChar() == 't') { controller.setIRMode(irmode = !irmode); } else if (e.getKeyChar() == 'y') { controller.setRegisteredDepth(rdepth = !rdepth); } else if (e.getKeyChar() == 'p') { printCloud = true; } }
private void pointCloudOut(FImage depth, String out, int xmin, int ymin, int xmax, int ymax, float xdiv, float ydiv) throws FileNotFoundException { final PrintWriter writer = new PrintWriter(new File(out)); final float stepx = (xmax - xmin) / xdiv; final float stepy = (ymax - ymin) / ydiv; final float[] xyz = new float[3]; final double factor = controller.computeScalingFactor(); for (int y = ymin; y < ymax; y += stepy) { for (int x = xmin; x < xmax; x += stepx) { final int d = (int) depth.pixels[y][x]; if (d > 0) { // double[] xyz = controller.cameraToWorld(x, y, d); controller.cameraToWorld(x, y, d, factor, xyz); writer.printf("%4.2f %4.2f %4.2f\n", xyz[0], xyz[1], xyz[2]); } } writer.flush(); } writer.close(); }
/** * Completely shutdown the context. This turns off all cameras. The context * will be restarted upon creation of a new KinectController. */ public synchronized static void shutdownFreenect() { while (ACTIVE_CONTROLLERS.size() > 0) { ACTIVE_CONTROLLERS.get(0).close(); } if (EVENT_THREAD != null) { EVENT_THREAD.kill(); } if (CONTEXT != null) libfreenectLibrary.freenect_shutdown(CONTEXT); CONTEXT = null; EVENT_THREAD = null; }
/** * Default constructor * @param id of kinect controller * @throws KinectException */ public KinectDepthSnapshot(int id) throws KinectException { controller = new KinectController(id, irmode,true); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] devices = ge.getScreenDevices(); JFrame frame=new JFrame("Full Screen JFrame"); //Set default close operation for JFrame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set JFrame size to full screen size follow current screen size screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; fullScreenResizeProcessor = new ResizeProcessor(screenWidth, screenHeight); frame.setBounds(0,0,screenWidth,screenHeight); videoFrame = VideoDisplay.createVideoDisplay(this, new DisplayUtilities.ImageComponent(true)); JFrame wholeWindow = new JFrame(); wholeWindow.setUndecorated(true); wholeWindow.setAlwaysOnTop(true); wholeWindow.getContentPane().add(videoFrame.getScreen()); devices[0].setFullScreenWindow(wholeWindow); ((JFrame)SwingUtilities.getRoot(videoFrame.getScreen())).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); SwingUtilities.getRoot(videoFrame.getScreen()).addKeyListener(this); }