=======
print("height:", height)
print("widht:", width)
cv2.imshow("before", image)
cv2.waitKey(0)
>>>>>>> 536f2b4cf039aaa66c898f02c27d7212ec378360
if height > width:
    r = 64 / height
    small = cv2.resize(image, (int(width * r)  , 64))
else:
    r = 64 / width
    small = cv2.resize(image, (64, int(height * r)))
if image is None: 
    print("image is null")
cv2.imshow("after", small)
cv2.waitKey(0)
#image = skimage.io.imread(os.path.join(TEST_PIC_DIR, "gray.jpg"))
#memoryUse = py.get_memory_info()[0]/2.**30
#print("Memory use:", memoryUse)

# Run detection
start = datetime.now()
result = model.detect([small], verbose=1)
print("Time taken for detection: {}".format(datetime.now() - start))

r = result[0]
visualize.display_instances(small, r['rois'], r['masks'], r['class_ids'], 
                            class_names, r['scores'])


Exemple #2
0
# Test on a random image
image_id = random.choice(dataset_val.image_ids)
original_image, image_meta, gt_class_id, gt_bbox, gt_mask =\
    modellib.load_image_gt(dataset_val, config,
                           image_id, use_mini_mask=False)

log("original_image", original_image)
log("image_meta", image_meta)
log("gt_class_id", gt_class_id)
log("gt_bbox", gt_bbox)
log("gt_mask", gt_mask)

visualize.display_instances(original_image,
                            gt_bbox,
                            gt_mask,
                            gt_class_id,
                            dataset_train.class_names,
                            figsize=(8, 8))

results = model.detect([original_image], verbose=1)

r = results[0]
visualize.display_instances(original_image,
                            r['rois'],
                            r['masks'],
                            r['class_ids'],
                            dataset_val.class_names,
                            r['scores'],
                            ax=get_ax())

# Compute VOC-Style mAP @ IoU=0.5
Exemple #3
0
def detect_and_color_splash(model, image_path=None, video_path=None):
    assert image_path or video_path

    class_names = ['BG', 'Pothole']

    _uid = str(uuid.uuid4())[:8]
    # Image or video?
    if image_path:
        # Run model detection and generate the color splash effect
        print("Running on {}".format(args.image))
        # Read image
        image = skimage.io.imread(args.image)
        # Detect objects
        r = model.detect([image], verbose=1)[0]
        # Mask and Box image, return as byte stream
        file_path = visualize.display_instances(image,
                                                r['rois'],
                                                r['masks'],
                                                r['class_ids'],
                                                class_names,
                                                r['scores'],
                                                colors=generate_color(
                                                    r['class_ids']),
                                                uid=_uid)
        # Save output
        shutil.copy2(file_path, ROOT_DIR)
        temp_folder_cleanup(_uid)
        # file_name = "splash_{:%Y%m%dT%H%M%S}.jpg".format(datetime.datetime.now())
        # plt.imsave(file_name, plt.imread(img_buff))
    elif video_path:
        import cv2
        # Video capture
        vcapture = cv2.VideoCapture(video_path)
        width = int(vcapture.get(cv2.CAP_PROP_FRAME_WIDTH))
        height = int(vcapture.get(cv2.CAP_PROP_FRAME_HEIGHT))
        fps = vcapture.get(cv2.CAP_PROP_FPS)

        # Define codec and create video writer
        uid = uuid.uuid4()
        file_path = "{}_{:%Y%m%dT%H%M%S}.avi".format(_uid,
                                                     datetime.datetime.now())
        vwriter = cv2.VideoWriter(file_path, cv2.VideoWriter_fourcc(*'MJPG'),
                                  fps, (width, height))
        count = 0
        success = True
        while success:
            print("frame: ", count)
            # Read next image
            success, image = vcapture.read()
            if success:
                # OpenCV returns images as BGR, convert to RGB
                image = image[..., ::-1]
                # Detect objects
                r = model.detect([image], verbose=0)[0]
                # Color splash
                splash = visualize.display_instances(image,
                                                     r['rois'],
                                                     r['masks'],
                                                     r['class_ids'],
                                                     class_names,
                                                     r['scores'],
                                                     colors=generate_color(
                                                         r['class_ids']),
                                                     is_video=True,
                                                     uid=_uid)
                splash = cv2.imread(splash)
                splash = cv2.resize(splash, (width, height))
                vwriter.write(splash)
                count += 1
        vwriter.release()
        temp_folder_cleanup(_uid)
    print("Saved to ", file_path)