Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 636:3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 24 Mar 2015 18:11:28 +0100 |
parents | 6ae68383071e |
children | bfaa6b95dae2 |
line wrap: on
line diff
--- a/python/moving.py Tue Mar 24 14:17:12 2015 +0100 +++ b/python/moving.py Tue Mar 24 18:11:28 2015 +0100 @@ -405,7 +405,7 @@ for spline_p in range(len(splines[spline])-1): #Get closest point on spline closestPoint = ppldb2p(p.x,p.y,splines[spline][spline_p][0],splines[spline][spline_p][1],splines[spline][spline_p+1][0],splines[spline][spline_p+1][1]) - if closestPoint == None: + if closestPoint is None: print('Error: Spline {0}, segment {1} has identical bounds and therefore is not a vector. Projection cannot continue.'.format(spline, spline_p)) return None # check if the @@ -570,7 +570,7 @@ return None else: inter = intersection(p1, p2, p3, p4) - if (inter != None + if (inter is not None and utils.inBetween(p1.x, p2.x, inter.x) and utils.inBetween(p3.x, p4.x, inter.x) and utils.inBetween(p1.y, p2.y, inter.y) @@ -582,7 +582,7 @@ def segmentLineIntersection(p1, p2, p3, p4): '''Indicates if the line going through p1 and p2 intersects inside p3, p4''' inter = intersection(p1, p2, p3, p4) - if inter != None and utils.inBetween(p3.x, p4.x, inter.x) and utils.inBetween(p3.y, p4.y, inter.y): + if inter is not None and utils.inBetween(p3.x, p4.x, inter.x) and utils.inBetween(p3.y, p4.y, inter.y): return inter else: return None @@ -594,7 +594,7 @@ The class is iterable''' def __init__(self, positions=None): - if positions != None: + if positions is not None: self.positions = positions else: self.positions = [[],[]] @@ -681,7 +681,7 @@ @staticmethod def _plot(positions, options = '', withOrigin = False, lastCoordinate = None, timeStep = 1, **kwargs): from matplotlib.pylab import plot - if lastCoordinate == None: + if lastCoordinate is None: plot(positions[0][::timeStep], positions[1][::timeStep], options, **kwargs) elif 0 <= lastCoordinate <= len(positions[0]): plot(positions[0][:lastCoordinate:timeStep], positions[1][:lastCoordinate:timeStep], options, **kwargs) @@ -818,7 +818,7 @@ q1=self.__getitem__(i) q2=self.__getitem__(i+1) p = utils.segmentIntersection(q1, q2, p1, p2) - if p != None: + if p is not None: if q1.x != q2.x: ratio = (p.x-q1.x)/(q2.x-q1.x) elif q1.y != q2.y: @@ -840,7 +840,7 @@ q1=self.__getitem__(i) q2=self.__getitem__(i+1) p = utils.segmentLineIntersection(p1, p2, q1, q2) - if p != None: + if p is not None: if q1.x != q2.x: ratio = (p.x-q1.x)/(q2.x-q1.x) elif q1.y != q2.y: @@ -897,13 +897,13 @@ lateral coordiante is stored as second coordinate''' def __init__(self, S = None, Y = None, lanes = None): - if S == None or Y == None or len(S) != len(Y): + if S is None or Y is None or len(S) != len(Y): self.positions = [[],[]] - if S != None and Y != None and len(S) != len(Y): + if S is not None and Y is not None and len(S) != len(Y): print("S and Y coordinates of different lengths\nInitializing to empty lists") else: self.positions = [S,Y] - if lanes == None or len(lanes) != self.length(): + if lanes is None or len(lanes) != self.length(): self.lanes = [] else: self.lanes = lanes @@ -948,13 +948,13 @@ def getIntersections(self, S1, lane = None): '''Returns a list of the indices at which the trajectory goes past the curvilinear coordinate S1 - (in provided lane if lane != None) + (in provided lane if lane is not None) the list is empty if there is no crossing''' indices = [] for i in xrange(self.length()-1): q1=self.__getitem__(i) q2=self.__getitem__(i+1) - if q1[0] <= S1 < q2[0] and (lane == None or (self.lanes[i] == lane and self.lanes[i+1] == lane)): + if q1[0] <= S1 < q2[0] and (lane is None or (self.lanes[i] == lane and self.lanes[i+1] == lane)): indices.append(i+(S1-q1[0])/(q2[0]-q1[0])) return indices @@ -1000,7 +1000,7 @@ print('The two objects\' time intervals do not overlap: obj1 {} and obj2 {}'.format(obj1.getTimeInterval(), obj2.getTimeInterval())) return None else: - if num == None: + if num is None: newNum = obj1.getNum() else: newNum = num @@ -1135,7 +1135,7 @@ @staticmethod def distances(obj1, obj2, instant1, _instant2 = None): from scipy.spatial.distance import cdist - if _instant2 == None: + if _instant2 is None: instant2 = instant1 else: instant2 = _instant2 @@ -1229,7 +1229,7 @@ result = getSYfromXY(self.getPositionAt(i), alignments) # Error handling - if(result == None): + if(result is None): print('Warning: trajectory {} at point {} {} has alignment errors (spline snapping)\nCurvilinear trajectory could not be computed'.format(self.getNum(), i, self.getPositionAt(i))) else: [align, alignPoint, snappedPoint, subsegmentDistance, S, Y] = result @@ -1246,7 +1246,7 @@ result = getSYfromXY(self.getPositionAt(i),[alignments[smoothed_lanes[i]]]) # Error handling - if(result == None): + if(result is None): ## This can be triggered by tracking errors when the trajectory jumps around passed another alignment. print(' Warning: trajectory {} at point {} {} has alignment errors during trajectory smoothing and will not be corrected.'.format(self.getNum(), i, self.getPositionAt(i))) else: @@ -1333,7 +1333,7 @@ croppedImg, yCropMin, yCropMax, xCropMin, xCropMax = imageBox(img, self, instant, homography, width, height, px, py, pixelThreshold) if len(croppedImg) > 0: # != [] hog = array([cvutils.HOG(croppedImg)], dtype = np.float32) - if self.aggregatedSpeed < pedBikeSpeedTreshold or bikeCarSVM == None: + if self.aggregatedSpeed < pedBikeSpeedTreshold or bikeCarSVM is None: self.userTypes[instant] = int(pedBikeCarSVM.predict(hog)) elif self.aggregatedSpeed < bikeCarSpeedTreshold: self.userTypes[instant] = int(bikeCarSVM.predict(hog)) @@ -1358,7 +1358,7 @@ if t not in self.userTypes: self.classifyUserTypeHoGSVMAtInstant(images[t], pedBikeCarSVM, t, homography, width, height, bikeCarSVM, pedBikeSpeedTreshold, bikeCarSpeedThreshold, px, py, pixelThreshold) # compute P(Speed|Class) - if speedProbabilities == None: # equiprobable information from speed + if speedProbabilities is None: # equiprobable information from speed userTypeProbabilities = {userType2Num['car']: 1., userType2Num['pedestrian']: 1., userType2Num['bicycle']: 1.} else: userTypeProbabilities = {userType2Num[userTypename]: speedProbabilities[userTypename](self.aggregatedSpeed) for userTypename in speedProbabilities} @@ -1380,7 +1380,7 @@ skip frames at beginning/end?''' print('not implemented/tested yet') if not hasattr(self, projectedPositions): - if homography != None: + if homography is not None: self.projectedPositions = obj.positions.project(homography) else: self.projectedPositions = obj.positions @@ -1424,7 +1424,7 @@ def computeCentroidTrajectory(self, homography = None): self.positions = self.topLeftPositions.add(self.bottomRightPositions).multiply(0.5) - if homography != None: + if homography is not None: self.positions = self.positions.project(homography) def matches(self, obj, instant, matchingDistance):