what method two conditional area

edited December 2013 in Library Questions

My Project

Camera => Face Tracking (Output Ellipse) => Face Pixelate

I want smile face.

My camera is not mirroring.

But face tracking library is mirroring.

Face pixelate based in camera data. (not mirrored)

I used scale code for match.

but pixelate area error.

I hope that matchpixelate area (black area) matched yellow ellipse area.

help me.

import gab.opencv.*;
import processing.video.*;
import java.awt.*;

Capture video;
OpenCV opencv;


void setup() {
  size(960, 720);
  video = new Capture(this, 640/4, 480/4);
  opencv = new OpenCV(this, 640/4, 480/4);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  
  smooth();
  video.start();
}

void draw() {
  pushMatrix();
  scale(-6, 6);
  translate(-video.width, 0);

  if (video.available() == true) {
    video.read();
  }
  opencv.loadImage(video);

  image(video, 0, 0 );

  noStroke();
  fill(#FDB503);
  Rectangle[] faces = opencv.detect();
  println(faces.length);

  popMatrix();
  video.loadPixels();

//Face Tracking
  for (int i = 0; i < faces.length; i++) {
    pushMatrix();
    scale(-6, 6);
    translate(-video.width, 0);

    ellipseMode(CORNER);
    ellipse(faces[i].x, faces[i].y, faces[i].width * 1.05, faces[i].height * 1.05);
    ellipseMode(CENTER);
    popMatrix();

//Face Pixelate
    for (int k = 0; k < 160; k++) {
      for (int j= 0; j < 120; j++) {
        int x = k * 6;
        int y = j * 6;

        int loc = (video.width - k - 1) + j*video.width;

        color c = video.pixels[loc];
        float grey = red(c)*0.8+green(c)*0.1+blue(c)*0.1;
        if (grey <=120 || grey >=120 || red(c) >= 192) {
          float disX = (faces[i].x * -4) - x ;
          float disY = (faces[i].y * 15) - y ;

//Pixel Area Conditional
          if (sqrt(sq(disX) + sq(disY)) < faces[i].width*3.15) {
            grey = 0;
            rectMode(CENTER);
            fill(grey);
            noStroke();
            rect(x, y, 6, 6);
          }
        }
      }
    }
  }
}

void captureEvent(Capture c) {
  c.read();
}
Sign In or Register to comment.