Exemplo n.º 1
0
def item_length(image, gc_image):
    """
    TODO
    """
    def higher_lower_body_split_line(face_rect):
        box_width = face_rect[0][2]
        y_split = face_rect[0][1] + 4.5 * box_width
        return y_split

    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

    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

    def arms_face_proportions(face_rect, right_hand, left_hand):
        num_of_left_hand_pixels = cv2.countNonZero(left_hand[:, :, 0])
        num_of_right_hand_pixels = cv2.countNonZero(right_hand[:, :, 0])
        prop_left = num_of_left_hand_pixels / face_rect[3]
        prop_right = num_of_right_hand_pixels / face_rect[3]
        return prop_left, prop_right

    def legs_face_proportion(face_rect, lower_bgr_skin):
        num_of_legs_pixels = cv2.countNonZero(lower_bgr_skin[:, :, 0])
        legs_prop = num_of_legs_pixels / face_rect[3]
        return legs_prop

    YCrCb_image = cv2.cvtColor(gc_image, cv2.COLOR_BGR2YCR_CB)
    face_rect = background_removal.find_face(image)
    if len(face_rect) > 0:
        y_split = higher_lower_body_split_line(face_rect)
        prop_left, prop_right = sleeve_length()
        legs_prop = dress_length()
    else:
        print 'no faces were detected'
        return -1, -1, -1
        # TODO: add general code that deals with that case
    return legs_prop, prop_left, prop_right
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
0
def crop_and_center_face(img_arr,
                         face_cascade=None,
                         eye_cascade=None,
                         x_size=250,
                         y_size=250):
    if not face_cascade:
        face_cascade = cv2.CascadeClassifier(
            constants.classifiers_folder +
            '/haarcascade_frontalface_default.xml')
    if not eye_cascade:
        eye_cascade = cv2.CascadeClassifier(constants.classifiers_folder +
                                            '/haarcascade_eye.xml')
    if not face_cascade:
        logging.warning('cant get face cascade in cropface in gender.py')
    if not eye_cascade:
        logging.warning('cant get eye cascade in cropface in gender.py')

    faces = background_removal.find_face(img_arr, max_num_of_faces=1)
    gray = cv2.cvtColor(img_arr, constants.BGR2GRAYCONST)
    i = 0
    cropped = None
    if faces is not None:
        for (x, y, w, h) in faces:
            roi_gray = gray[y:y + h, x:x + w]
            eyes = eye_cascade.detectMultiScale(roi_gray)

            if len(eyes) == 2:
                left = eyes[0]
                right = eyes[1]
                if left[0] > right[0]:
                    temp = left
                    left = right
                    right = temp
                original_left = [left[0] + x, left[1] + y, left[2], left[3]]
                original_right = [
                    right[0] + x, right[1] + y, right[2], right[3]
                ]
                lined_up = line_up_eyes(img_arr, original_left, original_right)
                lined_up_roi = lined_up[0:y_size, 0:x_size]
                dst = copy.copy(lined_up_roi)  # rotated.copy.deepcopy()
                return dst
            if i == 0:
                cropped = img_arr[y:y + h, x:x + w]
            i += 1

        # no set of two eyes found so just return as is
        dst = copy.copy(cropped)  # rotated.copy.deepcopy()
        return dst

    else:
        return img_arr
