Skip to content

Commit

Permalink
Add video output and put in comment cv2 window
Browse files Browse the repository at this point in the history
  • Loading branch information
bessszilard committed Jul 29, 2020
1 parent c277c09 commit 9ab55b3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions detectvideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
flags.DEFINE_string('video', './data/road.mp4', 'path to input video')
flags.DEFINE_float('iou', 0.45, 'iou threshold')
flags.DEFINE_float('score', 0.25, 'score threshold')
flags.DEFINE_string('output', None, 'path to output video')
flags.DEFINE_string('output_format', 'XVID', 'codec used in VideoWriter when saving video to file')

def main(_argv):
config = ConfigProto()
Expand All @@ -45,6 +47,14 @@ def main(_argv):
else:
saved_model_loaded = tf.saved_model.load(FLAGS.weights, tags=[tag_constants.SERVING])
infer = saved_model_loaded.signatures['serving_default']

if FLAGS.output:
# by default VideoCapture returns float instead of int
width = int(vid.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = int(vid.get(cv2.CAP_PROP_FPS))
codec = cv2.VideoWriter_fourcc(*FLAGS.output_format)
out = cv2.VideoWriter(FLAGS.output, codec, fps, (width, height))

while True:
return_value, frame = vid.read()
Expand Down Expand Up @@ -92,10 +102,14 @@ def main(_argv):
result = np.asarray(image)
info = "time: %.2f ms" %(1000*exec_time)
print(info)
cv2.namedWindow("result", cv2.WINDOW_AUTOSIZE)
result = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
cv2.imshow("result", result)
if cv2.waitKey(1) & 0xFF == ord('q'): break
# cv2.namedWindow("result", cv2.WINDOW_AUTOSIZE)
# result = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
# cv2.imshow("result", result)
# if cv2.waitKey(1) & 0xFF == ord('q'): break

if FLAGS.output:
result = cv2.cvtColor(result, cv2.COLOR_RGB2BGR)
out.write(result)

if __name__ == '__main__':
try:
Expand Down

0 comments on commit 9ab55b3

Please sign in to comment.