[英]Opencv: BoW computing SURF descriptors
I'm trying to do bag of words on a set of images, extracting SURF descriptors. 我正在尝试在一组图像上提取单词,以提取SURF描述符。 However, I obtain the following error on the very last line of the code pasted below:
但是,我在下面粘贴的代码的最后一行上获得以下错误:
type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) 类型== src2.type()&& src1.cols == src2.cols &&(类型== CV_32F ||类型== CV_8U)
If I use "SIFT" instead, then everything works. 如果我改用“ SIFT”,则一切正常。 But when I use "SURF", BoW cannot compute the SURF descriptors.
但是当我使用“ SURF”时,BoW无法计算SURF描述符。
Is this the correct way to instantiate SURF? 这是实例化SURF的正确方法吗? Am I allowed to use the cv2.NORM_L2 distance function?
我可以使用cv2.NORM_L2距离函数吗?
imgs2Keypoints = {}
kmeansTrainer = cv2.BOWKMeansTrainer(10);
for pathToImage in images:
sift = cv2.SURF(400)
img = cv2.imread(pathToImage)
kp, des = sift.detectAndCompute(img, None)
des = np.float32(des)
kmeansTrainer.add(des)
imgs2Keypoints[pathToImage] = kp
vocabulary = kmeansTrainer.cluster()
bow_ext.setVocabulary(vocabulary)
surf2 = cv2.DescriptorExtractor_create("SURF")
bow_ext = cv2.BOWImgDescriptorExtractor(surf2, cv2.BFMatcher(cv2.NORM_L2))
for pathToImage in images:
img = cv2.imread(pathToImage)
histogram = bow_ext.compute(img, imgs2Keypoints[pathToImage])[0]
Edit: 编辑:
sift = cv2.SURF(400)
creates extended SURF descriptors (128 dimensional), whereas 创建扩展的SURF描述符(128维),而
surf2 = cv2.DescriptorExtractor_create("SURF")
creates standard SURF descriptors (64 dimensional). 创建标准的SURF描述符(64维)。
A possible solution is to disable extended descriptors for the sift object 一种可能的解决方案是禁用sift对象的扩展描述符
sift.extended = False
Edit 2: 编辑2:
For use with extended descriptors: 与扩展描述符一起使用:
surf2.setBool("extended", True)
As for L2 norm: Yes, L2 distance is fine. 至于L2规范:是的,L2距离很好。 As stated in OpenCV docs :
如OpenCV docs所述 :
L1 and L2 norms are preferable choices for SIFT and SURF descriptors
L1和L2规范是SIFT和SURF描述符的首选
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.