# How can get the body outline contour through the Kinect?

**URL:** <https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384>\
**Category:** Libraries\
**Created:** [April 17, 2019, 8:44am UTC](https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384 "2019-04-17T08:44:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiangjun](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jiangjun](https://discourse.processing.org/u/jiangjun)\
**Post date:** [April 17, 2019, 8:44am UTC](https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384/1 "2019-04-17T08:44:15Z")

</div>

```auto
// 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.

 ![WechatIMG4](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/48a03627c4dde678d261bd391240010c52101817.jpeg)  
(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!

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 19, 2019, 10:29pm UTC](https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384/2 "2019-04-19T22:29:17Z")

</div>

> [@jiangjun](#):
>
> opencv.loadImage(kinect.getColorImage())

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](https://discourse.processing.org/t/how-to-use-heat-map-colors-to-filter-a-persons-silhouette/304/18)

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

> **[GitHub - ThomasLengeling/KinectPV2: Kinect4W 2.0 library for Processing](https://github.com/ThomasLengeling/KinectPV2)**
>
> Kinect4W 2.0 library for Processing. Contribute to ThomasLengeling/KinectPV2 development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![jiangjun](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jiangjun](https://discourse.processing.org/u/jiangjun)\
**Post date:** [April 20, 2019, 7:11am UTC](https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384/3 "2019-04-20T07:11:13Z")

</div>

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. ![WechatI2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/55e1ccc33ad3151f745312351c661b7c485c1d95.jpeg)
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

---

<div class="post-metadata">

**Author:** ![jiangjun](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jiangjun](https://discourse.processing.org/u/jiangjun)\
**Post date:** [April 20, 2019, 7:13am UTC](https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384/4 "2019-04-20T07:13:15Z")

</div>

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

 ![WechaMG4](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/146d01a11914062b96512fa731a527cb0f268a39.jpeg) will show the weird picture.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 20, 2019, 2:57pm UTC](https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384/5 "2019-04-20T14:57:25Z")

</div>

Did you look at the MaskTest example I linked?

---

<div class="post-metadata">

**Author:** ![jiangjun](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jiangjun](https://discourse.processing.org/u/jiangjun)\
**Post date:** [April 21, 2019, 1:56am UTC](https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384/6 "2019-04-21T01:56:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dash008](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@dash008](https://discourse.processing.org/u/dash008)\
**Post date:** [February 22, 2020, 1:56am UTC](https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384/7 "2020-02-22T01:56:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dash008](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@dash008](https://discourse.processing.org/u/dash008)\
**Post date:** [February 22, 2020, 2:13am UTC](https://discourse.processing.org/t/how-can-get-the-body-outline-contour-through-the-kinect/10384/8 "2020-02-22T02:13:14Z")

</div>

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.
