Beispiel #1
0
    if not os.path.exists(img_path):
        print('Image {} cannot be found at the path.'.format(img_path))
        continue

    annos_i = df_anno.loc[df_anno['image_id'] ==
                          img_name, :]  # all annotations on this image

    # if len(annos_i) < 20:
    #     continue

    # if len(images_html) > 400:  # cap on maximum to save
    #     break

    try:
        image = vis_utils.open_image(img_path).resize(viz_size)
    except Exception as e:
        print('Image {} failed to open. Error: {}'.format(img_path, e))
        continue

    # only save images with a particular class
    # classes = list(annos_i.loc[:, 'category_id'])
    # classes = [str(i) for i in classes]
    # if '3' not in classes:  # only save images with the 'group' class
    #     continue

    if len(annos_i) > 0:
        bboxes = list(annos_i.loc[:, 'bbox'])
        classes = list(annos_i.loc[:, 'category_id'])
        vis_utils.render_iMerit_boxes(bboxes, classes, image,
                                      label_map)  # image changed in place
Beispiel #2
0
    boxes_and_scores = json.loads(row[2])

    if images_local:
        image_obj = os.path.join(args.images_dir, image_id)
        if not os.path.exists(image_obj):
            print('Image {} is not found at images_dir; skipped.'.format(
                image_id))
            continue
    else:
        if not blob_service.exists(container_name, blob_name=image_id):
            print('Image {} is not found in the blob container {}; skipped.'.
                  format(image_id, container_name))
            continue

        image_obj = io.BytesIO()
        _ = blob_service.get_blob_to_stream(container_name, image_id,
                                            image_obj)

    image = vis_utils.open_image(image_obj).resize(
        viz_size)  # resize is to display them more quickly
    vis_utils.render_detection_bounding_boxes(
        boxes_and_scores, image, confidence_threshold=args.confidence)

    annotated_img_name = image_id.replace('/', '~')
    annotated_img_path = os.path.join(args.out_dir, annotated_img_name)
    image.save(annotated_img_path)
    num_saved += 1

print('Rendered detection results on {} images, saved to {}.'.format(
    num_saved, args.out_dir))
    max_conf = float(row[1])
    boxes_and_scores = json.loads(row[2])

    if images_local:
        image_obj = os.path.join(args.images_dir, image_id)
        if not os.path.exists(image_obj):
            print('Image {} is not found at local images_dir; skipped.'.format(image_id))
            continue
    else:
        print('image_id:', image_id)
        print('container_name:', container_name)
        if not blob_service.exists(container_name, blob_name=image_id):
            print('Image {} is not found in the blob container {}; skipped.'.format(image_id, container_name))
            continue

        image_obj = io.BytesIO()
        _ = blob_service.get_blob_to_stream(container_name, image_id, image_obj)

    # resize is for displaying them more quickly
    image = vis_utils.resize_image(vis_utils.open_image(image_obj), args.output_image_width)

    vis_utils.render_detection_bounding_boxes(boxes_and_scores, image, label_map=DETECTOR_LABEL_MAP,
                                              confidence_threshold=args.confidence)

    annotated_img_name = image_id.replace('/', '~').replace('\\', '~')
    annotated_img_path = os.path.join(args.out_dir, annotated_img_name)
    image.save(annotated_img_path)
    num_saved += 1

print('Rendered detection results on {} images, saved to {}.'.format(num_saved, args.out_dir))