commit 27f53c446fe7dbf83c962bba291d38a9ffe3bdf5
parent 40b3909db7318ddfb5f7976f5bd56f4fa4dd4700
Author: Marcel <MTRNord@users.noreply.github.com>
Date: Sun, 9 Oct 2016 16:09:50 +0200
Create stage3_analyseVideo.py
Diffstat:
1 file changed, 39 insertions(+), 0 deletions(-)
diff --git a/scripts/stage3_analyseVideo.py b/scripts/stage3_analyseVideo.py
@@ -0,0 +1,39 @@
+#This is:
+# __ __ .___ __________
+# / \ / \| |\______ \
+# \ \/\/ /| | | ___/
+# \ / | | | |
+# \__/\ / |___| |____|
+# \/ (Work in progress)
+#
+##### Video to single frames comes from: http://stackoverflow.com/a/19082750/4929236 #####
+
+import cv2
+
+cap = cv2.VideoCapture("./out.mp4")
+while not cap.isOpened():
+ cap = cv2.VideoCapture("./out.mp4")
+ cv2.waitKey(1000)
+ print "Wait for the header"
+
+pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
+while True:
+ flag, frame = cap.read()
+ if flag:
+ # The frame is ready and already captured
+ cv2.imshow('video', frame)
+ pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
+ print str(pos_frame)+" frames"
+ else:
+ # The next frame is not ready, so we try to read it again
+ cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos_frame-1)
+ print "frame is not ready"
+ # It is better to wait for a while for the next frame to be ready
+ cv2.waitKey(1000)
+
+ if cv2.waitKey(10) == 27:
+ break
+ if cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) == cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT):
+ # If the number of captured frames is equal to the total number of frames,
+ # we stop
+ break