Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/moving.py @ 1132:09ef0dc994a0
modification for performance computation
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 26 Feb 2020 22:32:39 -0500 |
parents | 2682b4696cdf |
children | c4d9c270f999 |
comparison
equal
deleted
inserted
replaced
1131:3972d85e3b6c | 1132:09ef0dc994a0 |
---|---|
1755 return Point.boundingRectangle(positions, self.getVelocityAtInstant(instant)) | 1755 return Point.boundingRectangle(positions, self.getVelocityAtInstant(instant)) |
1756 else: | 1756 else: |
1757 print('Object {} has no features'.format(self.getNum())) | 1757 print('Object {} has no features'.format(self.getNum())) |
1758 return None | 1758 return None |
1759 | 1759 |
1760 def motDistanceAtInstant(self, obj, instant): | |
1761 '''Returns distance for computing CLEAR MOT metrics | |
1762 (returns an actual value, otherwise munkres does not terminate)''' | |
1763 return Point.distanceNorm2(self.getPositionAtInstant(instant), obj.getPositionAtInstant(instant)) | |
1764 | |
1760 ### | 1765 ### |
1761 # User Type Classification | 1766 # User Type Classification |
1762 ### | 1767 ### |
1763 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, nInstantsIgnoredAtEnds = 0): | 1768 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, nInstantsIgnoredAtEnds = 0): |
1764 '''Classifies slow and fast road users | 1769 '''Classifies slow and fast road users |
1937 | 1942 |
1938 Its center is the center of the box (generalize to other shapes?) | 1943 Its center is the center of the box (generalize to other shapes?) |
1939 (computed after projecting if homography available) | 1944 (computed after projecting if homography available) |
1940 ''' | 1945 ''' |
1941 | 1946 |
1942 def __init__(self, num = None, timeInterval = None, topLeftPositions = None, bottomRightPositions = None, userType = userType2Num['unknown']): | 1947 def __init__(self, topLeftPositions, bottomRightPositions, num = None, timeInterval = None, userType = userType2Num['unknown']): |
1943 super(BBMovingObject, self).__init__(num, timeInterval, userType = userType) | 1948 super(BBMovingObject, self).__init__(num, timeInterval, userType = userType) |
1944 self.topLeftPositions = topLeftPositions.getPositions() | 1949 self.topLeftPositions = topLeftPositions.getPositions() |
1945 self.bottomRightPositions = bottomRightPositions.getPositions() | 1950 self.bottomRightPositions = bottomRightPositions.getPositions() |
1946 | 1951 |
1947 def computeCentroidTrajectory(self, homography = None): | 1952 def computeCentroidTrajectory(self, homography = None): |
1948 self.positions = self.topLeftPositions.add(self.bottomRightPositions).__mul__(0.5) | 1953 self.positions = self.topLeftPositions.add(self.bottomRightPositions).__mul__(0.5) |
1949 if homography is not None: | 1954 if homography is not None: |
1950 self.positions = self.positions.homographyProject(homography) | 1955 self.positions = self.positions.homographyProject(homography) |
1951 | |
1952 def matches(self, obj, instant, matchingDistance): | |
1953 '''Indicates if the annotation matches obj (MovingObject) | |
1954 with threshold matchingDistance | |
1955 Returns distance if below matchingDistance, matchingDistance+1 otherwise | |
1956 (returns an actual value, otherwise munkres does not terminate)''' | |
1957 d = Point.distanceNorm2(self.getPositionAtInstant(instant), obj.getPositionAtInstant(instant)) | |
1958 if d < matchingDistance: | |
1959 return d | |
1960 else: | |
1961 return matchingDistance + 1 | |
1962 | 1956 |
1963 def matchObjects(obj1, obj2, instant, matchingDistance): | 1957 def matchObjects(obj1, obj2, instant, matchingDistance): |
1964 '''Indicates if obj matches obj2 with threshold matchingDistance | 1958 '''Indicates if obj matches obj2 with threshold matchingDistance |
1965 Returns distance if below matchingDistance, matchingDistance+1 otherwise | 1959 Returns distance if below matchingDistance, matchingDistance+1 otherwise |
1966 (returns an actual value, otherwise munkres does not terminate)''' | 1960 (returns an actual value, otherwise munkres does not terminate)''' |
2018 previousMatches = matches.copy() | 2012 previousMatches = matches.copy() |
2019 # go through currently matched GT-TO and check if they are still matched withing matchingDistance | 2013 # go through currently matched GT-TO and check if they are still matched withing matchingDistance |
2020 toDelete = [] | 2014 toDelete = [] |
2021 for a in matches: | 2015 for a in matches: |
2022 if a.existsAtInstant(t) and matches[a].existsAtInstant(t): | 2016 if a.existsAtInstant(t) and matches[a].existsAtInstant(t): |
2023 d = a.matches(matches[a], t, matchingDistance) | 2017 d = a.motDistanceAtInstant(matches[a], t) |
2024 if d < matchingDistance: | 2018 if d < matchingDistance: |
2025 dist += d | 2019 dist += d |
2026 else: | 2020 else: |
2027 toDelete.append(a) | 2021 toDelete.append(a) |
2028 else: | 2022 else: |