Beispiel #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)
Beispiel #2
0
    # 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