Permalink
Browse files

log2video.py - add experiment with similarity

  • Loading branch information...
m3d committed Oct 18, 2018
1 parent 681afd3 commit 9194949165d2a895e14d387c8e866c584f8ff2ef
Showing with 11 additions and 0 deletions.
  1. +11 −0 tools/log2video.py
@@ -10,6 +10,7 @@
import cv2
import numpy as np
from skimage.measure import compare_ssim
from osgar.logger import LogReader, lookup_stream_id
from osgar.lib.serialize import deserialize
@@ -19,6 +20,7 @@ def create_video(logfile, outFilename, add_time=False):
assert outFilename.endswith(".avi"), outFilename
only_stream = lookup_stream_id(logfile, 'camera.raw')
writer = None
prev = None
with LogReader(logfile) as log:
for timestamp, stream_id, data in log.read_gen(only_stream):
buf = deserialize(data)
@@ -27,11 +29,20 @@ def create_video(logfile, outFilename, add_time=False):
height, width = img.shape[:2]
writer = cv2.VideoWriter( outFilename, cv2.VideoWriter_fourcc('F', 'M', 'P', '4'), 5, (width, height))
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
sim = 1
if prev is not None:
sim = compare_ssim(prev, gray, full=False)
print('%s\t%.3f' % (str(timestamp), sim))
if add_time:
x, y = 800, 100
s = str(timestamp)[:-3] # clip microseconds to miliseconds
cv2.putText(img, s, (x, y), cv2.FONT_HERSHEY_PLAIN, 5.0, (255, 255, 255), thickness=5)
x, y = 0, 100
s = str(sim)[:5]
cv2.putText(img, s, (x, y), cv2.FONT_HERSHEY_PLAIN, 5.0, (255, 255, 255), thickness=5)
writer.write(img)
prev = gray
writer.release()

0 comments on commit 9194949

Please sign in to comment.