How can get the body outline contour through the Kinect?

#1
// 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!

0 Likes

#2
  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?

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

0 Likes

#3
  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
0 Likes

#4

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

will show the weird picture.

0 Likes

#5

Did you look at the MaskTest example I linked?

0 Likes

#6

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

1 Like