import cv2
import matplotlib.pyplot as plt
template = cv2.imread('./light_t.jpg')
template = cv2.resize(template, (200, 200))
print(template.shape)
lineModDetector = cv2.linemod.getDefaultLINE()
print(len(lineModDetector.getModalities()))
mask = cv2.bitwise_not(template)[:,:,1]
ret, boundingBox = lineModDetector.addTemplate([template], "circle", mask)
print(ret)
print(boundingBox)
target = cv2.imread('../image/materias/light.jpg',)
target = cv2.resize( target, (200, 200))
results = lineModDetector.match(target, threshold=80)
运行此代码时出现以下错误:
error: (-215:Assertion failed) sources.size() == modalities.size() in function 'cv::linemod::Detector::match'
我尝试使用 python 实现
linemod
根据文档:https://docs.opencv.org/4.4.0/d7/d07/classcv_1_1linemod_1_1Detector.html 来源 源图像,每种模式一个。
你应该像这样使用它:
target = cv2.imread('../image/materias/light.jpg',)
目标 = cv2.resize( 目标, (200, 200))
目标=(目标,)
结果 = lineModDetector.match(目标,阈值=80)