Image error with face detector( noob question)

please format code with </> button * homework policy * asking questions

Hello, I am trying to put an image instead of a square in the face detector code and on a video and it gives me error the image is too big, it does not only occupy the face

import gab.opencv.*;

import processing.video.*;
import java.awt.*;
Capture cam;
OpenCV opencv;
Movie film;
PImage cara;

void settings() {
  size(640, 480);
}

void setup() {  
  cara= loadImage("cara.jpg");
  colorMode(HSB, 256, 256, 256);

  film= new Movie(this, "Secuencia 01_2.mp4");
  cam = new Capture(this, width, height);  

  opencv = new OpenCV(this, width, height);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  cam.start();
  film.loop();


  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
}

void draw() {
  background(250, 150, 0);

  //scale(2);
  opencv.loadImage(cam);

  //video.loadPixels();  
  image(film, 0, 0);
  loadPixels();

  Rectangle[] faces = opencv.detect();



  if (frameCount%15==0) println(faces.length);

  for (int x = 0; x < film.width; x++) {    
    for (int y = 0; y < film.height; y++) {      
      // Calculate the 1D location from a 2D grid
      int loc = x + y * film.width;      

      float h= hue(film.pixels[loc]);
      float s= saturation(film.pixels[loc]);
      float br= brightness(film.pixels[loc]);



      for (int i = 0; i < faces.length; i++) {
        //println(faces[i].x + "," + faces[i].y);
        float d = dist(faces[i].x, faces[i].y, faces[i].width, faces[i].height);      
        float adjustbrightness = map(d, 50, 200, 0, 255);


        color c = color(h, s, br);      
     
      }
    }
  }
  updatePixels();

  for (int i = 0; i < faces.length; i++) {
    //println(faces[i].x + "," + faces[i].y);
    float d = dist(faces[i].x, faces[i].y, faces[i].width, faces[i].height);

        image(cara,faces[i].width, faces[i].height);  
    
    if (frameCount%15==0) println(faces[i].x, faces[i].y, d);
  }
}


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

void movieEvent(Movie m) {
  m.read();
}
1 Like

Note that image() takes a fourth and fifth parameter. That is what you need.

You need to review imageMode() as it might be convenient to use another mode. You might find the default mode corners is convenient if it matches the behavior provided by OpenCV.

Kf

2 Likes

Thank you very much, I checked that part and I was able to adapt it to the face detector, thank you very much !! :smiling_face_with_three_hearts: