Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
vardanagarwal
GitHub Repository: vardanagarwal/Proctoring-AI
Path: blob/master/__pycache__/face_detector.cpython-37.pyc
454 views
B

4�!_�@s2dZddlZddlZddd�Zdd�Zd	d
�ZdS)z2
Created on Wed Jul 29 17:52:00 2020

@author: hp
�N�/models/res10_300x300_ssd_iter_140000.caffemodel�models/deploy.prototxtcCsd}d}tj�||�}|S)a{
    Get the face detection caffe model of OpenCV's DNN module
    
    Parameters
    ----------
    modelFile : string, optional
        Path to model file. The default is "models/res10_300x300_ssd_iter_140000.caffemodel".
    configFile : string, optional
        Path to config file. The default is "models/deploy.prototxt".

    Returns
    -------
    model : dnn_Net

    z/models/res10_300x300_ssd_iter_140000.caffemodelzmodels/deploy.prototxt)�cv2�dnn�readNetFromCaffe)�	modelFile�
configFile�model�r
�6C:\Users\hp\Desktop\minor project\new\face_detector.py�get_face_detectorsrcCs�|jdd�\}}tj�t�|d�ddd�}|�|�|��}g}xxt|jd�D]f}|dd|df}|dkrR|dd|dd	�ft�	||||g�}	|	�
d
�\}
}}}
|�|
|||
g�qRW|S)a
    Find the faces in an image
    
    Parameters
    ----------
    img : np.uint8
        Image to find faces from
    model : dnn_Net
        Face detection model

    Returns
    -------
    faces : list
        List of coordinates of the faces detected in the image

    N�)i,i,g�?)gZ@g f@g�^@rg�?���int)�shaperr�
blobFromImage�resize�setInput�forward�range�np�array�astype�append)�imgr	�h�w�blob�res�faces�i�
confidence�box�x�y�x1�y1r
r
r�
find_faces!s
&r(cCs4x.|D]&\}}}}t�|||f||fdd�qWdS)z�
    Draw faces on image

    Parameters
    ----------
    img : np.uint8
        Image to draw faces on
    faces : List of face coordinates
        Coordinates of faces to draw

    Returns
    -------
    None.

    )rr��rN)r�	rectangle)rr r$r%r&r'r
r
r�
draw_faces@sr+)rr)�__doc__r�numpyrrr(r+r
r
r
r�<module>s