dog_breeds_web_app/util.py
def crop_detected_faces(BGR_img, faces):
    """
    Crop faces on the test human image
    Parameters:
        BGR_img: a color (BGR) image has been read by OpenCV
        faces: number of faces that have been detected in an image
    Return:
        cropped_imgs: cropped images with detected faces
    """
    cropped_imgs = []
    offset = 25
    height, width = BGR_img.shape[:2]
    for i in range(len(faces)):
        x,y,w,h = faces[i]
        cropped_img = BGR_img[y-offset : y+h+offset, x-offset : x+w+offset]
        if(y-offset < 0):
            cropped_img = BGR_img[0 : y+h+offset, x-offset : x+w+offset]
        if(x-offset < 0):
            cropped_img = BGR_img[y-offset : y+h+offset, 0 : x+w+offset]
        if(y+h+offset > height):
            cropped_img = BGR_img[y-offset : height, 0 : x+w+offset]
        if(x+w+offset > width):
            cropped_img = BGR_img[y-offset : y+h+offset, 0 : width]
        cropped_imgs.append(cropped_img)
    return cropped_imgs

    Crop faces on the test human image
    Parameters:
        BGR_img: a color (BGR) image has been read by OpenCV
        faces: number of faces that have been detected in an image
    Return:
        cropped_imgs: cropped images with detected faces
    
Crop faces on the test human image
Crop faces on the test human image
def crop_detected_faces(BGR_img, faces):
    cropped_imgs = []
    offset = 25
    height, width = BGR_img.shape[:2]
    for i in range(len(faces)):
        x,y,w,h = faces[i]
        cropped_img = BGR_img[y-offset : y+h+offset, x-offset : x+w+offset]
        if(y-offset < 0):
            cropped_img = BGR_img[0 : y+h+offset, x-offset : x+w+offset]
        if(x-offset < 0):
            cropped_img = BGR_img[y-offset : y+h+offset, 0 : x+w+offset]
        if(y+h+offset > height):
            cropped_img = BGR_img[y-offset : height, 0 : x+w+offset]
        if(x+w+offset > width):
            cropped_img = BGR_img[y-offset : y+h+offset, 0 : width]
        cropped_imgs.append(cropped_img)
    return cropped_imgs
def crop_detected_faces ( BGR_img , faces ) : cropped_imgs = [ ] offset = 25 height , width = BGR_img . shape [ : 2 ] for i in range ( len ( faces ) ) : x , y , w , h = faces [ i ] cropped_img = BGR_img [ y - offset : y + h + offset , x - offset : x + w + offset ] if ( y - offset < 0 ) : cropped_img = BGR_img [ 0 : y + h + offset , x - offset : x + w + offset ] if ( x - offset < 0 ) : cropped_img = BGR_img [ y - offset : y + h + offset , 0 : x + w + offset ] if ( y + h + offset > height ) : cropped_img = BGR_img [ y - offset : height , 0 : x + w + offset ] if ( x + w + offset > width ) : cropped_img = BGR_img [ y - offset : y + h + offset , 0 : width ] cropped_imgs . append ( cropped_img ) return cropped_imgs
Crop faces on the test human image
Crop faces on the test human image
"""
    Crop faces on the test human image
    Parameters:
        BGR_img: a color (BGR) image has been read by OpenCV
        faces: number of faces that have been detected in an image
    Return:
        cropped_imgs: cropped images with detected faces
    """
BGR_img
a color (BGR) image has been read by OpenCV
a color ( BGR ) image has been read by OpenCV
faces
number of faces that have been detected in an image
number of faces that have been detected in an image