在 OpenCV Python 中使用 cv2.line_descriptor.drawLineMatches() 绘制匹配时出现未知 C++ 异常

问题描述 投票:0回答:0

我正在尝试使用 Python 中 OpenCV 的二进制描述符模块 来匹配从两个图像中提取的线描述符。但是,当使用

cv2.line_descriptor.drawLineMatches()
函数绘制火柴时,出现以下错误

img3 = cv2.line_descriptor.drawLineMatches(img,keylines1,field,keylines2,matches[:10],None)

cv2.error:来自 OpenCV 代码的未知 C++ 异常

我做错了什么?任何建议都会有所帮助。谢谢。

import cv2
import numpy as np 

#Read gray image
img = cv2.imread("8.jpg",0)
field = cv2.imread('field1.png',0)

lsd = cv2.line_descriptor.LSDDetector.createLSDDetector()


#Detect lines in the image
keylines1 = lsd.detect(img, scale=2, numOctaves=2)
keylines2 = lsd.detect(field, scale=2, numOctaves=2)


# # # compute descriptors for lines
bd = cv2.line_descriptor.BinaryDescriptor.createBinaryDescriptor()
k1,descr1 = bd.compute(img, keylines1)
k2,descr2 = bd.compute(field, keylines2)

bdm =  cv2.line_descriptor.BinaryDescriptorMatcher()

matches = bdm.match(descr1, descr2)

matches = sorted(matches, key = lambda x:x.distance)
#img3 = cv2.drawMatches(img,k1,field,k2,matches[10],None,1)

img3 = cv2.line_descriptor.drawLineMatches(img,keylines1,field,keylines2,matches[:10],None)

#Show image
cv2.imshow("LSD",img3 )
cv2.waitKey(0)
python opencv image-processing computer-vision feature-extraction
© www.soinside.com 2019 - 2024. All rights reserved.