Skip to content

Instantly share code, notes, and snippets.

@blech
Forked from celoyd/sscan.py
Created March 21, 2018 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blech/add7a12ef4b0b72e3d2e3485c9e6aa64 to your computer and use it in GitHub Desktop.
Save blech/add7a12ef4b0b72e3d2e3485c9e6aa64 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# ./sscan.py input.mov rownumber output.png
# This is meant to be hyper-simple and makes
# some assumptions like: you want a row (not
# a column), the video is RGB (not gray), etc.
# Bug: frame_count is sometimes fractional.
# int() and the "if not okay" are workarounds.
import numpy as np
import cv2
from sys import argv
movf, row, outf = argv[1:]
row = int(row)
slice_width=12
viddy = cv2.VideoCapture(movf)
width = int(viddy.get(3)) # can you tell this API is by C programmers?
height = int(viddy.get(4))
frame_count = int(viddy.get(7))
print width, height, frame_count
rows = np.empty((height, frame_count*slice_width, 3)) # 3 channels
for frame_n in range(frame_count):
print("%s/%s" % (frame_n, frame_count)) # or not
okay, frame = viddy.read()
if not okay: break
for i in range(0, slice_width):
rows[:,(slice_width*frame_n)+i] = frame[:,row+i]
cv2.imwrite(outf, rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment