Python 使用视频流计算对象的数量
我目前正在开发一个游戏,涉及使用视频流使用openCV库,使用Python作为编程语言。游戏由12个QR标记(对象)组成。如何使用OpenCV(cv2库)计算视频流中对象的数量(基准标记或QR码)。以下函数调用一个库函数,该函数读取QR码,并使用use或增强现实为每个标记创建一个框架:Python 使用视频流计算对象的数量,python,opencv,Python,Opencv,我目前正在开发一个游戏,涉及使用视频流使用openCV库,使用Python作为编程语言。游戏由12个QR标记(对象)组成。如何使用OpenCV(cv2库)计算视频流中对象的数量(基准标记或QR码)。以下函数调用一个库函数,该函数读取QR码,并使用use或增强现实为每个标记创建一个框架: def readAndDetect(image): global markerDictionary markers = detect_markers(image) for marker
def readAndDetect(image):
global markerDictionary
markers = detect_markers(image)
for marker in markers:
marker.highlite_marker(image)
#Create a dictionary key == MarkerId , Values: (center)]
markerDictionary[marker.id] = marker.center
print(markerDictionary)
cv2.imshow('Test Frame', image)
我的代码不断生成对象,即不断复制和计数标记。我想使用历史记录来跟踪对象以限制重复。有什么方法可以限制复制吗?解决方案是创建一个历史记录,按照如下方式维护和跟踪对象的数量:
global StringPair
markers = detect_markers(image)
# to remove duplicate
refined_markers = dict( [ ( marker.id, marker ) for marker in markers if self.checkForExistance(marker.id) ] )
# And then Assign the values to the markers As result, markers has no duplicate
markers = [ refined_markers[idx] for idx in refined_markers ]
# create history
self.history.insert(0, markers )
#print (">>>", history)
if len(self.history) > 30:
self.history.pop()
# get all markers from history
#this will be my list for stuff
all_markers = {}
for entry in reversed(self.history):
for marker in entry:
all_markers[marker.id] = marker
#Generate and highlight the markers
for idx in all_markers:
marker = all_markers[idx]
marker.highlite_marker(image)
# Number of detected markers
self.count2 = len(all_markers)