Mercurial Hosting > traffic-intelligence
comparison scripts/manual-video-analysis.py @ 889:4ea296ee1ae2
work in progress
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 24 Mar 2017 14:20:01 -0400 |
parents | d2eb8c93f7de |
children | 85bcc758ee5b |
comparison
equal
deleted
inserted
replaced
888:40994bb43148 | 889:4ea296ee1ae2 |
---|---|
23 c: Go back 100 frames | 23 c: Go back 100 frames |
24 x: Go back 10 frames | 24 x: Go back 10 frames |
25 Spacebar: Go forward one frame | 25 Spacebar: Go forward one frame |
26 l: Skip to frame number | 26 l: Skip to frame number |
27 q: Quit and end program''') | 27 q: Quit and end program''') |
28 # configuration of keys and user types (see moving) | |
29 userTypeNames = ['unknown', | |
30 'car', | |
31 'pedestrian', | |
32 'motorcycle', | |
33 'bicycle', | |
34 'bus', | |
35 'truck'] | |
36 class UserConfiguration(object): | |
37 def __init__(self, name, keyNew, keyAddInstant): | |
38 self.name = name | |
39 self.keyNew = ord(keyNew) | |
40 self.keyAddInstant = ord(keyAddInstant) | |
41 self.userNum = 0 | |
42 self.userInstant = 0 | |
28 | 43 |
44 def isKeyNew(self, k): | |
45 return (k == self.keyNew) | |
46 | |
47 def isKeyAddInstant(self, k): | |
48 return (k == self.keyAddInstant) | |
49 | |
50 def isKey(self, k): | |
51 return self.isKeyNew() or self.isKeyAddInstant() | |
52 | |
53 @staticmethod | |
54 def isKey(configurations): | |
55 for c in configurations: | |
56 if c.isKey(): | |
57 return c | |
58 return None | |
59 | |
60 userConfigurations = [UserConfiguration(userTypeNames[1],1,'u','i'), | |
61 UserConfiguration(userTypeNames[2],2,'j','k')] | |
62 | |
63 # start of program | |
29 cap = cv2.VideoCapture(args.videoFilename) | 64 cap = cv2.VideoCapture(args.videoFilename) |
30 cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, args.firstFrameNum) | 65 cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, args.firstFrameNum) |
31 cv2.namedWindow('Video', cv2.WINDOW_NORMAL) | 66 cv2.namedWindow('Video', cv2.WINDOW_NORMAL) |
32 | 67 |
33 # output filename | 68 # output filename |
48 frameNum = int(cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)) | 83 frameNum = int(cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)) |
49 cv2.putText(frame, str(frameNum), (1,20), cv2.FONT_HERSHEY_PLAIN, 1, (255, 0,0)) | 84 cv2.putText(frame, str(frameNum), (1,20), cv2.FONT_HERSHEY_PLAIN, 1, (255, 0,0)) |
50 cv2.imshow('Video',frame) | 85 cv2.imshow('Video',frame) |
51 | 86 |
52 key= cv2.waitKey(0) | 87 key= cv2.waitKey(0) |
53 #Change the keys to record the vehicle in this section | 88 |
54 if key == ord('q'): | 89 if key == ord('q'): |
55 break | 90 break |
91 else: | |
92 config = UserConfiguration.isKey(userConfigurations) | |
93 if config is not None: | |
94 if c.isKeyNew(): | |
95 pass # increment userNum | |
96 elif c.isKeyAddInstant(): | |
97 pass # increment userInstant | |
98 # print/write | |
99 | |
56 elif key == ord('u') or key == ord('i'): | 100 elif key == ord('u') or key == ord('i'): |
57 if key == ord('u'): | 101 if key == ord('u'): |
58 vehNumber += 1 | 102 vehNumber += 1 |
59 lineNum = 0 | 103 lineNum = 0 |
60 print('New Vehicle') | 104 print('New Vehicle') |