Last active
March 21, 2018 00:45
-
-
Save celoyd/55b8876c02e968c599f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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