Mercurial Hosting > traffic-intelligence
comparison scripts/classify-objects.py @ 993:e8eabef7857c
update to OpenCV3 for python
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 16 May 2018 21:06:52 -0400 |
parents | 64259b9885bf |
children | 933670761a57 |
comparison
equal
deleted
inserted
replaced
992:2cd1ce245024 | 993:e8eabef7857c |
---|---|
33 speedAggregationFunc = lambda speeds: np.percentile(speeds, args.speedAggregationQuantile) | 33 speedAggregationFunc = lambda speeds: np.percentile(speeds, args.speedAggregationQuantile) |
34 else: | 34 else: |
35 print('Unknown speed aggregation method: {}. Exiting'.format(classifierParams.speedAggregationMethod)) | 35 print('Unknown speed aggregation method: {}. Exiting'.format(classifierParams.speedAggregationMethod)) |
36 sys.exit() | 36 sys.exit() |
37 | 37 |
38 pedBikeCarSVM = ml.SVM() | 38 pedBikeCarSVM = ml.SVM_load(classifierParams.pedBikeCarSVMFilename) |
39 pedBikeCarSVM.load(classifierParams.pedBikeCarSVMFilename) | 39 bikeCarSVM = ml.SVM_load(classifierParams.bikeCarSVMFilename) |
40 bikeCarSVM = ml.SVM() | |
41 bikeCarSVM.load(classifierParams.bikeCarSVMFilename) | |
42 | 40 |
43 # log logistic for ped and bik otherwise ((pedBeta/pedAlfa)*((sMean/pedAlfa)**(pedBeta-1)))/((1+(sMean/pedAlfa)**pedBeta)**2.) | 41 # log logistic for ped and bik otherwise ((pedBeta/pedAlfa)*((sMean/pedAlfa)**(pedBeta-1)))/((1+(sMean/pedAlfa)**pedBeta)**2.) |
44 carNorm = norm(classifierParams.meanVehicleSpeed, classifierParams.stdVehicleSpeed) | 42 carNorm = norm(classifierParams.meanVehicleSpeed, classifierParams.stdVehicleSpeed) |
45 pedNorm = norm(classifierParams.meanPedestrianSpeed, classifierParams.stdPedestrianSpeed) | 43 pedNorm = norm(classifierParams.meanPedestrianSpeed, classifierParams.stdPedestrianSpeed) |
46 # numpy lognorm shape, loc, scale: shape for numpy is scale (std of the normal) and scale for numpy is exp(location) (loc=mean of the normal) | 44 # numpy lognorm shape, loc, scale: shape for numpy is scale (std of the normal) and scale for numpy is exp(location) (loc=mean of the normal) |
70 timeInterval = moving.TimeInterval.unionIntervals([obj.getTimeInterval() for obj in objects]) | 68 timeInterval = moving.TimeInterval.unionIntervals([obj.getTimeInterval() for obj in objects]) |
71 if args.startFrame0: | 69 if args.startFrame0: |
72 timeInterval.first = 0 | 70 timeInterval.first = 0 |
73 | 71 |
74 capture = cv2.VideoCapture(videoFilename) | 72 capture = cv2.VideoCapture(videoFilename) |
75 width = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)) | 73 width = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)) |
76 height = int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)) | 74 height = int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT)) |
77 | 75 |
78 #if undistort: # setup undistortion | 76 #if undistort: # setup undistortion |
79 # [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) | 77 # [map1, map2] = cvutils.computeUndistortMaps(width, height, undistortedImageMultiplication, intrinsicCameraMatrix, distortionCoefficients) |
80 # height, width = map1.shape | 78 # height, width = map1.shape |
81 # newImgSize = (int(round(width*undistortedImageMultiplication)), int(round(height*undistortedImageMultiplication))) | 79 # newImgSize = (int(round(width*undistortedImageMultiplication)), int(round(height*undistortedImageMultiplication))) |
87 currentObjects = [] | 85 currentObjects = [] |
88 if capture.isOpened(): | 86 if capture.isOpened(): |
89 ret = True | 87 ret = True |
90 frameNum = timeInterval.first | 88 frameNum = timeInterval.first |
91 if not args.startFrame0: | 89 if not args.startFrame0: |
92 capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNum) | 90 capture.set(cv2.CAP_PROP_POS_FRAMES, frameNum) |
93 lastFrameNum = timeInterval.last | 91 lastFrameNum = timeInterval.last |
94 | 92 |
95 while ret and frameNum <= lastFrameNum: | 93 while ret and frameNum <= lastFrameNum: |
96 ret, img = capture.read() | 94 ret, img = capture.read() |
97 if ret: | 95 if ret: |