• fullscreen
  • control.pde
  • controlPanel.pde
  • drawScanBox.pde
  • kinect3Dscanner.pde
  • kinectPoints.pde
  • kinectUtilities.pde
  • scans.pde
  • /*
     * Peasycam style scene controls
     */
    
    void mouseDragged(){
      rotX += map(mouseY-pmouseY,0,height,0,TWO_PI);
      rotY += map(mouseX-pmouseX,0,width,0,TWO_PI);
    }
    
    void keyPressed(){
      switch(keyCode){
        case UP:
          zoom *= 1.05;
          break;
        case DOWN:
          zoom /= 1.05;
          break;
      }
    }
    
    
    /*
     * ControlP5 Kinect controls
     */
    
    void controlPanel(){
      int deltaX = 20;
      int deltaY = 20;
      int stepX = 100;
      int stepY = 30;
      
      ControlP5 cp5 = new ControlP5(this);
      
      ControlWindow cw = cp5.addControlWindow("Kinect control",0,0,400,deltaY+13*stepY+10);
      cw.hideCoordinates();
      cw.setBackground(color(0));
    
      Toggle drawBandsToggle = cp5.addToggle("drawBands",drawBands,deltaX,deltaY,20,20);
      drawBandsToggle.setCaptionLabel("Draw bands");
      drawBandsToggle.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      drawBandsToggle.moveTo(cw);
    
      Toggle drawPixelsToggle = cp5.addToggle("drawPixels",drawPixels,deltaX+1*stepX,deltaY,20,20);
      drawPixelsToggle.setCaptionLabel("Draw pixels");
      drawPixelsToggle.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      drawPixelsToggle.moveTo(cw);
    
      Toggle realToggle = cp5.addToggle("realColor",realColor,deltaX+2*stepX,deltaY,20,20);
      realToggle.setCaptionLabel("Real color");
      realToggle.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      realToggle.moveTo(cw);
    
      Slider resSlider = cp5.addSlider("resolution",1,10,resolution,deltaX,deltaY+1*stepY,300,20);
      resSlider.setCaptionLabel("Resolution");
      resSlider.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      resSlider.setNumberOfTickMarks(10);
      resSlider.showTickMarks(false);
      resSlider.moveTo(cw);
    
        
      Range xLimsRange = cp5.addRange("xRange",xmin-0.1*(xmax-xmin),xmax+0.1*(xmax-xmin),xmin,xmax,deltaX,deltaY+3*stepY,300,20);
      xLimsRange.setCaptionLabel("X limits");
      xLimsRange.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      xLimsRange.moveTo(cw);
    
      Range yLimsRange = cp5.addRange("yRange",ymin-0.1*(ymax-ymin),ymax+0.1*(ymax-ymin),ymin,ymax,deltaX,deltaY+4*stepY,300,20);
      yLimsRange.setCaptionLabel("Y limits");
      yLimsRange.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      yLimsRange.moveTo(cw);
    
      Range zLimsRange = cp5.addRange("zRange",zmin-0.1*(zmax-zmin),zmax+0.1*(zmax-zmin),zmin,zmax,deltaX,deltaY+5*stepY,300,20);
      zLimsRange.setCaptionLabel("Z limits");
      zLimsRange.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      zLimsRange.moveTo(cw);
    
    
      Slider boxSizeSlider = cp5.addSlider("boxSize",10,500,boxSize,deltaX,deltaY+7*stepY,300,20);
      boxSizeSlider.setCaptionLabel("Box size");
      boxSizeSlider.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      boxSizeSlider.moveTo(cw);
    
      Slider xCenterSlider = cp5.addSlider("xBox",xmin,xmax,boxCenter.x,deltaX,deltaY+8*stepY,300,20);
      xCenterSlider.setCaptionLabel("Box X");
      xCenterSlider.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      xCenterSlider.moveTo(cw);
    
      Slider yCenterSlider = cp5.addSlider("yBox",ymin,ymax,boxCenter.y,deltaX,deltaY+9*stepY,300,20);
      yCenterSlider.setCaptionLabel("Box Y");
      yCenterSlider.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      yCenterSlider.moveTo(cw);
    
      Slider zCenterSlider = cp5.addSlider("zBox",zmin,zmax,boxCenter.z,deltaX,deltaY+10*stepY,300,20);
      zCenterSlider.setCaptionLabel("Box Z");
      zCenterSlider.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      zCenterSlider.moveTo(cw);
    
    
      Bang takeScanBang = cp5.addBang("takeScan",deltaX,deltaY+12*stepY,20,20);
      takeScanBang.setCaptionLabel("Take scan");
      takeScanBang.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      takeScanBang.moveTo(cw);
    
      Toggle drawScansToggle = cp5.addToggle("drawScans",drawScans,deltaX+stepX,deltaY+12*stepY,20,20);
      drawScansToggle.setCaptionLabel("Draw Scans");
      drawScansToggle.getCaptionLabel().align(ControlP5.RIGHT_OUTSIDE,CENTER).setPaddingX(10);
      drawScansToggle.moveTo(cw);
    }
    
    void controlEvent(ControlEvent theControlEvent){
      if(theControlEvent.isFrom("xRange")){
        xmin = theControlEvent.getController().getArrayValue(0);
        xmax = theControlEvent.getController().getArrayValue(1);
      }
      if(theControlEvent.isFrom("yRange")){
        ymin = theControlEvent.getController().getArrayValue(0);
        ymax = theControlEvent.getController().getArrayValue(1);
      }
      if(theControlEvent.isFrom("zRange")){
        zmin = theControlEvent.getController().getArrayValue(0);
        zmax = theControlEvent.getController().getArrayValue(1);
      }
      if(theControlEvent.isFrom("xBox")){
        boxCenter.x = theControlEvent.getController().getValue();
      }
      if(theControlEvent.isFrom("yBox")){
        boxCenter.y = theControlEvent.getController().getValue();
      }
      if(theControlEvent.isFrom("zBox")){
        boxCenter.z = theControlEvent.getController().getValue();
      }
      if(theControlEvent.isFrom("takeScan")){
        takeScan = true;
      }
    }
    
    
    void drawScanBox(PVector scanCenter, float delta){
      smooth();
      noFill();
      stroke(255);
      strokeWeight(1);
    
      pushMatrix();
        translate(scanCenter.x,scanCenter.y,scanCenter.z);
        line(-delta,0,0,delta,0,0);
        line(0,-delta,0,0,delta,0);
        line(0,0,-delta,0,0,delta);
        box(delta,delta,delta);
      popMatrix();
    
      noSmooth();
      noStroke();
    }
    
    
    /* 
     * Simple 3D scanner using the Kinect (JGC).
     *
     * Select the scanner area with the controls and press the "take scan" button 
     * to capture the 3D points inside the box.
     * A mesh is created with the Hemesh library and saved in the sketch directory.
     * The colors of the mesh faces are saved in a different file.
     * 
     * Press the "take scan" button again to take more scans. 
     * 
     * Use http://www.openprocessing.org/sketch/62533 to read and represent the mesh.
     *
     */
    
    import SimpleOpenNI.*;
    import controlP5.*;
    import wblut.core.processing.*;
    import wblut.hemesh.tools.*;
    import wblut.hemesh.creators.*;
    import wblut.hemesh.core.*;
    import wblut.geom.core.*;
    
    // Prefix for the mesh and color files.
    // Will overwrite previous scans if is not changed.
    String file = "face";  
    
    public boolean drawBands = true;
    public boolean drawPixels = false;
    public boolean realColor = true;
    public int     resolution = 2;
    public float   xmin, xmax, ymin, ymax, zmin, zmax; 
    public float   boxSize = 300;
    public PVector boxCenter;
    public boolean takeScan = false;
    public boolean drawScans = false;
    
    SimpleOpenNI context;
    WB_Render render;
    
    float zoom = 0.35;
    float rotX = PI;
    float rotY = 0;
    
    ArrayList scansList = new ArrayList();
    
    void setup(){
      size(1024,768,P3D);
      frameRate(5);
      perspective(radians(45),float(width)/float(height),10.0,150000.0);
    
      // Render for the mesh
      render = new WB_Render(this);  
    
      // Initialize the Kinect                       
      context = new SimpleOpenNI(this); 
      context.setMirror(true);
      context.enableDepth();  
      context.enableRGB();
      context.alternativeViewPointDepthToImage();
      
      // Update the kinect to calculate the scene limits
      context.update(); 
      calculateLimits(context.depthMap(),context.depthMapRealWorld());
    
      // Initial scan box position
      boxCenter = new PVector((xmax+xmin)/2,(ymax+ymin)/2,(zmax+zmin)/2);
      
      // This should come after calculateLimits() and the boxCenter definition
      controlPanel(); 
    }
    
    void draw(){
      // Update the kinect
      context.update();
      int[] depthMap = context.depthMap();
      PVector[] realWorldMap = context.depthMapRealWorld();
      PImage rgbImage = context.rgbImage();
    
      // This reduces the number of points in the maps. 
      // Good if your computer doesn't have a lot of memory
      int[] resDepth = resizeDepth(depthMap,resolution);
      PVector[]resMap3D = resizeMap3D(realWorldMap,resolution);
      PImage resRGB = resizeRGB(rgbImage,resolution);
      boolean[] constrainedImg = constrainImg(resDepth,resMap3D,xmin,xmax,ymin,ymax,zmin,zmax);
      
      // Position the scene
      background(10);
      translate(width/2,height/2,0);
      rotateX(rotX);
      rotateY(rotY);
      scale(zoom);
      translate(0,0,-1500);
      
      // Lights with real colors doesn't look very nice 
      if(!realColor){     
        directionalLight(255,255,255,0,-0.2,1); 
      }
    
      // Paint the kinect points
      KinectPoints kp = new KinectPoints(resMap3D,resRGB,constrainedImg);
      if(drawBands){
        if(realColor){
          kp.drawAsBands();
        }
        else{
          kp.drawAsBands(color(50,50,255));
        }
      }
      if(drawPixels){
        if(realColor){
          kp.drawAsPixels(2);
        }
        else{
          kp.drawAsPixels(2,color(200));
        }
      }
        
      // Draw the scan box
      drawScanBox(boxCenter,boxSize);
      
      // Take the scan and create the mesh
      if(takeScan){
        boolean[] scanRegion = scanPoints(resDepth,resMap3D,boxCenter,boxSize);
        Scan scan = new Scan(resMap3D,resRGB,scanRegion);
        scan.createMesh();
    
        // Different name for each scan file
        String scanFileName = file+scansList.size(); 
        scan.saveMesh(scanFileName);
    
        scansList.add(scan);
        takeScan = false;
      }
      
      // Draw the mesh. Only if we already took a scan.
      if(drawScans && (scansList.size() > 0)){ 
        for(Iterator i = scansList.iterator(); i.hasNext(); ){
          Scan scan = (Scan) i.next();
          if(realColor){
            scan.drawMesh();
          }
          else{
            scan.drawMesh(color(255));
          }
        }
      }
    
    }
    
    
    /*
     * Simple class to save and draw the kinect points.
     *
     */
    
    class KinectPoints{
      PVector[] map3D;    // 3D points
      PImage rgbImg;      // Point colors 
      boolean[] consImg;  // Valid points 
        
      KinectPoints(PVector[] tempMap3D, PImage tempRGBimg, boolean[] tempConsImg){
        map3D = tempMap3D;
        rgbImg = tempRGBimg;
        consImg = tempConsImg;
      }
      
      void drawAsPixels(int pSize){
        strokeWeight(pSize);
    
        int nPoints = map3D.length;
        for(int i = 0; i < nPoints; i++){
          if(consImg[i]){
            PVector p = map3D[i];
            stroke(rgbImg.pixels[i]);
            point(p.x,p.y,p.z);
          }  
        }
      }
      
      void drawAsPixels(int pSize, color col){
        strokeWeight(pSize);
        stroke(col);
        
        int nPoints = map3D.length;
        for(int i = 0; i < nPoints; i++){
          if(consImg[i]){ 
            PVector p = map3D[i];
            point(p.x,p.y,p.z);
          }  
        }
      }
    
      void drawAsBands(){
        noStroke();
    
        int xSize = rgbImg.width;
        int ySize = rgbImg.height;
        float maxSep = 90;         // Maximum separation allowed between two consecutive points
        boolean started = false;   // Controls when a band has been started
        
        for(int y = 0; y < ySize-1; y++){
          for(int x = 0; x < xSize; x++){
            int index = x + y*xSize;
            if(consImg[index]){
              // Upper point
              fill(rgbImg.pixels[index]);
              PVector p = map3D[index];
              if(!started){
                beginShape(TRIANGLE_STRIP);
                vertex(p.x,p.y,p.z);
                started = true;
              }
              else if(p.dist(map3D[index-1]) < maxSep){  
                vertex(p.x,p.y,p.z);         
              }
              else{
                endShape();
                started = false;
                x--;  // Is a good point, use it in the next loop as starting point for a new band
                continue;
              }
              // Lower point         
              if(consImg[index+xSize]){
                PVector lp = map3D[index+xSize];
                if(p.dist(lp) < maxSep){
                  fill(rgbImg.pixels[index+xSize]);
                  vertex(lp.x,lp.y,lp.z);
                } 
                else{
                  vertex(p.x,p.y,p.z);
                }            
              }
              else{
                vertex(p.x,p.y,p.z);
              }            
              // Finish the band if is the last point in the row
              if(x == xSize-1){
                endShape();
                started = false;
              }
            }
            else if(started){
              // Upper point is not valid, let's see if we can use the lower point
              // for the last point in the band
              if(consImg[index+xSize]){
                PVector lp = map3D[index+xSize];
                if(lp.dist(map3D[index-1]) < maxSep){
                  fill(rgbImg.pixels[index+xSize]);
                  vertex(lp.x,lp.y,lp.z);
                }
              }
              endShape();
              started = false;
            }
          }
        }
      }
      
      void drawAsBands(color col){
        noStroke();
        fill(col);
    
        int xSize = rgbImg.width;
        int ySize = rgbImg.height;
        float maxSep = 90;         // Maximum separation allowed between two consecutive points
        boolean started = false;   // Controls when a band has been started
        
        for(int y = 0; y < ySize-1; y++){
          for(int x = 0; x < xSize; x++){
            int index = x + y*xSize;
            if(consImg[index]){
              // Upper point
              PVector p = map3D[index];
              if(!started){
                beginShape(TRIANGLE_STRIP);
                vertex(p.x,p.y,p.z);
                started = true;
              }
              else if(p.dist(map3D[index-1]) < maxSep){  
                vertex(p.x,p.y,p.z);         
              }
              else{
                endShape();
                started = false;
                x--;  // Is a good point, use it in the next loop as starting point for a new band
                continue;
              }
              // Lower point         
              if(consImg[index+xSize]){
                PVector lp = map3D[index+xSize];
                if(p.dist(lp) < maxSep){
                  vertex(lp.x,lp.y,lp.z);
                } 
                else{
                  vertex(p.x,p.y,p.z);
                }            
              }
              else{
                vertex(p.x,p.y,p.z);
              }            
              // Finish the band if is the last point in the row
              if(x == xSize-1){
                endShape();
                started = false;
              }
            }
            else if(started){
              // Upper point is not valid, let's see if we can use the lower point
              // as the last point in the band
              if(consImg[index+xSize]){
                PVector lp = map3D[index+xSize];
                if(lp.dist(map3D[index-1]) < maxSep){
                  vertex(lp.x,lp.y,lp.z);
                }
              }
              endShape();
              started = false;
            }
          }
        }
      }
     
    }
    
    
    /*
     * Some useful functions to resize and constrain the Kinect data
     */
    
    void calculateLimits(int[] depthImg, PVector[] map3D){
      xmin = ymin = zmin = 100000;
      xmax = ymax = zmax = -100000;
      
      for(int i = 0; i < depthImg.length; i++){
        if(depthImg[i] > 0){
          PVector p = map3D[i];
          if(p.x < xmin){
            xmin = p.x;
          }
          if(p.x > xmax){
            xmax = p.x;
          }
          if(p.y < ymin){
            ymin = p.y;
          }
          if(p.y > ymax){
            ymax = p.y;
          }
          if(p.z < zmin){
            zmin = p.z;
          }
          if(p.z > zmax){
            zmax = p.z;
          }
        } 
      }
    }  
    
    int[] resizeDepth(int[] depthImg, int n){
      int xSizeOrig = context.depthWidth();
      int ySizeOrig = context.depthHeight();
      int xSize = xSizeOrig/n;
      int ySize = ySizeOrig/n;
      int[] resDepthImg = new int[xSize*ySize];
    
      for(int y = 0; y < ySize; y++){
        for(int x = 0; x < xSize; x++){
          resDepthImg[x + y*xSize] = depthImg[x*n + y*n*xSizeOrig];
        }
      }
      return resDepthImg;
    }
    
    PVector[] resizeMap3D(PVector[] map3D, int n){
      int xSizeOrig = context.depthWidth();
      int ySizeOrig = context.depthHeight();
      int xSize = xSizeOrig/n;
      int ySize = ySizeOrig/n;
      PVector[] resMap3D = new PVector[xSize*ySize];
    
      for(int y = 0; y < ySize; y++){
        for(int x = 0; x < xSize; x++){
          resMap3D[x + y*xSize] = map3D[x*n + y*n*xSizeOrig].get();
        }
      }
      return resMap3D;
    }
    
    PImage resizeRGB(PImage rgbImg, int n){
      int xSizeOrig = context.depthWidth();
      int ySizeOrig = context.depthHeight();
      int xSize = xSizeOrig/n;
      int ySize = ySizeOrig/n;
      PImage resRGB = createImage(xSize,ySize,RGB);
     
      for(int y = 0; y < ySize; y++){
        for(int x = 0; x < xSize; x++){
          resRGB.pixels[x + y*xSize] = rgbImg.pixels[x*n + y*n*xSizeOrig];
        }
      }
      return resRGB; 
    }
    
    boolean[] constrainImg(int[] depthImg, PVector[] map3D, float xMin, float xMax, float yMin, float yMax, float zMin, float zMax){
      boolean[] consImg = new boolean[depthImg.length];
    
      for(int i = 0; i < consImg.length; i++){
        PVector p = map3D[i];
        consImg[i] = (depthImg[i] > 0) && 
                     (p.x > xMin) && (p.x < xMax) && 
                     (p.y > yMin) && (p.y < yMax) && 
                     (p.z > zMin) && (p.z < zMax);
      } 
      return consImg; 
    }  
    
    boolean[] scanPoints(int[] depthImg, PVector[] map3D, PVector centalPoint, float delta){
      boolean[] sPoints = new boolean[depthImg.length];
    
      for(int i = 0; i < sPoints.length; i++){
        PVector p = map3D[i];
        sPoints[i] = (depthImg[i] > 0) && 
                     (p.x > (centalPoint.x-0.5*delta)) && (p.x < (centalPoint.x+0.5*delta)) && 
                     (p.y > (centalPoint.y-0.5*delta)) && (p.y < (centalPoint.y+0.5*delta)) && 
                     (p.z > (centalPoint.z-0.5*delta)) && (p.z < (centalPoint.z+0.5*delta));
      } 
      return sPoints; 
    }  
    
    
    /*
     * Subclass of the KinectPoints class.
     *
     * Implements some functions to create, save and represent a mesh 
     * of the scanned points
     *
     */
    
    class Scan extends KinectPoints{
      HE_Mesh mesh;
      color[] colors;
    
      Scan(PVector[] tempMap3D, PImage tempRGBimg, boolean[] tempConsImg){
        super(tempMap3D,tempRGBimg,tempConsImg);
      }
      
      void createMesh(){
        ArrayList faceList = new ArrayList(); 
        ArrayList colorList = new ArrayList();
        int xSize = rgbImg.width;
        int ySize = rgbImg.height;
        float maxSep = 90;  // Maximum separation allowed between two consecutive points
        
        for(int y = 0; y < ySize-1; y++){
          for(int x = 0; x < xSize-1; x++){
            int index = x + y*xSize;
            // First triangle
            if(consImg[index] && consImg[index+1] && consImg[index+xSize]){
              PVector p1 = map3D[index];
              PVector p2 = map3D[index+1];
              PVector p3 = map3D[index+xSize];
              if((p1.dist(p2) < maxSep) && (p1.dist(p3) < maxSep) && (p2.dist(p3) < maxSep)){
                WB_Point3d hp1 = new WB_Point3d(p1.x,p1.y,p1.z);
                WB_Point3d hp2 = new WB_Point3d(p2.x,p2.y,p2.z);
                WB_Point3d hp3 = new WB_Point3d(p3.x,p3.y,p3.z);
                faceList.add(new WB_ExplicitTriangle(hp1,hp2,hp3));
                colorList.add((color) rgbImg.pixels[index]);
              }
            }
            // Second triangle
            if(consImg[index+1] && consImg[index+1+xSize] && consImg[index+xSize]){
              PVector p1 = map3D[index+1];
              PVector p2 = map3D[index+1+xSize];
              PVector p3 = map3D[index+xSize];
              if((p1.dist(p2) < maxSep) && (p1.dist(p3) < maxSep) && (p2.dist(p3) < maxSep)){
                WB_Point3d hp1 = new WB_Point3d(p1.x,p1.y,p1.z);
                WB_Point3d hp2 = new WB_Point3d(p2.x,p2.y,p2.z);
                WB_Point3d hp3 = new WB_Point3d(p3.x,p3.y,p3.z);
                faceList.add(new WB_ExplicitTriangle(hp1,hp2,hp3));
                colorList.add((color) rgbImg.pixels[index]);
              }
            }
          }
        }
       
        // Create the mesh from the faceList
        HEC_FromTriangles creator = new HEC_FromTriangles();
        creator.setTriangles(faceList);
        mesh = new HE_Mesh(creator); 
        //mesh.validate(true,true);
        
        // Transform the color ArrayList into a simple Array (faster?) 
        colors = new color[colorList.size()];
        Iterator iter = colorList.iterator();
        for(int i = 0; iter.hasNext(); i++){
          colors[i] = (color)(Integer) iter.next();
        }
      }
        
      void saveMesh(String file){
        HET_Export.saveToHemesh(mesh,sketchPath(file+".hemesh")); 
        println("mesh saved in "+file+".hemesh");
    
        String[] s = new String[colors.length];
        for(int i = 0; i < colors.length; i++){
          s[i] = red(colors[i])+" "+green(colors[i])+" "+blue(colors[i]);
        }
        saveStrings(file+".col",s);
        println("colors saved in "+file+".col");
      }
    
      void drawMesh(){
        noStroke();
    
        Iterator<HE_Face> iter = mesh.fItr();
        for(int i = 0; iter.hasNext(); i++){
          HE_Face f = iter.next();
          fill(colors[i]);
          render.drawFace(f);
        }
      }
    
      void drawMesh(color col){
        noStroke();
        fill(col);
        
        render.drawFaces(mesh);
        // Draw the face normals
        //stroke(color(255,0,0));
        //render.drawFaceNormals(20,mesh);
      }
      
    }
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Javier Graciá Carpio

    Kinect 3D scanner

    Add to Faves Me Likey@! 8
    You must login/register to add this sketch to your favorites.

    Simple 3D scanner using the Kinect.

    Doesn't work in the browser. You need a Kinect to run it and the controlP5 (version controlP5_1.5.1), hemesh and simple-openni libraries installed.

    Select the scanner area with the controls and press the "take scan" button to capture the 3D points inside the box. A mesh is created with the Hemesh library and saved in the sketch directory. The colors of the mesh faces are saved in a different file. Press the "take scan" button again to take more scans.

    Use http://www.openprocessing.org/sketch/62533 to read and represent the mesh.

    Ian C
    26 Aug 2012
    The SimpleOpenNi examples work for me, and I have the 2 libraries, but
    I get this error when I try to run this:

    Exception in thread "Animation Thread" java.lang.NoSuchMethodError: SwigDirector_ContextWrapper_onExitUserCb
    at SimpleOpenNI.SimpleOpenNIJNI.swig_module_init(Native Method)
    at SimpleOpenNI.SimpleOpenNIJNI.<clinit>(SimpleOpenNIJNI.java:1553)
    at SimpleOpenNI.ContextWrapper.<init>(ContextWrapper.java:54)
    at SimpleOpenNI.SimpleOpenNI.<init>(SimpleOpenNI.java:209)
    at kinect3Dscanner.setup(kinect3Dscanner.java:121)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:722)
    Hi Ian. Which version of processing are you using? I only tested it in 1.5.1. It could also be that something in the last version of the SimpleOpenNi library has changed. The last version is from May 27th and I uploaded this sketch in May 23, so I guess I was using version 0.17. I'll check that today when I get home.

    Thank you for trying it!
    masm
    27 Aug 2012
    Hey, I have the same problem as Ian. How could I fix the problem? Install previous version of processing or the code can be fixed somehow?
    Cheers, Maria
    Hi Ian and Maria. I installed the latest version of the simpleOpenNI library (0.27) together with the latest OpenNI (1.5.4.0), NITE (1.5.2.21) and kinect driver (5.1.2.1). The sketch works in my laptop (Linux) in processing 1.5.1 and 2.0a8. Which operating system are you using?
    Sergio
    27 Sep 2012
    Hi!
    I get the following error messages:

    Display 0 does not exist, using the default display instead.
    Exception in thread "Animation Thread" java.lang.NoSuchMethodError: SwigDirector_ContextWrapper_onExitUserCb
    at SimpleOpenNI.SimpleOpenNIJNI.swig_module_init(Native Method)
    at SimpleOpenNI.SimpleOpenNIJNI.<clinit>(SimpleOpenNIJNI.java:1553)
    at SimpleOpenNI.ContextWrapper.<init>(ContextWrapper.java:54)
    at SimpleOpenNI.SimpleOpenNI.<init>(SimpleOpenNI.java:209)
    at kinect3Dscanner.setup(kinect3Dscanner.java:122)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:680)
    Hi Sergio! Can you tell in which line of the code is this error produced? You tried the examples that come with the SimpleOpenNI library and they work for you, right?
    Sergio
    28 Sep 2012
    hi!
    This is all it says:

    Display 0 does not exist, using the default display instead.
    java.lang.NullPointerException
    at processing.mode.java.runner.Runner.findException(Runner.java:664)
    at processing.mode.java.runner.Runner.reportException(Runner.java:609)
    at processing.mode.java.runner.Runner.exception(Runner.java:552)
    at processing.mode.java.runner.EventThread.exceptionEvent(EventThread.java:367)
    at processing.mode.java.runner.EventThread.handleEvent(EventThread.java:255)
    at processing.mode.java.runner.EventThread.run(EventThread.java:89)
    Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: --full-screen
    at processing.core.PApplet.runSketch(Unknown Source)
    at processing.core.PApplet.main(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: --full-screen
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 2 more
    Are you using the Processing IDE? It should highlight in red the line in the sketch where it crashes. Did you try the examples?
    Sergio
    1 Oct 2012
    Here it goes an screenshot. it might help better than my explanations :)
    https://www.dropbox.com/s/vzoli6w3ph7a7ti/Screen Shot 2012-09-28 at 18.23.01.png
    Hi!
    I see you're using processing 2.0b3. Can you try version 1.5.1 to see if it works there?
    And again, did you try the examples that come with the SimpleOpenNI library? If they also produce an error, it will be related with the SimpleOpenNI installation and not with my sketch.
    Sergio
    2 Oct 2012
    Hi again!

    https://www.dropbox.com/s/xltbmrw2213wzk0/Screen Shot 2012-10-02 at 15.26.33.png

    this is with 1.5.1. SimpleOpenNI examples run just fine with both versions :)
    :(
    I'm quite new in Java and those error messages are difficult to understand....

    Can you try my other Kinect sketch?
    http://www.openprocessing.org/sketch/60316
    and the mesh viewer?
    http://www.openprocessing.org/sketch/62533
    I would like to know if it's related with one of the libraries I'm using.

    Which version of the ControlP5 library are you using? I tested it with the version from 04/09/2012:
    http://code.google.com/p/controlp5/downloads/detail?name=controlP5-0.7.2.zip&can=1&q=
    but I just realized they updated it recently. I'll test it with the new version when I get home.
    I have the feeling that is gonna be the controlP5 version...
    Sergio
    3 Oct 2012
    I'm not really sure it will be it. Ive tried the IP5 examples and they work just fine... :(
    Yes, but if they changed something in the library, older examples (like my sketch) may crash. I'll try it this evening, I'm busy now :)
    Sergio
    3 Oct 2012
    Thanks so much!
    Hi Sergio!
    I tested the sketch with processing 1.5.1 and the last controlP5 library version that is still compatible with processing 1.5.1 and it works. It also works with processing 2.0b3 and the same version of the controlP5 library:
    http://code.google.com/p/controlp5/downloads/detail?name=controlP5-1.5.1.zip

    However it doesn't work with processing 2.0b3 and the latest release of the controlP5 library. Andreas Schlegel has introduced significant changes in this new version, and some of the options I was using before have changed.

    I'll try to update the sketch in the next days to make it compatible with that library again, but for the moment please use the version from the link above.

    Let me know if this fixes the problem!
    Sergio
    4 Oct 2012
    Now I'm quite lost here. I did what you suggested and it didn't work. I've tried the code in a macbook pro with os x 10.7 instead of the 10.8 and still get the same error. Damn!
    Well, we found one error, there are clearly more ;)
    Can you try this sketch?
    http://www.openprocessing.org/sketch/60316
    That one I know it worked for other people, so if it doesn't work for you, then it must be related with your installation.
    I requires also controlP5-1.5.1
    Sergio
    4 Oct 2012
    Hi! This works but it crash with the following message when using the sliders. You might be right then about the controlP5 thing.

    Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 8480
    at kinect$Particles.paint(kinect.java:1020)
    at kinect.draw(kinect.java:177)
    at processing.core.PApplet.handleDraw(PApplet.java:1631)
    at processing.core.PApplet.run(PApplet.java:1530)
    at java.lang.Thread.run(Thread.java:680)
    Sergio
    4 Oct 2012
    it works better with the 2.03b
    That's when you change the resolution, right? That happens sometimes (not always) if you move the slider too fast, but it shouldn't happen with the other sliders. If this one works in your Mac, then the problem is somewhere in the kinect scanner sketch. I'll think about it...
    Good to know that the other one works! :)
    Sergio
    5 Oct 2012
    Yep :) Im so eager to be able to play with the scanner, hehehe
    I'm currently working on an improved version that is able to reconstruct the full (360 degrees) 3D shape of small objects combining various scans taken from different angles.
    It will also allow you to create 3D slit scans, as I show in this video:

    https://vimeo.com/50476546

    Playing with the Kinect is fun!
    BTW, are you also Spanish?
    Sergio
    5 Oct 2012
    Sí, señor! :)
    A ver si consigo hacer funcionar tu scanner y me pongo a trastear un poco más. De programación no tengo mucha idea pero tengo ganas de pasar los archivos a cinema y trastear. A ver si hay suerte!

    Por cierto, mil gracias por la ayuda!!!!
    Hi Sergio, masm and Ian C! I just uploaded an improved version of the sketch:
    http://www.openprocessing.org/sketch/78606
    Several thinks changed, so, if we are lucky, the problem you were having might be solved now. Please try it and let me know if it works in your computer!
    Jens
    12 Jan 2013
    When trying to "save scan" I get an error on this line in "kinectPoints":
    map3D[i] = tempMap3D[i].get();

    Take scan: Done (scan 1)
    Exception in thread "Animation Thread" java.lang.NullPointerException
    at kinect3DscannerV2$KinectPoints.<init>(kinect3DscannerV2.java:827)
    at kinect3DscannerV2$Scan.<init>(kinect3DscannerV2.java:1084)
    at kinect3DscannerV2$Scan.crop(kinect3DscannerV2.java:1249)
    at kinect3DscannerV2$Scan.savePoints(kinect3DscannerV2.java:1256)
    at kinect3DscannerV2.draw(kinect3DscannerV2.java:237)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:680)

    Any idea what's causing this?
    Jens
    12 Jan 2013
    It's the same in both Processing 1.5 and 2.0b7
    Hi Jens, I posted a new version of the kinect scanner http://www.openprocessing.org/sketch/78606
    Try it and tell me if you find the same problem.
    Cheers!
    Jens
    14 Jan 2013
    Hi Javier. Thanks for responding. I already use the newest example (sorry for commenting in an earlier version.
    Did you click the "take scan" button before you clicked the "save scan" button?

    It could also be that the scanbox doesn't contain any points... You should make sure there are some points inside (but I agree, that's a bug in my code. It should check that first :))
    fabian urban
    1 Apr 2013
    Hi all!! I have a problem,

    "Cannot find a class or type named "iterator""

    I have 2.0b.3 Processing and mac os x. what may be happening? thank you very much!
    Hola fabian!

    This is an old version of the sketch. Try this other one and tell me if it works:
    http://www.openprocessing.org/sketch/78606

    It will not work with modern versions of the controP5 library. You have to install this older version:
    http://code.google.com/p/controlp5/downloads/detail?name=controlP5-1.5.1.zip

    Good luck!
    Umair Ullah
    25 May 2013
    How to merge all the scans to develop a 3d model ???
    EdmondMak
    18 Aug 2013
    java.lang.NullPointerException
    at processing.mode.java.runner.Runner.findException(Runner.java:925)
    at processing.mode.java.runner.Runner.reportException(Runner.java:870)
    at processing.mode.java.runner.Runner.exceptionEvent(Runner.java:813)
    at processing.mode.java.runner.Runner$2.run(Runner.java:699)

    What's wrong with me?
    Thanks!
    Hi EdmondMak,
    This is an old version of the kinect scanner . I posted a newer version here

    http://www.openprocessing.org/sketch/78606

    Can you try it and tell me if you find the same problem?
    Cheers!
    You need to login/register to comment.