Quantcast
Channel: Kinect - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 530

[Kinect] How to set transparent background except user's silhouette?

$
0
0

Hi, I am quite new to the forum.

I get a lot of help from this forum. And I hope to be able to give back when I will get better with programming:)

I am making a kinect game for my university project, and now I am testing some basic features.

What I want to do is to display only a user's silhouette over a background(game stage etc.)

So I tried to color the pixels of depthImage within a threshold with one color and other pixels with transparent color

color(0, 0, 0, 0);

But when I run the code, transparent pixels are displayed at first, but as a person moves around, the silhouette color remains and overlaps, creating the "Painting" effect.

Demo video: https://youtu.be/KXebF0i0FKg

It would be great if you can tell me what I am doing wrong, or just guide me to the right direction?

Thanks in advance. Here's the code:

import org.openkinect.freenect.*;
import org.openkinect.processing.*;

Kinect kinect;

// Depth image
PImage depthImg;

// Threshold
int minDepth = 450;
int maxDepth = 890;

void setup() {
  size(1280, 720);
  background(145, 170, 180);

  kinect = new Kinect(this);
  kinect.initDepth();
  kinect.enableMirror(true);

  // Silhouette image
  depthImg = new PImage(kinect.width, kinect.height, ARGB);
}

void draw() {

  // Draw the raw image
  //image(kinect.getDepthImage(), 0, 0);

  depthImg.loadPixels();

  // Threshold the depth image
  int[] rawDepth = kinect.getRawDepth();

  for (int x = 0; x < kinect.width; x++) {
    for (int y = 0; y < kinect.height; y++) {
      int index = x + y * kinect.width;
      int p = rawDepth[index];

      if (p > minDepth && p < maxDepth) {
        depthImg.pixels[index] = color(62, 96, 111); //Silhouette color
      } else {
        depthImg.pixels[index] = color(0, 0, 0, 0); // background color
      }
    }
  }

  // Draw the thresholded image
  depthImg.updatePixels();
  imageMode(CENTER);
  image(depthImg, width/2, height - kinect.height / 2);
}

OS: Mac OS Sierra v10.12.6

Processing: v3.3.6

Library: Open Kinect

Kinect Hardware: Microsoft Kinect v1, 1414!


Viewing all articles
Browse latest Browse all 530

Trending Articles