多目标跟踪OpenCV Python,轮廓保持交换

时间:2017-04-23 21:23:22

标签: python opencv

因此,我正在尝试编写一个程序,该程序将跟踪相同大小和颜色的3个轮​​廓,同时保持单独识别,但轮廓不断从一个跳到另一个。例如,我在每个轮廓上都有红色,绿色和蓝色圆圈,但轮廓#1会在红色和绿色之间翻转,反之亦然。我按大小排序轮廓,但即使我没有,我仍然遇到同样的问题。我正在运行OpenCV 3.2和python 3.5。

if len(cnts) > 2:                                                       
    cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:10]     
    for i in range(0,3):                                                
        ((x[i], y[i]), radius[i]) = cv2.minEnclosingCircle(cnts[i])     
        for i in range(0,3):                                            
            M = cv2.moments(cnts[i])                                    
            center[i] = (int(M["m10"]/ M["m00"]), int(M["m01"] / M["m00"]))
        if flag is False:                                               
            for i in range(0,3):                                        
                cup[i]=center[i]                                        
            flag = True                                                 
        else:                                                           
            if radius[i]>10:                                                            
                for i in range(0,3):                                        
                cup[i] = center[closestPoint(cup[i], center)]           
                #for i in range (0,3):                                  
                cv2.circle(frame, (int(cup[i][0]), int(cup[i][1])),     
                       int(radius[i]), color[i],2)                  
                cv2.circle(frame,(cup[i][0],cup[i][1]),5,(0,0,255),-1)  

0 个答案:

没有答案