Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/manual-video-analysis.py @ 1012:01db14e947e4
resolved
| author | Wendlasida |
|---|---|
| date | Fri, 01 Jun 2018 10:47:49 -0400 |
| parents | 933670761a57 |
| children | 234e2228fd30 |
comparison
equal
deleted
inserted
replaced
| 1011:4f0312bee393 | 1012:01db14e947e4 |
|---|---|
| 1 #! /usr/bin/env python | 1 #! /usr/bin/env python3 |
| 2 | 2 |
| 3 import sys, argparse, cv2, numpy as np | 3 import sys, argparse, cv2, numpy as np |
| 4 | 4 |
| 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.''', | 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.''', |
| 6 epilog = '''The output should give you a .csv file with the same name as your video file with columns in this format: | 6 epilog = '''The output should give you a .csv file with the same name as your video file with columns in this format: |
| 20 Press s to skip 10 frames | 20 Press s to skip 10 frames |
| 21 Press c to go back 100 frames | 21 Press c to go back 100 frames |
| 22 Press x to go back 10 frames | 22 Press x to go back 10 frames |
| 23 Press spacebar to go forward one frame | 23 Press spacebar to go forward one frame |
| 24 Press l to skip to frame number | 24 Press l to skip to frame number |
| 25 Press Enter to finish inputting user characteristics (if any in pop up window) | 25 Press s to finish inputting user characteristics (if any in pop up window) |
| 26 Press q to quit and end program''') | 26 Press q to quit and end program''') |
| 27 # configuration of keys and user types (see moving) | 27 # configuration of keys and user types (see moving) |
| 28 userTypeNames = ['unknown', | 28 userTypeNames = ['unknown', |
| 29 'car', | 29 'car', |
| 30 'pedestrian', | 30 'pedestrian', |
| 80 for c in userConfigurations: | 80 for c in userConfigurations: |
| 81 print(c.getHelpStr()) | 81 print(c.getHelpStr()) |
| 82 | 82 |
| 83 # start of program | 83 # start of program |
| 84 cap = cv2.VideoCapture(args.videoFilename) | 84 cap = cv2.VideoCapture(args.videoFilename) |
| 85 cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, args.firstFrameNum) | 85 cap.set(cv2.CAP_PROP_POS_FRAMES, args.firstFrameNum) |
| 86 fps = cap.get(cv2.cv.CV_CAP_PROP_FPS) | 86 fps = cap.get(cv2.CAP_PROP_FPS) |
| 87 print('Video at {} frames/s'.format(fps)) | 87 print('Video at {} frames/s'.format(fps)) |
| 88 cv2.namedWindow('Video', cv2.WINDOW_NORMAL) | 88 cv2.namedWindow('Video', cv2.WINDOW_NORMAL) |
| 89 | 89 |
| 90 # output filename | 90 # output filename |
| 91 if args.outputFilename is None: | 91 if args.outputFilename is None: |
| 100 lineNum = -1 | 100 lineNum = -1 |
| 101 out = open(outputFilename, 'a') | 101 out = open(outputFilename, 'a') |
| 102 | 102 |
| 103 while(cap.isOpened()): | 103 while(cap.isOpened()): |
| 104 ret, frame = cap.read() | 104 ret, frame = cap.read() |
| 105 frameNum = int(cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)) | 105 frameNum = int(cap.get(cv2.CAP_PROP_POS_FRAMES)) |
| 106 cv2.putText(frame, str(frameNum), (1,20), cv2.FONT_HERSHEY_PLAIN, 1, (255, 0,0)) | 106 cv2.putText(frame, str(frameNum), (1,20), cv2.FONT_HERSHEY_PLAIN, 1, (255, 0,0)) |
| 107 cv2.imshow('Video',frame) | 107 cv2.imshow('Video',frame) |
| 108 | 108 |
| 109 key= cv2.waitKey(0) | 109 key= cv2.waitKey(0) |
| 110 | 110 |
| 121 key2 = ord('1') | 121 key2 = ord('1') |
| 122 cv2.namedWindow('Input', cv2.WINDOW_NORMAL) | 122 cv2.namedWindow('Input', cv2.WINDOW_NORMAL) |
| 123 attributeNum = 0 | 123 attributeNum = 0 |
| 124 while key2 != ord('s'): | 124 while key2 != ord('s'): |
| 125 attrImg = 255*np.ones((20*args.nAttributes, 20, 3)) | 125 attrImg = 255*np.ones((20*args.nAttributes, 20, 3)) |
| 126 for i in xrange(args.nAttributes): | 126 for i in range(args.nAttributes): |
| 127 if i == (attributeNum%args.nAttributes): | 127 if i == (attributeNum%args.nAttributes): |
| 128 cv2.putText(attrImg, str(config.attributes[i]), (1,20*(i+1)), cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 255)) | 128 cv2.putText(attrImg, str(config.attributes[i]), (1,20*(i+1)), cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 255)) |
| 129 else: | 129 else: |
| 130 cv2.putText(attrImg, str(config.attributes[i]), (1,20*(i+1)), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0)) | 130 cv2.putText(attrImg, str(config.attributes[i]), (1,20*(i+1)), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0)) |
| 131 cv2.imshow('Input', attrImg) | 131 cv2.imshow('Input', attrImg) |
| 151 elif key == ord('x'): | 151 elif key == ord('x'): |
| 152 cap.set(1,frameNum-10) | 152 cap.set(1,frameNum-10) |
| 153 elif key == ord('c'): | 153 elif key == ord('c'): |
| 154 cap.set(1,frameNum-100) | 154 cap.set(1,frameNum-100) |
| 155 elif key == ord('l'): | 155 elif key == ord('l'): |
| 156 frameNum = int(raw_input("Please enter the frame number you would like to skip to\n")) | 156 frameNum = int(input("Please enter the frame number you would like to skip to\n")) |
| 157 cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES,frameNum) | 157 cap.set(cv2.CAP_PROP_POS_FRAMES,frameNum) |
| 158 | 158 |
| 159 out.close() | 159 out.close() |
| 160 cap.release() | 160 cap.release() |
| 161 cv2.destroyAllWindows() | 161 cv2.destroyAllWindows() |
| 162 | 162 |
