Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/display-synced-trajectories.py @ 1012:01db14e947e4
resolved
| author | Wendlasida |
|---|---|
| date | Fri, 01 Jun 2018 10:47:49 -0400 |
| parents | 933670761a57 |
| children | cc5cb04b04b0 |
comparison
equal
deleted
inserted
replaced
| 1011:4f0312bee393 | 1012:01db14e947e4 |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python3 |
| 2 | 2 |
| 3 import sys, argparse, os.path | 3 import sys, argparse, os.path |
| 4 from datetime import datetime, timedelta | 4 from datetime import datetime, timedelta |
| 5 import numpy as np | 5 import numpy as np |
| 6 import cv2 | 6 import cv2 |
| 55 if len(filenames) == 0: | 55 if len(filenames) == 0: |
| 56 print('Empty filename list') | 56 print('Empty filename list') |
| 57 sys.exit() | 57 sys.exit() |
| 58 | 58 |
| 59 if windowNames is None: | 59 if windowNames is None: |
| 60 windowNames = ['frame{}'.format(i) for i in xrange(len(filenames))] | 60 windowNames = ['frame{}'.format(i) for i in range(len(filenames))] |
| 61 #wait = 5 | 61 #wait = 5 |
| 62 #if rescale == 1.: | 62 #if rescale == 1.: |
| 63 for windowName in windowNames: | 63 for windowName in windowNames: |
| 64 cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) | 64 cv2.namedWindow(windowName, cv2.WINDOW_NORMAL) |
| 65 #if frameRate > 0: | 65 #if frameRate > 0: |
| 70 captures = [cv2.VideoCapture(fn) for fn in filenames] | 70 captures = [cv2.VideoCapture(fn) for fn in filenames] |
| 71 if np.array([cap.isOpened() for cap in captures]).all(): | 71 if np.array([cap.isOpened() for cap in captures]).all(): |
| 72 key = -1 | 72 key = -1 |
| 73 ret = True | 73 ret = True |
| 74 nFramesShown = 0 | 74 nFramesShown = 0 |
| 75 for i in xrange(len(captures)): | 75 for i in range(len(captures)): |
| 76 if firstFrameNums[i] > 0: | 76 if firstFrameNums[i] > 0: |
| 77 captures[i].set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNums[i]) | 77 captures[i].set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNums[i]) |
| 78 while ret and not cvutils.quitKey(key): | 78 while ret and not cvutils.quitKey(key): |
| 79 rets = [] | 79 rets = [] |
| 80 images = [] | 80 images = [] |
| 81 for i in xrange(len(captures)): | 81 for i in range(len(captures)): |
| 82 if firstFrameNums[i]+nFramesShown>=0: | 82 if firstFrameNums[i]+nFramesShown>=0: |
| 83 ret, img = captures[i].read() | 83 ret, img = captures[i].read() |
| 84 if ret and args.undistort: | 84 if ret and args.undistort: |
| 85 img = cv2.remap(img, videoSequences[i].cameraView.cameraType.map1, videoSequences[i].cameraView.cameraType.map2, interpolation=cv2.INTER_LINEAR) | 85 img = cv2.remap(img, videoSequences[i].cameraView.cameraType.map1, videoSequences[i].cameraView.cameraType.map2, interpolation=cv2.INTER_LINEAR) |
| 86 rets.append(ret) | 86 rets.append(ret) |
| 89 rets.append(False) | 89 rets.append(False) |
| 90 images.append(None) | 90 images.append(None) |
| 91 if np.array(rets).any(): | 91 if np.array(rets).any(): |
| 92 #if printFrames: | 92 #if printFrames: |
| 93 print('frame shown {0}'.format(nFramesShown)) | 93 print('frame shown {0}'.format(nFramesShown)) |
| 94 for i in xrange(len(filenames)): | 94 for i in range(len(filenames)): |
| 95 if rets[i]:#firstFrameNums[i]+nFramesShown>=0: | 95 if rets[i]:#firstFrameNums[i]+nFramesShown>=0: |
| 96 for obj in objects: | 96 for obj in objects: |
| 97 if obj.existsAtInstant(mergedFirstFrameNum+nFramesShown): | 97 if obj.existsAtInstant(mergedFirstFrameNum+nFramesShown): |
| 98 #print obj.num, obj.timeInterval, mergedFirstFrameNum, nFramesShown | 98 #print obj.num, obj.timeInterval, mergedFirstFrameNum, nFramesShown |
| 99 if i not in obj.projectedPositions: | 99 if i not in obj.projectedPositions: |
| 109 key = cv2.waitKey(wait) | 109 key = cv2.waitKey(wait) |
| 110 #if cvutils.saveKey(key): | 110 #if cvutils.saveKey(key): |
| 111 # cv2.imwrite('image-{}.png'.format(frameNum), img) | 111 # cv2.imwrite('image-{}.png'.format(frameNum), img) |
| 112 nFramesShown += args.step | 112 nFramesShown += args.step |
| 113 if args.step > 1: | 113 if args.step > 1: |
| 114 for i in xrange(len(captures)): | 114 for i in range(len(captures)): |
| 115 if firstFrameNums[i]+nFramesShown >= 0: | 115 if firstFrameNums[i]+nFramesShown >= 0: |
| 116 captures[i].set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNums[i]+nFramesShown) | 116 captures[i].set(cv2.cv.CV_CAP_PROP_POS_FRAMES, firstFrameNums[i]+nFramesShown) |
| 117 cv2.destroyAllWindows() | 117 cv2.destroyAllWindows() |
| 118 else: | 118 else: |
| 119 print('Video captures for {} failed'.format(filenames)) | 119 print('Video captures for {} failed'.format(filenames)) |
