Mercurial Hosting > traffic-intelligence
annotate scripts/manual-video-analysis.py @ 1253:ef68d4ba7dae
added loading ego vehicle in kitti 2D format and method to plot outline
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 25 Mar 2024 17:05:20 -0400 |
parents | 4cd8ace3552f |
children |
rev | line source |
---|---|
998
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
891
diff
changeset
|
1 #! /usr/bin/env python3 |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
3 import sys, argparse, cv2, numpy as np |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
4 |
1118 | 5 parser = argparse.ArgumentParser(description='''The program replays the video and allows to manually id vehicles and mark instants, eg when they cross given areas in the scene. Use this program in combination with a screen marker program (For example, Presentation Assistant) to draw multiple lines on the screen.''', |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
6 epilog = '''The output should give you a .csv file with the same name as your video file with columns in this format: |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
7 vehicle number, frame number |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
8 You can easily spot mistakes in the csv file for a line with number, SKIP. If this happens, just delete the previous vehicle observation.''', |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
9 formatter_class=argparse.RawDescriptionHelpFormatter) |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
10 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file', required = True) |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
11 parser.add_argument('-o', dest = 'outputFilename', help = 'name of the output file (csv file)') |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', default = 0, type = int) |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
13 parser.add_argument('-n', dest = 'nAttributes', help = 'number of attributes characterizing users', default = 0, type = int) |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
14 |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
15 args = parser.parse_args() |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
16 |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
17 print('''Commands: |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
18 Press o when you make a mistake in input |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
19 Press d to skip 100 frames |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
20 Press s to skip 10 frames |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
21 Press c to go back 100 frames |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
22 Press x to go back 10 frames |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
23 Press spacebar to go forward one frame |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
24 Press l to skip to frame number |
998
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
891
diff
changeset
|
25 Press s to finish inputting user characteristics (if any in pop up window) |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
26 Press q to quit and end program''') |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
27 # configuration of keys and user types (see moving) |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
28 userTypeNames = ['unknown', |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
29 'car', |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
30 'pedestrian', |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
31 'motorcycle', |
1242
4cd8ace3552f
major update for classification, allowing the use of neural network classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1228
diff
changeset
|
32 'cyclist', |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
33 'bus', |
1242
4cd8ace3552f
major update for classification, allowing the use of neural network classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1228
diff
changeset
|
34 'truck', |
4cd8ace3552f
major update for classification, allowing the use of neural network classification
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
1228
diff
changeset
|
35 'automated'] |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
36 class UserConfiguration(object): |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
37 def __init__(self, name, keyNew, keyAddInstant, nAttributes): |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
38 self.name = name |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
39 self.keyNew = ord(keyNew) |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
40 self.keyAddInstant = ord(keyAddInstant) |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
41 self.userNum = 0 |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
42 self.nAttributes = nAttributes |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
43 self.resetAttributes() |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
44 |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
45 def getHelpStr(self): |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
46 return 'Press {} for new {}, {} for new instant for current {}'.format(chr(self.keyNew), self.name, chr(self.keyAddInstant), self.name) |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
47 |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
48 def resetAttributes(self): |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
49 self.userInstant = 0 |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
50 self.attributes = [-1]*self.nAttributes |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
51 |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
52 def setAttribute(self, i, value): |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
53 self.attributes[i%self.nAttributes] = value |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
54 |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
55 def getAttributeStr(self): |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
56 if self.nAttributes > 0: |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
57 return ','.join([str(i) for i in self.attributes])+',' |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
58 else: |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
59 return '' |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
60 |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
61 def isKeyNew(self, k): |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
62 return (k == self.keyNew) |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
63 |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
64 def isKeyAddInstant(self, k): |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
65 return (k == self.keyAddInstant) |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
66 |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
67 def isKey(self, k): |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
68 return self.isKeyNew(k) or self.isKeyAddInstant(k) |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
69 |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
70 @staticmethod |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
71 def getConfigurationWithKey(configurations, k): |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
72 for c in configurations: |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
73 if c.isKey(k): |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
74 return c |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
75 return None |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
76 |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
77 userConfigurations = [UserConfiguration(userTypeNames[1],'u','i', args.nAttributes), |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
78 UserConfiguration(userTypeNames[2],'j','k', args.nAttributes)] |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
79 |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
80 print(' ') |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
81 for c in userConfigurations: |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
82 print(c.getHelpStr()) |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
83 |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
84 # start of program |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
85 cap = cv2.VideoCapture(args.videoFilename) |
998
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
891
diff
changeset
|
86 cap.set(cv2.CAP_PROP_POS_FRAMES, args.firstFrameNum) |
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
891
diff
changeset
|
87 fps = cap.get(cv2.CAP_PROP_FPS) |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
88 print('Video at {} frames/s'.format(fps)) |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
89 cv2.namedWindow('Video', cv2.WINDOW_NORMAL) |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
90 |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
91 # output filename |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
92 if args.outputFilename is None: |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
93 i = args.videoFilename.rfind('.') |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
94 if i>0: |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
95 outputFilename = args.videoFilename[:i]+'.csv' |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
96 else: |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
97 outputFilename = args.videoFilename+'.csv' |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
98 else: |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
99 outputFilename = args.outputFilename |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
100 vehNumber = 0 |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
101 lineNum = -1 |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
102 out = open(outputFilename, 'a') |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
103 |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
104 while(cap.isOpened()): |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
105 ret, frame = cap.read() |
998
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
891
diff
changeset
|
106 frameNum = int(cap.get(cv2.CAP_PROP_POS_FRAMES)) |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
107 cv2.putText(frame, str(frameNum), (1,20), cv2.FONT_HERSHEY_PLAIN, 1, (255, 0,0)) |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
108 cv2.imshow('Video',frame) |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
109 |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
110 key= cv2.waitKey(0) |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
111 |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
112 if key == ord('q'): |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
113 break |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
114 else: |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
115 config = UserConfiguration.getConfigurationWithKey(userConfigurations, key) |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
116 if config is not None: |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
117 if config.isKeyNew(key): |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
118 config.userNum += 1 |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
119 config.resetAttributes() |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
120 print('New {} {}'.format(config.name, config.userNum)) |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
121 if args.nAttributes > 0: |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
122 key2 = ord('1') |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
123 cv2.namedWindow('Input', cv2.WINDOW_NORMAL) |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
124 attributeNum = 0 |
891
ab3a4cb524a9
forgot frame number
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
890
diff
changeset
|
125 while key2 != ord('s'): |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
126 attrImg = 255*np.ones((20*args.nAttributes, 20, 3)) |
998
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
891
diff
changeset
|
127 for i in range(args.nAttributes): |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
128 if i == (attributeNum%args.nAttributes): |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
129 cv2.putText(attrImg, str(config.attributes[i]), (1,20*(i+1)), cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 255)) |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
130 else: |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
131 cv2.putText(attrImg, str(config.attributes[i]), (1,20*(i+1)), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0)) |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
132 cv2.imshow('Input', attrImg) |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
133 key2 = cv2.waitKey(0) |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
134 if chr(key2).isdigit(): |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
135 config.setAttribute(attributeNum, chr(key2)) |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
136 attributeNum += 1 |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
137 cv2.destroyWindow('Input') |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
138 elif config.isKeyAddInstant(key): |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
139 config.userInstant += 1 |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
140 print('User {} no {} at line {}'.format(config.name, config.userNum, config.userInstant)) |
891
ab3a4cb524a9
forgot frame number
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
890
diff
changeset
|
141 out.write('{},{},{}{},{}\n'.format(config.userNum, config.name, config.getAttributeStr(), config.userInstant, frameNum)) |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
142 oldUserConfig = config |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
143 if key == ord('o'): |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
144 print('SKIPPED') |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
145 out.write('{},{},SKIP\n'.format(oldUserConfig.userNum, oldUserConfig.name)) |
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
146 elif key == ord('d'): |
1120 | 147 cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum+100) |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
148 elif key == ord('s'): |
1120 | 149 cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum+10) |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
150 elif key == ord('a'): |
1120 | 151 cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum+1) |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
152 elif key == ord('x'): |
1120 | 153 cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum-10) |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
154 elif key == ord('c'): |
1120 | 155 cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum-100) |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
156 elif key == ord('l'): |
998
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
891
diff
changeset
|
157 frameNum = int(input("Please enter the frame number you would like to skip to\n")) |
933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
891
diff
changeset
|
158 cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum) |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
159 |
890
85bcc758ee5b
new version to manual annotation, easy to configure to add new road user type and characteristics
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
889
diff
changeset
|
160 out.close() |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
161 cap.release() |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
162 cv2.destroyAllWindows() |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
163 |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
164 #97a |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
165 #115s |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
166 #100d |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
167 #102f |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
168 #103g |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
169 #104h |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
170 #106j |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
171 #107k |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
172 #108l |