comparison scripts/polytracktopdtv.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 4dd68b0765b1
children 933670761a57
comparison
equal deleted inserted replaced
635:6ae68383071e 636:3058e00887bc
33 ... and other type if the objects_type table is defined in SQLite''' 33 ... and other type if the objects_type table is defined in SQLite'''
34 typeDict = dict() 34 typeDict = dict()
35 cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='objects_type'") 35 cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='objects_type'")
36 data = cursor.fetchone() 36 data = cursor.fetchone()
37 37
38 if(data == None): 38 if(data is None):
39 typeDict["0"] = "unknown" 39 typeDict["0"] = "unknown"
40 typeDict["1"] = "car" 40 typeDict["1"] = "car"
41 typeDict["2"] = "pedestrians" 41 typeDict["2"] = "pedestrians"
42 typeDict["3"] = "motorcycle" 42 typeDict["3"] = "motorcycle"
43 typeDict["4"] = "bicycle" 43 typeDict["4"] = "bicycle"
57 deltaTimestamp = 1000.0/float(fps); 57 deltaTimestamp = 1000.0/float(fps);
58 time+=datetime.timedelta(microseconds=firstFrameNum*deltaTimestamp*1000) 58 time+=datetime.timedelta(microseconds=firstFrameNum*deltaTimestamp*1000)
59 59
60 inc = 1000 #How many frame we fetch in the video at a time 60 inc = 1000 #How many frame we fetch in the video at a time
61 61
62 if lastFrameNum != None: 62 if lastFrameNum is not None:
63 delta = lastFrameNum-firstFrameNum 63 delta = lastFrameNum-firstFrameNum
64 if delta < inc: 64 if delta < inc:
65 inc = delta 65 inc = delta
66 66
67 currentIdx = firstFrameNum 67 currentIdx = firstFrameNum
72 for f in frameList: 72 for f in frameList:
73 cv2.imwrite(os.path.join(framePath,time.strftime("%Y%m%d-%H%M%S.%f")[:-3]+'.jpg'), f) 73 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) 74 time += datetime.timedelta(microseconds=deltaTimestamp*1000)
75 currentIdx = currentIdx + inc 75 currentIdx = currentIdx + inc
76 76
77 if lastFrameNum != None: 77 if lastFrameNum is not None:
78 delta = lastFrameNum-currentIdx 78 delta = lastFrameNum-currentIdx
79 if delta < inc: 79 if delta < inc:
80 inc = delta 80 inc = delta
81 if inc: 81 if inc:
82 frameList = cvutils.getImagesFromVideo(videoFile, firstFrameNum = currentIdx, nFrames = inc) 82 frameList = cvutils.getImagesFromVideo(videoFile, firstFrameNum = currentIdx, nFrames = inc)
94 videoFolderExist specifiy if we want to reextract the video frame or if they already exist at workdir/videoframes/ 94 videoFolderExist specifiy if we want to reextract the video frame or if they already exist at workdir/videoframes/
95 firstFrameNum is the first frame we want to extract 95 firstFrameNum is the first frame we want to extract
96 lastFrameNum is the last frame we want to extract (or None if we want to extract everything) 96 lastFrameNum is the last frame we want to extract (or None if we want to extract everything)
97 ''' 97 '''
98 error = False 98 error = False
99 if sceneFilename != None: 99 if sceneFilename is not None:
100 scene = utils.SceneParameters.loadConfigFile(os.path.join(workDirname, sceneFilename)) 100 scene = utils.SceneParameters.loadConfigFile(os.path.join(workDirname, sceneFilename))
101 time = scene[sectionName].date 101 time = scene[sectionName].date
102 inputDb = os.path.join(workDirname, scene[sectionName].databaseFilename) 102 inputDb = os.path.join(workDirname, scene[sectionName].databaseFilename)
103 videoFile = os.path.join(workDirname, scene[sectionName].videoFilename) 103 videoFile = os.path.join(workDirname, scene[sectionName].videoFilename)
104 104
105 if databaseFilename != None: 105 if databaseFilename is not None:
106 inputDb = os.path.join(workDirname, databaseFilename) 106 inputDb = os.path.join(workDirname, databaseFilename)
107 if videoFilename != None: 107 if videoFilename is not None:
108 videoFile = os.path.join(workDirname, videoFilename) 108 videoFile = os.path.join(workDirname, videoFilename)
109 # elif videoFolderExist == False: 109 # elif videoFolderExist == False:
110 # print('No video path specified') 110 # print('No video path specified')
111 # error = True 111 # error = True
112 112
113 videoFolderPath = os.path.join(workDirname, "videoframes/") 113 videoFolderPath = os.path.join(workDirname, "videoframes/")
114 fileName = sectionName 114 fileName = sectionName
115 115
116 if videoFile != None: 116 if videoFile is not None:
117 fps = cvutils.getFPS(videoFile) 117 fps = cvutils.getFPS(videoFile)
118 print('Video should run at ' + str(fps) + ' fps') 118 print('Video should run at ' + str(fps) + ' fps')
119 deltaTimestamp = 1000.0/float(fps); 119 deltaTimestamp = 1000.0/float(fps);
120 if videoFolderExist == False: 120 if videoFolderExist == False:
121 if os.path.exists(videoFolderPath): 121 if os.path.exists(videoFolderPath):
145 print('Zipping files...') 145 print('Zipping files...')
146 if not os.path.exists(inputZipVideoName) or not videoFolderExist: 146 if not os.path.exists(inputZipVideoName) or not videoFolderExist:
147 zipFolder(videoFolderPath, inputZipVideoName) 147 zipFolder(videoFolderPath, inputZipVideoName)
148 print('Zipping files...Done.') 148 print('Zipping files...Done.')
149 #We generate the structure for ZipVideo 149 #We generate the structure for ZipVideo
150 if cameraCalibrationFilename != None: 150 if cameraCalibrationFilename is not None:
151 calibrationFile = cameraCalibrationFilename 151 calibrationFile = cameraCalibrationFilename
152 else: 152 else:
153 calibrationFile = 'calib.json' 153 calibrationFile = 'calib.json'
154 zipVideo = ZipVideo(video_zip_file=inputZipVideoName, 154 zipVideo = ZipVideo(video_zip_file=inputZipVideoName,
155 time_offset=0.0, time_scale=1.0, master_timestamps=masterTimestampList, calibration_file=calibrationFile) 155 time_offset=0.0, time_scale=1.0, master_timestamps=masterTimestampList, calibration_file=calibrationFile)
187 trackset.append(t) 187 trackset.append(t)
188 print('Reading boundingbox table') 188 print('Reading boundingbox table')
189 #3) We read the bounding box table 189 #3) We read the bounding box table
190 cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='bounding_boxes'") 190 cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='bounding_boxes'")
191 data = cursor.fetchone() 191 data = cursor.fetchone()
192 if data == None: 192 if data is None:
193 print('No bounding box table. Maybe it was not generated ?') 193 print('No bounding box table. Maybe it was not generated ?')
194 else: 194 else:
195 cursor.execute("SELECT object_id, frame_number, x_top_left, y_top_left, x_bottom_right, y_bottom_right FROM bounding_boxes") 195 cursor.execute("SELECT object_id, frame_number, x_top_left, y_top_left, x_bottom_right, y_bottom_right FROM bounding_boxes")
196 for row in cursor: 196 for row in cursor:
197 objectId = row[0] 197 objectId = row[0]