Example #1
0
def make_mask_test(image_url, bb=None):
    svg_address = constants.svg_folder
    image = Utils.get_cv2_img_array(image_url)  # turn the URL into a cv2 image
    small_image, resize_ratio = background_removal.standard_resize(
        image, 400)  # shrink image for faster process
    bb = [int(b) for b in (np.array(bb) / resize_ratio)
          ]  # shrink bb in the same ratio
    fg_mask = background_removal.get_fg_mask(
        small_image, bb
    )  # returns the grab-cut mask (if bb => PFG-PBG gc, if !bb => face gc)
    # bb_mask = background_removal.get_binary_bb_mask(small_image, bb)            # bounding box mask
    # combined_mask = cv2.bitwise_and(fg_mask, bb_mask)                           # for sending the right mask to the fp
    gc_image = background_removal.get_masked_image(small_image, fg_mask)
    face_rect = background_removal.find_face(small_image)
    if len(face_rect) > 0:
        x, y, w, h = face_rect[0]
        face_image = image[y:y + h, x:x + w, :]
        without_skin = kassper.skin_removal(face_image, gc_image)
        crawl_mask = kassper.clutter_removal(without_skin, 200)
        without_clutter = background_removal.get_masked_image(
            without_skin, crawl_mask)
        mask = kassper.get_mask(without_clutter)
    else:
        mask = kassper.get_mask(gc_image)
    return mask
Example #2
0
def gc2mask_test(image, bb):
    small_image, resize_ratio = background_removal.standard_resize(
        image, 400)  # shrink image for faster process
    bb = np.array(bb) / resize_ratio
    bb = bb.astype(np.uint16)  # shrink bb in the same ratio
    # bb = [int(b) for b in (np.array(bb)/resize_ratio)]
    x, y, w, h = bb
    cv2.rectangle(small_image, (x, y), (x + w, y + h), [0, 255, 0], 2)
    cv2.imshow('1', small_image)
    cv2.waitKey(0)
    fg_mask = background_removal.get_fg_mask(
        small_image, bb
    )  # returns the grab-cut mask (if bb => PFG-PBG gc, if !bb => face gc)
    cv2.imshow('2', background_removal.get_masked_image(small_image, fg_mask))
    cv2.waitKey(0)
    bb_mask = background_removal.get_binary_bb_mask(small_image,
                                                    bb)  # bounding box mask
    cv2.imshow('3', background_removal.get_masked_image(small_image, bb_mask))
    cv2.waitKey(0)
    combined_mask = cv2.bitwise_and(
        fg_mask, bb_mask)  # for sending the right mask to the fp
    cv2.imshow('4',
               background_removal.get_masked_image(small_image, combined_mask))
    cv2.waitKey(0)
    return
Example #3
0
def pd_test(image_url):
    '''not sure if this is currenltly kosher 10.12.16'''
    image = Utils.get_cv2_img_array(image_url)
    mask, labels, pose = paperdoll.paperdoll_parse_enqueue.paperdoll_enqueue(
        image_url, async=False)
    cv2.imshow('image', image)
    cv2.imshow('color_mask', color_paperdoll_mask(mask))
    bgnd_mask = []
    for num in np.unique(mask):
        # convert numbers to labelsC
        category = list(labels.keys())[list(labels.values()).index(num)]
        item_mask = 255 * np.array(mask == num, dtype=np.uint8)
        if category == 'null':
            bgnd_mask = 255 - item_mask
        if cv2.countNonZero(item_mask) > 2000:
            item_image = background_removal.get_masked_image(image, item_mask)
            after_gc = create_gc_mask(image, item_mask, bgnd_mask)
            cv2.imshow(category + "'s image (" + str(num) + ')', item_image)
            cv2.imshow(
                category + "'s gc image",
                background_removal.get_masked_image(
                    image,
                    background_removal.get_masked_image(image, after_gc)))
            # cv2.imshow(category + "'s mask", 255 * item_mask / num)
            cv2.waitKey(0)
            cv2.destroyWindow(category + "'s image (" + str(num) + ')')
            cv2.destroyWindow(category + "'s gc image")
    cv2.destroyAllWindows()
Example #4
0
def get_mask(small_image, bb=None):
    if bb is not None:
        bb = [int(b) for b in (np.array(bb) / resize_ratio)]  # shrink bb in the same ratio
    fg_mask = background_removal.get_fg_mask(small_image, bb)                     # returns the grab-cut mask (if bb => PFG-PBG gc, if !bb => face gc)
    gc_image = background_removal.get_masked_image(small_image, fg_mask)
    without_skin = kassper.skin_removal(gc_image, small_image)
    crawl_mask = kassper.clutter_removal(without_skin, 400)
    without_clutter = background_removal.get_masked_image(without_skin, crawl_mask)
    fp_mask = kassper.get_mask(without_clutter)
    return fp_mask
Example #5
0
 def dress_length():
     lower_body_ycrcb = YCrCb_image[y_split:gc_image.shape[0] - 1, :, :]
     lower_bgr = cv2.cvtColor(lower_body_ycrcb, cv2.COLOR_YCR_CB2BGR)
     only_skin_down = kassper.skin_detection_with_grabcut(
         lower_bgr, image, 'skin')
     only_skin_down = background_removal.get_masked_image(
         lower_bgr, kassper.clutter_removal(only_skin_down, 500))
     legs_prop = legs_face_proportion(face_rect[0], only_skin_down)
     return legs_prop
Example #6
0
def skin_removal_test():
    image, ratio = background_removal.standard_resize(
        background_removal.get_image(), 400)
    fg_mask = background_removal.get_fg_mask(image)
    gc_image = background_removal.get_masked_image(image, fg_mask)
    face_rect = background_removal.find_face(image)
    x, y, w, h = face_rect[0]
    face_image = image[y:y + h, x:x + w, :]
    without_skin = kassper.skin_removal(gc_image, face_image)
    cv2.imshow('original', image)
    cv2.imshow('gc', gc_image)
    cv2.imshow('after skin', without_skin)
    cv2.waitKey(0)
Example #7
0
 def sleeve_length():
     """
     """
     x, y, w, h = face_rect[0]
     upper_body_ycrcb = YCrCb_image[0:y_split, :, :]
     upper_bgr = cv2.cvtColor(upper_body_ycrcb, cv2.COLOR_YCR_CB2BGR)
     only_skin_up = kassper.skin_detection_with_grabcut(
         upper_bgr, upper_bgr, 'skin')
     only_skin_up = background_removal.get_masked_image(
         upper_bgr, kassper.clutter_removal(only_skin_up, 500))
     right_hand = only_skin_up[y + int(1.3 * h):y_split,
                               1:int(x + w / 2), :]
     left_hand = only_skin_up[y + int(1.3 * h):y_split,
                              int(x + w / 2):only_skin_up.shape[1] - 1, :]
     prop_left, prop_right = arms_face_proportions(face_rect[0], right_hand,
                                                   left_hand)
     return prop_left, prop_right
Example #8
0
def item_length_test(dir):
    print dir
    images_list = Utils.get_images_list(dir)
    legs_prop_list = []
    for image in images_list:
        fg_mask = background_removal.get_fg_mask(image)
        gc_image = background_removal.get_masked_image(image, fg_mask)
        legs_prop, prop_left, prop_right = item_length(image, gc_image)
        if legs_prop != -1:
            legs_prop_list.append(legs_prop)
        if len(images_list) > 100:
            break
    fig = plt.hist(legs_prop_list)
    plt.title("proportion Histogram")
    plt.xlabel("Value")
    plt.ylabel("Frequency")
    fig.show()
    fig.close()
    return