Exemplo n.º 5
0
def find_images(description):
    print('starting to find ' + str(description))
    for i in range(0, 500):
        mdoc = dbUtils.lookfor_next_unbounded_feature_from_db_category(
            current_item=i,
            skip_if_marked_to_skip=True,
            which_to_show='showAll',
            filter_type='byWordInDescription',
            category_id=None,
            word_in_description=description,
            db=None)

        if mdoc is not None and 'doc' in mdoc:
            doc = mdoc['doc']
            # print doc

            xlarge_url = doc['image']['sizes']['XLarge']['url']
            # print('large img url:' + str(xlarge_url))
            img_arr = Utils.get_cv2_img_array(xlarge_url)
            if img_arr is None:
                return None
            small_img = background_removal.standard_resize(img_arr, 400)[0]
            show_visual_output = False
            if show_visual_output == True:
                cv2.imshow('im1', img_arr)
                k = cv2.waitKey(200)
                cv2.imshow('smallim1', small_img)
                k = cv2.waitKey(200)
            relevance = background_removal.image_is_relevant(small_img)
            if not relevance:
                print('image is not relevant:' + str(description))
                continue
            print('image is relevant:' + str(description))
            face1 = background_removal.find_face(img_arr)
            if face1 is not None and len(face1) != 0:
                print('face1:' + str(face1))
                bb1 = face1[0]
                get_pose_est_bbs(xlarge_url,
                                 description,
                                 n=i,
                                 show_visual_output=show_visual_output,
                                 bb=bb1)

            else:
                get_pose_est_bbs(xlarge_url,
                                 description,
                                 n=i,
                                 show_visual_output=show_visual_output)
Exemplo n.º 6
0
def get_bb(img_array, use_visual_output=True, fname='filename', item='dress'):
    faces = background_removal.find_face(img_array, max_num_of_faces=1)
    if faces is not None and faces is not [] and faces is not (
    ) and len(faces) == 1:

        print('faces:' + str(faces))
        face = faces[0]
    else:
        return None
    if item == 'dress':
        item_length = 12
        item_width = 4
        item_y_offset = 0
    else:
        item_length = 12
        item_width = 4
        item_y_offset = 0

    orig_h, orig_w, d = img_array.shape
    head_x0 = face[0]
    head_y0 = face[1]
    w = face[2]
    h = face[3]
    item_w = w * item_width
    item_y0 = head_y0 + h + item_y_offset
    item_h = min(h * item_length, orig_h - item_y0 - 1)
    item_x0 = max(0, head_x0 + w / 2 - item_w / 2)
    item_w = min(w * item_width, orig_w - item_x0 - 1)
    item_box = [item_x0, item_y0, item_w, item_h]
    if use_visual_output == True:
        cv2.rectangle(img_array, (item_box[0], item_box[1]),
                      (item_box[0] + item_box[2], item_box[1] + item_box[3]),
                      GREEN,
                      thickness=1)
        print('plotting img, dims:' + str(orig_w) + ' x ' + str(orig_h))
        # im = plt.imshow(img_array)
        # plt.show(block=False)

        cv2.imshow(fname, img_array)
        cv2.moveWindow('win', 100, 200)
        k = cv2.waitKey(50)
        # raw_input('enter to continue')
        cv2.destroyAllWindows()

        if k in [27, ord('Q'), ord('q')]:  # exit on ESC
            pass
    assert (Utils.bounding_box_inside_image(img_array, item_box))
    return item_box
Exemplo n.º 7
0
    for description in descriptions:
        for i in range(0, 100):
            mdoc = dbUtils.lookfor_next_unbounded_feature_from_db_category(
                item_number=i,
                skip_if_marked_to_skip=True,
                which_to_show='showAll',
                filter_type='byWordInDescription',
                category_id=None,
                word_in_description=description,
                db=None,
            )
            if 'doc' in mdoc:
                doc = mdoc['doc']
                print doc

                xlarge_url = doc['image']['sizes']['XLarge']['url']
                print('large img url:' + str(xlarge_url))
                img_arr = Utils.get_cv2_img_array(xlarge_url)
                face1 = background_removal.find_face(img_arr)
                if face1 is not None and len(face1) != 0:
                    print('face1:' + str(face1))
                    bb1 = face1
                    get_pose_est_bbs(xlarge_url, description, n=i, bb=bb1)

                else:
                    get_pose_est_bbs(xlarge_url, description, n=i)

#Vnecks round neck natanel
# tight vs nontight dresses yakir