Skip to content

Instantly share code, notes, and snippets.

@celoyd
Last active March 21, 2018 00:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save celoyd/55b8876c02e968c599f8 to your computer and use it in GitHub Desktop.
Save celoyd/55b8876c02e968c599f8 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)
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))
rows = np.empty((frame_count, 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
rows[frame_n] = frame[row]
cv2.imwrite(outf, rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment