我有一段代码用于匹配影片剪辑和参考图像之间的特征。它通常运行良好,但有时会在剪辑中间抛出错误。由于它总是在相同的剪辑中,并且在同一时间,我猜它尝试分析的帧有问题。
我的代码:
cap = cv2.VideoCapture(clip_file)
img1 = cv2.imread(ref_image,0)
while(cap.isOpened()):
# read the frame and convert to gray-scale
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Initiate ORB detector
orb = cv2.ORB_create()
# find the keypoints and descriptors with ORB
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(gray,None)
# FLANN parameters
FLANN_INDEX_LSH = 6
index_params= dict(algorithm = FLANN_INDEX_LSH,
table_number = 6, # 12
key_size = 12, # 20
multi_probe_level = 1) #2
search_params = dict(checks=50) # or pass empty dictionary …Run Code Online (Sandbox Code Playgroud)