Example #1
0
def segment_draw(segment_org_path, labeled_img_path, label_path, show=True):
    label = pd.read_csv(label_path)

    if len(label) == 0:
        print("No component needs to be labeled \n")
        return

    for s in range(label.iloc[-1].segment_no + 1):
        seg_input_path = os.path.join(segment_org_path, str(s) + '.png')
        seg_output_path = os.path.join(labeled_img_path, str(s) + '.png')
        seg_img = cv2.imread(seg_input_path)
        seg_label = label[label['segment_no'] == s]
        draw.label(seg_label, seg_img, seg_output_path, show)
    print('Labeled img saved in ' + labeled_img_path)
Example #2
0
    img_segment_path = os.path.join(segment_root, str(index))
    label_path = os.path.join(label_root, str(index) + '.csv')

    # catch label and screenshot img and segment them into smaller size
    img, label = None, None
    catch_success = False
    if is_catch_element and '.com' in links.iloc[index]:
        # set the format of libel
        libel_format = pd.read_csv(os.path.join(data_position, 'format.csv'), index_col=0)
        url = 'http://' + links.iloc[index] if 'http://' not in links.iloc[index] else links.iloc[index]
        try:
            img, label = catch.catch(url, label_path, img_org_path, libel_format, driver_path)
        except FunctionTimedOut:
            print('Catch Time Out')
            continue

    # segment the lengthy images
    if is_segment and img is not None:
        seg.segment_img(img, 600, img_segment_path, 0)

    # read and draw label on segment img
    if is_draw_label and img is not None and label is not None:
        draw.label(label, img, img_drawn_path)

    end_time = time.clock()
    print("*** %d Time taken:%ds ***\n" % (index, int(end_time - start_time)))

    if index > end_pos:
        break

if is_read_existed_links:
    # read links
    csv = pd.read_csv(os.path.join(data_position, 'preset_500_2.csv'))
    links = csv.link

print("*** Links Fetched ***\n")

start_pos = 1
for index in range(start_pos, len(links)):
    start_time = time.clock()
    # set path
    org_img_path = os.path.join(img_root, str(index) + '.png')
    drawn_img_path = os.path.join(drawn_root, str(index) + '.png')
    label_path = os.path.join(label_root, str(index) + '.csv')

    # catch label and screenshot img and segment them into smaller size
    catch_success = False
    if is_catch_element:
        # set the format of libel
        libel_format = pd.read_csv(os.path.join(data_position, 'format.csv'), index_col=0)
        url = 'http://' + links.iloc[index]
        img, label = catch.catch(url, label_path, org_img_path, libel_format, driver_path)

    # read and draw label on segment img
    if is_draw_label and img is not None and label is not None:
        draw.label(label, img, drawn_img_path)

    end_time = time.clock()
    print("*** Time taken:%ds ***\n" % int(end_time - start_time))