def show_face_body(img):
    xcrop_bias = 50
    body_head_portion = 5

    start = time.time()
    rh, rw, rc = img.shape
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
    
    for (x,y,w,h) in faces:
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        if y+h*2 > rh:
            continue
        crop_img = img[y+h:y+h*body_head_portion, x-xcrop_bias:x+w+xcrop_bias]
        cv2.rectangle(img, (x-xcrop_bias,y+h), (x+w+xcrop_bias, y+h*body_head_portion), (0, 255, 0), 2)
        #cv2.imwrite(img_path+'/'+f+'_'+str(ct)+'.jpg', crop_img)
    cv2.imshow('img',img)
    cv2.waitKey(1000)
    cv2.destroyAllWindows()
    end = time.time()
    print 'total time consumed: %d'%int(end - start)
Esempio n. 2
0
def show_face_body(img):
    xcrop_bias = 50
    body_head_portion = 5

    start = time.time()
    rh, rw, rc = img.shape
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        if y + h * 2 > rh:
            continue
        crop_img = img[y + h:y + h * body_head_portion,
                       x - xcrop_bias:x + w + xcrop_bias]
        cv2.rectangle(img, (x - xcrop_bias, y + h),
                      (x + w + xcrop_bias, y + h * body_head_portion),
                      (0, 255, 0), 2)
        #cv2.imwrite(img_path+'/'+f+'_'+str(ct)+'.jpg', crop_img)
    cv2.imshow('img', img)
    cv2.waitKey(1000)
    cv2.destroyAllWindows()
    end = time.time()
    print 'total time consumed: %d' % int(end - start)
Esempio n. 3
0
    print blurriness
    return blurriness

def get_face_region(gray_frame):
    results = []
    faces = face_cascade.detectMultiScale(gray_frame, 1.3, 5)
    for (x,y,w,h) in faces:
        results.append((x,y,w,h))
    return results

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Test blurriness')
    parser.add_argument('image_path', metavar='image_path', 
                                    help='path of the image that is to be calculated')
    args = parser.parse_args()
    img = cv2.imread(args.image_path)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = get_face_region(gray)
    for item in faces:
        x = item[0]
        y = item[1]
        w = item[2]
        h = item[3]
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        blurriness = get_blurriness(gray[y:y+h, x:x+w])
        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(img,'Blurriness:' + str(blurriness),(x,y), font, 1,(255,255,255),2)
        cv2.imshow('img',img)
        cv2.waitKey(5000)
        cv2.destroyAllWindows()
Esempio n. 4
0
def get_face_region(gray_frame):
    results = []
    faces = face_cascade.detectMultiScale(gray_frame, 1.3, 5)
    for (x, y, w, h) in faces:
        results.append((x, y, w, h))
    return results


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Test blurriness')
    parser.add_argument('image_path',
                        metavar='image_path',
                        help='path of the image that is to be calculated')
    args = parser.parse_args()
    img = cv2.imread(args.image_path)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = get_face_region(gray)
    for item in faces:
        x = item[0]
        y = item[1]
        w = item[2]
        h = item[3]
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        blurriness = get_blurriness(gray[y:y + h, x:x + w])
        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(img, 'Blurriness:' + str(blurriness), (x, y), font, 1,
                    (255, 255, 255), 2)
        cv2.imshow('img', img)
        cv2.waitKey(5000)
        cv2.destroyAllWindows()