Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 726:43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 07 Aug 2015 13:07:53 -0400 |
parents | e14e2101a5a9 |
children | c6d4ea05a2d0 |
comparison
equal
deleted
inserted
replaced
725:35bc5e30a53f | 726:43ae3a1af290 |
---|---|
1064 obj.velocities = self.velocities.getTrajectoryInInterval(trajectoryInterval) | 1064 obj.velocities = self.velocities.getTrajectoryInInterval(trajectoryInterval) |
1065 return obj | 1065 return obj |
1066 else: | 1066 else: |
1067 print 'The object does not exist at '+str(inter) | 1067 print 'The object does not exist at '+str(inter) |
1068 return None | 1068 return None |
1069 | |
1070 def getObjectsInMask(self, mask, homography = None, minLength = 1): | |
1071 '''Returns new objects made of the positions in the mask | |
1072 mask is in the destination of the homography space''' | |
1073 if homography is not None: | |
1074 self.projectedPositions = self.positions.project(homography) | |
1075 else: | |
1076 self.projectedPositions = self.positions | |
1077 def inMask(positions, i, mask): | |
1078 p = positions[i] | |
1079 return mask[p.y, p.x] != 0. | |
1080 | |
1081 #subTimeIntervals self.getFirstInstant()+i | |
1082 filteredIndices = [inMask(self.projectedPositions, i, mask) for i in range(int(self.length()))] | |
1083 # 'connected components' in subTimeIntervals | |
1084 l = 0 | |
1085 intervalLabels = [] | |
1086 prev = True | |
1087 for i in filteredIndices: | |
1088 if i: | |
1089 if not prev: # new interval | |
1090 l += 1 | |
1091 intervalLabels.append(l) | |
1092 else: | |
1093 intervalLabels.append(-1) | |
1094 prev = i | |
1095 intervalLabels = array(intervalLabels) | |
1096 subObjects = [] | |
1097 for l in set(intervalLabels): | |
1098 if l >= 0: | |
1099 if sum(intervalLabels == l) >= minLength: | |
1100 times = [self.getFirstInstant()+i for i in range(len(intervalLabels)) if intervalLabels[i] == l] | |
1101 subTimeInterval = TimeInterval(min(times), max(times)) | |
1102 subObjects.append(self.getObjectInTimeInterval(subTimeInterval)) | |
1103 | |
1104 return subObjects | |
1069 | 1105 |
1070 def getPositions(self): | 1106 def getPositions(self): |
1071 return self.positions | 1107 return self.positions |
1072 | 1108 |
1073 def getVelocities(self): | 1109 def getVelocities(self): |