【问题标题】:counting the numbers of objects using video steam使用视频流计算对象的数量
【发布时间】:2019-05-05 02:34:04
【问题描述】:

我目前正在开发一款游戏,该游戏涉及使用 OpenCV 库,使用 Python 作为编程语言使用视频流。游戏由十二个 QR 标记(对象)组成。如何使用 OpenCV(cv2 库)计算视频流上的对象(基准标签或 QR 码)的数量。以下函数调用一个库函数,该函数读取 QR 码并使用使用或增强现实为每个标记创建一个框架:

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)

我的代码不断生成对象,即不断复制和计数标记。我虽然使用历史来跟踪对象以限制重复。有什么办法可以限制重复吗?

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    解决方案是创建一个历史记录来维护并持续跟踪对象的数量,如下所示:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 2023-02-14
      • 2012-11-27
      • 1970-01-01
      • 2021-11-07
      • 2015-11-22
      相关资源
      最近更新 更多