# Image error with face detector( noob question)

**URL:** <https://discourse.processing.org/t/image-error-with-face-detector-noob-question/21536>\
**Category:** Libraries\
**Tags:** homework\
**Created:** [June 3, 2020, 7:56pm UTC](https://discourse.processing.org/t/image-error-with-face-detector-noob-question/21536 "2020-06-03T19:56:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![panic](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@panic](https://discourse.processing.org/u/panic)\
**Post date:** [June 3, 2020, 7:56pm UTC](https://discourse.processing.org/t/image-error-with-face-detector-noob-question/21536/1 "2020-06-03T19:56:00Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

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

```auto
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();
}

```

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 3, 2020, 11:21pm UTC](https://discourse.processing.org/t/image-error-with-face-detector-noob-question/21536/2 "2020-06-03T23:21:10Z")

</div>

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

You need to review [imageMode()](https://processing.org/reference/imageMode_.html) 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

---

<div class="post-metadata">

**Author:** ![panic](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@panic](https://discourse.processing.org/u/panic)\
**Post date:** [June 3, 2020, 11:35pm UTC](https://discourse.processing.org/t/image-error-with-face-detector-noob-question/21536/3 "2020-06-03T23:35:26Z")

</div>

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