我试图对图像上的点描述符进行操作,在这样做的同时,获取我的关键点的2D坐标的numpy表示,对其应用一些线性转换,并将其转换回cv2.KeyPoint对象的列表中是很有用的。
我似乎没有这样做,我的问题似乎归结为代码中的一个事实。
import cv2
import imutils
img = imutils.url_to_image('https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png')
detector = cv2.AKAZE_create()
gray_image = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
kpts, desc = detector.detectAndCompute(gray_image, None)
coords = cv2.KeyPoint_convert(kpts)
# here I would to stuff with coords
# and then finally
transformed_kpts = cv2.KeyPoint_convert(coords)最后一行无法执行。
把事情进一步简化,做一些简单的事情,比如
cv2.KeyPoint_convert(cv2.KeyPoint_convert(kpts))撞车
OpenCV(4.1.2) /io/opencv/模块/core/src/Copy.cpp:254:错误:(-215:断言失败) == CV_MAT_CN(dtype)函数'copyTo‘中的通道()
这是一个错误,还是我做了一些根本错误的事情?
从文档看,在一个键点列表上两次应用该函数应该运行良好,并将原始列表还给我。
我的cv2.__version__是4.1.2。
发布于 2021-02-07 09:34:20
cv2.KeyPoint_convert(kpts) -> pts2f的输出是一个(n,2) ndarray
cv2.KeyPoint_convert(pts2f) -> kpts的输入应该是(n,1,2) ndarray
因此,要运行代码段,需要重新构造第一个输出,如下所示
kpts, desc = detector.detectAndCompute(gray_image, None)
coords = cv2.KeyPoint_convert(kpts)
transformed_kpts = cv2.KeyPoint_convert(coords.reshape(len(kpts), 1, 2))您可以验证kpts和transformed_kpts是否与
all([transformed_kpts[i].pt == kpts[i].pt for i in range(len(kpts))])https://stackoverflow.com/questions/60060615
复制相似问题