Class FaceRecognizer


  • public class FaceRecognizer
    extends java.lang.Object
    A face recognition image filter. This filter detects faces in the given frame that lie in a square of dimensions [x,x], where _minFaceSize <= x >= _maxFaceSize. The parameters of the filter are:
    • MinFaceSize: Minimum face size to be considered ( one side of a bounding square)
    • MaxFaceSize: Maximum face size to be considered ( one side of a bounding square)
    The class uses Haar Cascade classifier based object detection, as well as the classifiers for frontal face recognition are based on implementations provided by OpenCV 3.1.0.
    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Ilge Akkaya
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (cxh)
    • Constructor Summary

      Constructors 
      Constructor Description
      FaceRecognizer()
      Construct an instance of FaceRecognizer and load the face recognition classifier.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.opencv.core.Mat bufferedImage2Mat​(java.awt.image.BufferedImage source)
      Convert a BufferedImage object to OpenCV's Mat representation.
      org.opencv.core.Rect[] detectFaces​(org.opencv.core.Mat img)
      Detect faces.
      java.awt.image.BufferedImage filter​(java.awt.image.BufferedImage source, java.lang.String filterName)
      Apply the specified filter to the source image.
      int getFaceCount()
      Return the number of faces detected.
      org.opencv.core.Rect[] getFaceRectangles()
      Return the number of faces detected.
      java.awt.image.BufferedImage mat2BufferedImage​(org.opencv.core.Mat matrix)
      Convert a Mat image into a BufferedImage.
      void setMaxFaceSize​(int size)
      Set the maximum face size.
      void setMinFaceSize​(int size)
      Set the minimum face size.
      java.lang.String toString()
      Return a string description of the filter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • FaceRecognizer

        public FaceRecognizer()
                       throws java.io.IOException
        Construct an instance of FaceRecognizer and load the face recognition classifier.
        Throws:
        java.io.IOException - If the shared library cannot be found.
    • Method Detail

      • filter

        public java.awt.image.BufferedImage filter​(java.awt.image.BufferedImage source,
                                                   java.lang.String filterName)
                                            throws IllegalActionException
        Apply the specified filter to the source image.
        Parameters:
        source - The source image to transform.
        filterName - "eyes" or "faces".
        Returns:
        The transformed image.
        Throws:
        IllegalActionException - If the filter is anything other than "eyes" or "faces".
      • bufferedImage2Mat

        public org.opencv.core.Mat bufferedImage2Mat​(java.awt.image.BufferedImage source)
        Convert a BufferedImage object to OpenCV's Mat representation.
        Parameters:
        source - BufferedImage input
        Returns:
        Mat matrix
      • mat2BufferedImage

        public java.awt.image.BufferedImage mat2BufferedImage​(org.opencv.core.Mat matrix)
        Convert a Mat image into a BufferedImage.
        Parameters:
        matrix - Mat input
        Returns:
        BufferedImage output
      • detectFaces

        public org.opencv.core.Rect[] detectFaces​(org.opencv.core.Mat img)
                                           throws java.io.IOException
        Detect faces.
        Parameters:
        img - The image containing faces
        Returns:
        An array of faces.
        Throws:
        java.io.IOException - if the haar cascade file cannot be found.
      • getFaceCount

        public int getFaceCount()
        Return the number of faces detected.
        Returns:
        The number of faces detected.
      • getFaceRectangles

        public org.opencv.core.Rect[] getFaceRectangles()
        Return the number of faces detected.
        Returns:
        The number of faces detected.
      • setMinFaceSize

        public void setMinFaceSize​(int size)
                            throws IllegalActionException
        Set the minimum face size.
        Parameters:
        size - the minimum face size, which must be positive.
        Throws:
        IllegalActionException - If the value of the size parameter is less than 0.
      • setMaxFaceSize

        public void setMaxFaceSize​(int size)
                            throws IllegalActionException
        Set the maximum face size.
        Parameters:
        size - the maximum face size, which must be positive.
        Throws:
        IllegalActionException - If the value of the size parameter is less than 0.
      • toString

        public java.lang.String toString()
        Return a string description of the filter.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string "MotionDetectorFilter".