生成具有 ORB 可以检测到的特征的图像
Generate an image with features ORB can detect
出于单元测试的目的,我正在尝试创建一个具有 ORB 可以检测到的特征的图像;这比存储真实世界的图像更可取。我使用的是带有很多角的简单几何形状,但 ORB 没有找到任何东西 -- 为什么不呢?
这是我的图片:
我用这段代码生成的:
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)
问题是图像的数据类型,需要是 np.uint8
。
出于单元测试的目的,我正在尝试创建一个具有 ORB 可以检测到的特征的图像;这比存储真实世界的图像更可取。我使用的是带有很多角的简单几何形状,但 ORB 没有找到任何东西 -- 为什么不呢?
这是我的图片:
我用这段代码生成的:
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)
问题是图像的数据类型,需要是 np.uint8
。