Beispiel #1
0
def histeq(img):
    rh, rw, rc = img.shape
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img2 = None
    img2 = cv2.equalizeHist(gray)
    cv2.imshow('img', gray)
    cv2.imshow('img2', img2)
    cv2.waitKey(10000)
    cv2.destroyAllWindows()
Beispiel #2
0
def histeq(img):
    rh, rw, rc = img.shape
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img2 = None
    img2 = cv2.equalizeHist(gray)
    cv2.imshow('img', gray)
    cv2.imshow('img2', img2)
    cv2.waitKey(10000)
    cv2.destroyAllWindows()
Beispiel #3
0
def sharpen(img):
    rh, rw, rc = img.shape
    img2 = np.zeros((rh, rw, 3), dtype=np.uint8);
    kernel_size = 3
    scale = 1
    delta = 0
    ddepth = cv2.CV_64F
    img2 = cv2.convertScaleAbs(cv2.Laplacian(img,ddepth,ksize = kernel_size,scale = scale,delta = delta))
    
    sharpened = cv2.addWeighted(img, 1, img2, -0.5, 0)
    cv2.imshow('original img', img)
    cv2.imshow('sharpened img', sharpened)
    cv2.waitKey(5000)
    cv2.destroyAllWindows()
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)
Beispiel #5
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)
    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()
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()