Home > Blockchain >  Generate an image with features ORB can detect
Generate an image with features ORB can detect

Time:02-12

For the purposes of a unit test, I'm trying to create an image with features ORB can detect; this is preferable to storing a real-world image. I'm using simple geometric shapes with lots of corners, but ORB isn't finding anything -- why not?

This is my image:

My image

Which I generated with this code:

import cv2
import numpy as np

img_dims = (480, 640)
center = (np.array(img_dims) / 2).astype(int)
radius = 10

features = np.zeros(img_dims (3,), dtype=np.float32)

features = cv2.rectangle(features,
                         (center - radius)[::-1],
                         (center   radius)[::-1],
                         (0, 255, 0),
                         -1)
features = cv2.circle(features,
                      center[::-1],
                      radius,
                      (255, 0, 0),
                      2)
features = cv2.rectangle(features,
                         (center - int(radius / 2))[::-1],
                         (center   int(radius / 2))[::-1],
                         (0, 0, 255),
                         -1)

# cv2.imshow("", features)
# cv2.waitKey(-1)

detector = cv2.ORB_create(nfeatures=100000)
keypoints, descriptors = detector.detectAndCompute(features, None)
assert len(keypoints)

CodePudding user response:

The problem was the datatype of the image, which needed to be np.uint8.

  • Related