CodingTrain / Suggestion-Box

A repo to track ideas for topics
571 stars 86 forks source link

Computer Vision #25

Open shiffman opened 8 years ago

shiffman commented 8 years ago

Great reference by @golanlevin: http://www.flong.com/texts/essays/essay_cvad/

proggreg commented 8 years ago

Will you be doing blob detection with the kinect?

shiffman commented 8 years ago

@proggreg yes, I plan to. I think this should be a part of #24

Pixelinator commented 8 years ago

Could you scan a given image to find a Color Palette of the most used colors in this image?

majman commented 8 years ago

yes please! Would love to see video exploring aspects of CV in p5 along the lines of face recognition (face swapping?), object tracking (snapchat filters), scene detection.

good stuff here: https://trackingjs.com/

meiamsome commented 8 years ago

Reminder from stream: Track cups as ears and replace with cartoon ears

MatiasConTilde commented 8 years ago

@proggreg this is my try on it for the Kinect 2:

import org.openkinect.processing.*;

Kinect2 kinect;

ArrayList <Blob> blobs;

int threshold = 1200;
PImage display;

void setup() {
  size(512, 424, P2D);

  blobs = new ArrayList();

  kinect = new Kinect2(this);
  kinect.initDepth();
  kinect.initDevice();

  display = createImage(kinect.depthWidth, kinect.depthHeight, RGB);
}

void draw() {
  background(0);

  int[] depth = kinect.getRawDepth();
  PImage bkg = kinect.getDepthImage();

  blobs.clear();

  display.loadPixels();
  for (int x = 0; x < kinect.depthWidth; x++) {
    for (int y = 0; y < kinect.depthHeight; y++) {
      int index =  x + y*kinect.depthWidth;
      int rawDepth = depth[index];
      if (rawDepth > 0 && rawDepth < threshold) {
        boolean found = false;
        for (Blob b : blobs) {
          if (b.isNear(x, y, 32)) {
            b.add(x, y);
            found = true;
          }
        }
        if (!found) blobs.add(new Blob(x, y));
        display.set(x, y, color(170, 0, 0));
      } else display.set(x, y, bkg.pixels[index]);
    }
  } 
  display.updatePixels();

  image(display, 0, 0);
  textSize(32);
  text(blobs.size(), 20, 20+32);
  for (Blob b : blobs) b.display();
}

class Blob {
  PVector min, max;

  Blob(float x, float y) {
    min = new PVector(x, y);
    max = new PVector(x, y);
  }

  void add(float x, float y) {
    min.set(min(min.x, x), min(min.y, y));
    max.set(max(max.x, x), max(max.y, y));
  }

  //Very important! This is not my algorithm, it's a modified version of this: http://openprocessing.org/sketch/20795
  boolean isNear(float circleX, float circleY, float radius) {
    float rectangleX = min.x;
    float rectangleY = min.y;
    float rectangleWidth = max.x - rectangleX;
    float rectangleHeight = max.y - rectangleY;
    float circleDistanceX = abs(circleX - rectangleX - rectangleWidth/2);
    float circleDistanceY = abs(circleY - rectangleY - rectangleHeight/2);

    if (circleDistanceX > rectangleWidth/2 + radius) return false;
    if (circleDistanceY > rectangleHeight/2 + radius) return false;
    if (circleDistanceX <= rectangleWidth/2) return true;
    if (circleDistanceY <= rectangleHeight/2) return true;

    float cornerDistanceSq = sq(circleDistanceX - rectangleWidth/2) + sq(circleDistanceY - rectangleHeight/2);

    return (cornerDistanceSq <= sq(radius));
  }

  float size() {
    return min.dist(max);
  }

  void display() {
    rectMode(CORNERS);
    noFill();
    stroke(255);
    rect(min.x, min.y, max.x, max.y);
  }
}
spaanse commented 8 years ago

can you do a live droste effect that replaces a colored square

spaanse commented 8 years ago

Blobs with distance to the nearest pixel is possible, you just forgot to add the first pixel, so it had nothing to compare possible new pixels to, the arraylist size wasn't too big, it was too small: 0 items

shiffman commented 8 years ago

@spaanse aaaaaack, hah, thank you. Will revisit this next time!

spaanse commented 8 years ago

no problem

Pixelinator commented 8 years ago

Skeletal Tracking might be a real cool thing to do (maybe a hard one too)

abb00sh commented 8 years ago

Image display; ---> PImage display;

lfkopp commented 7 years ago

I would love to see the license plate recognition.

jeykech commented 7 years ago

thanx for suggesting my suggestion with these suggestions :) 👍