Mercurial Hosting > traffic-intelligence
comparison scripts/polytracktopdtv.py @ 998:933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 27 May 2018 23:22:48 -0400 |
parents | 3058e00887bc |
children | cc5cb04b04b0 |
comparison
equal
deleted
inserted
replaced
997:4f3387a242a1 | 998:933670761a57 |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env python3 |
2 | 2 |
3 from pdtv import TsaiCamera, ZipVideo, SyncedVideos, TrackSet, Track, State | 3 from pdtv import TsaiCamera, ZipVideo, SyncedVideos, TrackSet, Track, State |
4 import sys, os, datetime, argparse | 4 import sys, os, datetime, argparse |
5 import shutil | 5 import shutil |
6 import sqlite3 | 6 import sqlite3 |
66 | 66 |
67 currentIdx = firstFrameNum | 67 currentIdx = firstFrameNum |
68 frameList = cvutils.getImagesFromVideo(videoFile, firstFrameNum = currentIdx, nFrames = inc) | 68 frameList = cvutils.getImagesFromVideo(videoFile, firstFrameNum = currentIdx, nFrames = inc) |
69 | 69 |
70 while len(frameList) == inc and inc > 0: | 70 while len(frameList) == inc and inc > 0: |
71 | |
72 for f in frameList: | 71 for f in frameList: |
73 cv2.imwrite(os.path.join(framePath,time.strftime("%Y%m%d-%H%M%S.%f")[:-3]+'.jpg'), f) | 72 cv2.imwrite(os.path.join(framePath,time.strftime("%Y%m%d-%H%M%S.%f")[:-3]+'.jpg'), f) |
74 time += datetime.timedelta(microseconds=deltaTimestamp*1000) | 73 time += datetime.timedelta(microseconds=deltaTimestamp*1000) |
75 currentIdx = currentIdx + inc | 74 currentIdx = currentIdx + inc |
76 | 75 |
78 delta = lastFrameNum-currentIdx | 77 delta = lastFrameNum-currentIdx |
79 if delta < inc: | 78 if delta < inc: |
80 inc = delta | 79 inc = delta |
81 if inc: | 80 if inc: |
82 frameList = cvutils.getImagesFromVideo(videoFile, firstFrameNum = currentIdx, nFrames = inc) | 81 frameList = cvutils.getImagesFromVideo(videoFile, firstFrameNum = currentIdx, nFrames = inc) |
83 print('Extracting frame ' + str(currentIdx)) | 82 print('Extracting frame {}'.format(currentIdx)) |
84 return len(frameList) > 0 | 83 return len(frameList) > 0 |
85 | 84 |
86 | 85 |
87 | 86 |
88 def convertDatabase(workDirname, sectionName, sceneFilename = None, databaseFilename = None, videoFilename = None, videoFolderExist = False, firstFrameNum = 0, lastFrameNum = None, cameraCalibrationFilename = None, outputFileName = 'roaduser.json'): | 87 def convertDatabase(workDirname, sectionName, sceneFilename = None, databaseFilename = None, videoFilename = None, videoFolderExist = False, firstFrameNum = 0, lastFrameNum = None, cameraCalibrationFilename = None, outputFileName = 'roaduser.json'): |
113 videoFolderPath = os.path.join(workDirname, "videoframes/") | 112 videoFolderPath = os.path.join(workDirname, "videoframes/") |
114 fileName = sectionName | 113 fileName = sectionName |
115 | 114 |
116 if videoFile is not None: | 115 if videoFile is not None: |
117 fps = cvutils.getFPS(videoFile) | 116 fps = cvutils.getFPS(videoFile) |
118 print('Video should run at ' + str(fps) + ' fps') | 117 print('Video should run at {} fps'.format(fps)) |
119 deltaTimestamp = 1000.0/float(fps); | 118 deltaTimestamp = 1000.0/float(fps); |
120 if videoFolderExist == False: | 119 if videoFolderExist == False: |
121 if os.path.exists(videoFolderPath): | 120 if os.path.exists(videoFolderPath): |
122 shutil.rmtree(videoFolderPath) | 121 shutil.rmtree(videoFolderPath) |
123 utils.mkdir(videoFolderPath) | 122 utils.mkdir(videoFolderPath) |