How to scale webcamera view when face is detected?

edited April 2016 in Kinect

Webcamera through Processing detects the face, when arduino proximity sensor is activated and put a rectangle around the face, what I would like to do is to make the whole view or just what is inside the rectangle bigger (scale it twice) or rotate or change the collor, when the face is detected. How should I amend my code? Many thanks This is my processing code:

import processing.serial.*;
Serial myPort;

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

Capture video;
OpenCV opencv;

boolean playVid = false;

void setup() {
  size(640, 480);

  myPort = new Serial(this, Serial.list()[1], 9600);
  myPort.bufferUntil('\n');

  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); 

  video.start();
}

void draw() {
  if (myPort.available() > 0) {
    String unoMessage = myPort.readStringUntil('@');

    if (unoMessage != null) { 
      if (unoMessage.equals("StartCamera@")) {
        playVid = true;
        println(unoMessage);
      }
    }
  }

  if (playVid) {
    scale(2);
    opencv.loadImage(video);

    image(video, 0, 0 );

    noFill();
    stroke(0, 255, 0);
    strokeWeight(3);
    Rectangle[] faces = opencv.detect();
    println(faces.length);

    for (int i = 0; i < faces.length; i++) {
      println(faces[i].x + "," + faces[i].y);
      rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    }
  }
}

void captureEvent(Capture c) {
  c.read();
}

Answers

  • edited May 2016
    import processing.serial.*;
    Serial myPort;
    
    import gab.opencv.*;
    import processing.video.*;
    import java.awt.*;
    
    Capture video;
    OpenCV opencv;
    
    boolean playVid = false;
    
    void setup() {
      size(640, 480);
    
      myPort = new Serial(this, Serial.list()[1], 9600);
      myPort.bufferUntil(ENTER);
    
      video = new Capture(this, 640/2, 480/2);
      opencv = new OpenCV(this, 640/2, 480/2);
      opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); 
    
      video.start();
    }
    
    void draw() {
      if (myPort.available() > 0) {
        String unoMessage = myPort.readStringUntil('@');
    
        if (unoMessage != null) { 
          if (unoMessage.equals("StartCamera@")) {
            playVid = true;
            println(unoMessage);
          }
        }
      }
    
      if (playVid) {
        scale(2);
        opencv.loadImage(video);
    
        image(video, 0, 0 );
    
        noFill();
        stroke(0, 255, 0);
        strokeWeight(3);
        Rectangle[] faces = opencv.detect();
        println(faces.length);
    
        for (int i = 0; i < faces.length; i++) {
          println(faces[i].x + "," + faces[i].y);
          rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
        }
      }
    }
    
    void captureEvent(Capture c) {
      c.read();
    }
    
Sign In or Register to comment.