How can get the body outline contour through the Kinect?

// code goes here
import gab.opencv.*;
import KinectPV2.KJoint;
import KinectPV2.*;
KinectPV2 kinect;
OpenCV opencv;


void setup() {
  //size(512, 424, P3D);
  fullScreen();
  opencv=new OpenCV(this,1920,1080);


  // Writing to the depth buffer is disabled to avoid rendering
  // artifacts due to the fact that the particles are semi-transparent
  // but not z-sorted.
  hint(DISABLE_DEPTH_MASK);
 
  kinect = new KinectPV2(this);
  kinect.enableDepthImg(true);
  kinect.enablePointCloud(true);
  kinect.enableSkeletonColorMap(true);
  kinect.enableColorImg(true);
  kinect.enableBodyTrackImg(true);

  kinect.init();
 
} 

void draw () {
  background(#0d0d0d);
  
  boolean contourBodyIndex=false;
  int threshold=100;
  double polygonFactor=1.00;
  
  opencv.loadImage(kinect.getColorImage());
  opencv.gray();
  opencv.threshold(threshold);

  //opencv.updateBackground();
  opencv.dilate();
  opencv.erode();
    
  
  

  ArrayList<Contour> contours = opencv.findContours(false, false); // zhao yi dui lun kuo

  if (contours.size() > 0) {
    for (Contour contour : contours) { 
      contour.setPolygonApproximationFactor(polygonFactor); // can shu 
      if (contour.numPoints() > 50) {
        stroke(0, 200, 200); // miao bian
        strokeWeight(1);
        noFill();
        beginShape();
        for (PVector point : contour.getPolygonApproximation ().getPoints()) {
          vertex(point.x, point.y); // the third pic
        }
        endShape();
      }
    }
  }
}

I have two questions:
(1) Actually, I want to just get the body outline contour. And this is right now picture.


(2) I have tried to change the "opencv.loadImage(kinect.getColorImage()); " getColorImage() to get BodyTrackImage(), but the picture size is so weird.

Thanks a lot!

  1. I don’t have a kinect to test here, but it looks like you are trying to find contours on the color image – not on the depth image. Is that what you meant to do? Are you working from an example sketch? What kind of contour are you trying to find – the silhouette of a person?

  2. I believe that the two cameras (the color camera and depth camera) are different sizes. Many kinect tutorials suggest ways of dealing with this issue.

You might also find this helpful – another kinect project with silhouettes. How to use heat map colors to filter a person's silhouette? - #18 by clab

Have you tried the MaskTest example from the library you are using?

  1. Actually, I have tried color image, depth image, body track image, but all can only be displayed by a small window whose size is 512x414.
  2. Plz look at the picture. This kind of contour is what I want to get rather than silhouette of a person. I have uploaded

Furthermore, if I change the opencv(this,512,414); to opencv(this,1920,1080).
the window

will show the weird picture.

Did you look at the MaskTest example I linked?

Thanks sooooooo much! I have seen your example and know how to change the picture size and I did it!

1 Like

Hi! I’m having the same issue with rescaling a contour using the IR image. I have read the MaskTest example but, still not finding the way to do it.

Nevermind, I just found a way to do it. When adding the vertex in the contour, insted of adding the point x position, and the point y position, just multiply a number to scale it so if it is vertex(point.x,point.y) change it for vertex(point.x * n, point.y * n), where n is the number to scale.

1 Like