Пример #1
0
  /**
   * Draw the given shape, filled with the specified colour.
   *
   * @param s The shape to draw.
   * @param col The colour to fill the polygon with.
   */
  public void drawShapeFilled(final Shape s, Q col) {
    col = this.sanitise(col);
    if (s instanceof Polygon) {
      this.drawPolygonFilled((Polygon) s, col);
    } else {
      this.drawShape(s, col);

      final int minx = (int) Math.max(0, Math.round(s.minX()));
      final int maxx = (int) Math.min(this.targetImage.getWidth(), Math.round(s.maxX()));
      final int miny = (int) Math.max(0, Math.round(s.minY()));
      final int maxy = (int) Math.min(this.targetImage.getHeight(), Math.round(s.maxY()));

      for (int y = miny; y <= maxy; y++) {
        for (int x = minx; x <= maxx; x++) {
          final Pixel p = new Pixel(x, y);
          if (s.isInside(p)) this.targetImage.setPixel(p.x, p.y, col);
        }
      }
    }
  }
  /**
   * {@inheritDoc}
   *
   * @see org.openimaj.video.VideoDisplayListener#beforeUpdate(org.openimaj.image.Image)
   */
  @Override
  public void beforeUpdate(MBFImage frame) {
    if (edgeDetect) frame.processInplace(new CannyEdgeDetector2());

    if (faceDetect) {
      HaarCascadeDetector d = new HaarCascadeDetector(100);
      List<DetectedFace> faces = d.detectFaces(Transforms.calculateIntensityNTSC(frame));

      for (DetectedFace face : faces) {
        Shape transBounds = face.getBounds();
        MBFImageRenderer renderer = frame.createRenderer();
        renderer.drawPolygon(transBounds.asPolygon(), RGBColour.RED);
      }
    }

    if (faceKPDetect) {
      System.out.println("HERE");
      FKEFaceDetector fkp =
          new FKEFaceDetector(HaarCascadeDetector.BuiltInCascade.frontalface_alt.load());
      List<KEDetectedFace> faces = fkp.detectFaces(Transforms.calculateIntensityNTSC(frame));

      for (KEDetectedFace face : faces) {
        Shape transBounds = face.getBounds();
        MBFImageRenderer renderer = frame.createRenderer();
        renderer.drawPolygon(transBounds.asPolygon(), RGBColour.RED);

        for (FacialKeypoint kp : face.getKeypoints()) {
          Point2d pt = kp.position.clone();
          pt.translate((float) transBounds.minX(), (float) transBounds.minY());
          renderer.drawPoint(pt, RGBColour.GREEN, 3);
        }
      }
    }

    if (moustache)
      try {
        frame.internalAssign(new Mustache().addMustaches(frame));
      } catch (IOException e) {
        e.printStackTrace();
      }
  }
Пример #3
0
 /**
  * Draw the given shape in the specified colour with the given thickness lines.
  *
  * @param s The shape to draw.
  * @param thickness The thickness of the lines to use
  * @param col The colour to draw the lines in
  */
 public void drawShape(final Shape s, final int thickness, final Q col) {
   this.drawPolygon(s.asPolygon(), thickness, col);
 }