Mercurial Hosting > traffic-intelligence
annotate scripts/manual-video-analysis.py @ 919:7b3f2e0a2652
saving and loading prototype trajectories
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 05 Jul 2017 13:16:47 -0400 |
parents | ab3a4cb524a9 |
children | 933670761a57 |
rev | line source |
---|---|
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
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 |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
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.''', |
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 |
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
|
25 Press Enter to finish inputting user characteristics (if any in pop up window) |
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', |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
32 'bicycle', |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
33 'bus', |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
34 'truck'] |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
35 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
|
36 def __init__(self, name, keyNew, keyAddInstant, nAttributes): |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
37 self.name = name |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
38 self.keyNew = ord(keyNew) |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
39 self.keyAddInstant = ord(keyAddInstant) |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 |
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 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
|
45 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
|
46 |
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 def resetAttributes(self): |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
48 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
|
49 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
|
50 |
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
|
51 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
|
52 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
|
53 |
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 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
60 def isKeyNew(self, k): |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
61 return (k == self.keyNew) |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
62 |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
63 def isKeyAddInstant(self, k): |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
64 return (k == self.keyAddInstant) |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
65 |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
66 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
|
67 return self.isKeyNew(k) or self.isKeyAddInstant(k) |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
68 |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
69 @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
|
70 def getConfigurationWithKey(configurations, k): |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
71 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
|
72 if c.isKey(k): |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
73 return c |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
74 return None |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
75 |
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
|
76 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
|
77 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
|
78 |
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 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
|
80 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
|
81 print(c.getHelpStr()) |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
82 |
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
83 # start of program |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
84 cap = cv2.VideoCapture(args.videoFilename) |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
85 cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, args.firstFrameNum) |
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
|
86 fps = cap.get(cv2.cv.CV_CAP_PROP_FPS) |
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
|
87 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
|
88 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
|
89 |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
90 # output filename |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
91 if args.outputFilename is None: |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
92 i = args.videoFilename.rfind('.') |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
93 if i>0: |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
94 outputFilename = args.videoFilename[:i]+'.csv' |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
95 else: |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
96 outputFilename = args.videoFilename+'.csv' |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
97 else: |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
98 outputFilename = args.outputFilename |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
99 vehNumber = 0 |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
100 lineNum = -1 |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
101 out = open(outputFilename, 'a') |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
102 |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
103 while(cap.isOpened()): |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
104 ret, frame = cap.read() |
885
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
105 frameNum = int(cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)) |
7f61854fcc6d
first updated version of manual data collection script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
884
diff
changeset
|
106 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
|
107 cv2.imshow('Video',frame) |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
108 |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
109 key= cv2.waitKey(0) |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
110 |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
111 if key == ord('q'): |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
112 break |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
113 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
|
114 config = UserConfiguration.getConfigurationWithKey(userConfigurations, key) |
889
4ea296ee1ae2
work in progress
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
886
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 attributeNum = 0 |
891
ab3a4cb524a9
forgot frame number
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
890
diff
changeset
|
124 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
|
125 attrImg = 255*np.ones((20*args.nAttributes, 20, 3)) |
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 for i in xrange(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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 elif key == ord('d'): |
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 cap.set(1,frameNum+100) |
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
|
147 elif key == ord('s'): |
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 cap.set(1,frameNum+10) |
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
|
149 elif key == ord('a'): |
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 cap.set(1,frameNum+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
|
151 elif key == ord('x'): |
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 cap.set(1,frameNum-10) |
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
|
153 elif key == ord('c'): |
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 cap.set(1,frameNum-100) |
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
|
155 elif key == ord('l'): |
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 frameNum = int(raw_input("Please enter the frame number you would like to skip to\n")) |
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
|
157 cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES,frameNum) |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
158 |
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
|
159 out.close() |
884
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
160 cap.release() |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
161 cv2.destroyAllWindows() |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
162 |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
163 #97a |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
164 #115s |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
165 #100d |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
166 #102f |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
167 #103g |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
168 #104h |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
169 #106j |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
170 #107k |
ac4bcbcc9cda
added manual data collection script, thanks Philip Morse!
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
171 #108l |