Skip to content

Instantly share code, notes, and snippets.

@celoyd
Last active March 21, 2018 00:45

Revisions

  1. celoyd revised this gist Mar 19, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions sscan.py
    Original file line number Diff line number Diff line change
    @@ -17,14 +17,14 @@
    row = int(row)

    viddy = cv2.VideoCapture(movf)
    width = viddy.get(3) # can you tell this API is by C programmers?
    height = viddy.get(4)
    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
    print("%s/%s" % (frame_n, frame_count)) # or not
    okay, frame = viddy.read()
    if not okay: break
    rows[frame_n] = frame[row]
  2. celoyd revised this gist Jun 15, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions sscan.py
    Original file line number Diff line number Diff line change
    @@ -19,12 +19,12 @@
    viddy = cv2.VideoCapture(movf)
    width = viddy.get(3) # can you tell this API is by C programmers?
    height = viddy.get(4)
    frame_count = viddy.get(7)
    frame_count = int(viddy.get(7))

    rows = np.empty((frame_count, width, 3)) # 3 channels

    for frame_n in range(int(frame_count)):
    print frame_n
    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]
  3. celoyd revised this gist Jun 15, 2014. 2 changed files with 32 additions and 22 deletions.
    22 changes: 0 additions & 22 deletions slit.py
    Original file line number Diff line number Diff line change
    @@ -1,22 +0,0 @@
    # draft
    # - factor out constants (including output filename)
    # - find more efficient way of appending ndarrays

    import numpy as np
    import cv2
    from sys import argv

    v = cv2.VideoCapture(argv[1])
    rows = np.zeros((1, 1920, 3))
    n = 0
    while n < 8000:
    # try:
    _, frame = v.read()
    print n
    #print frame[0].shape
    rows = np.vstack((rows, np.reshape(frame[655], (1, 1920, 3)) ))
    n += 1
    # except:
    # break

    cv2.imwrite('dingo.png', rows)
    32 changes: 32 additions & 0 deletions sscan.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/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 = viddy.get(3) # can you tell this API is by C programmers?
    height = viddy.get(4)
    frame_count = viddy.get(7)

    rows = np.empty((frame_count, width, 3)) # 3 channels

    for frame_n in range(int(frame_count)):
    print frame_n
    okay, frame = viddy.read()
    if not okay: break
    rows[frame_n] = frame[row]

    cv2.imwrite(outf, rows)
  4. celoyd revised this gist Jun 12, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion slit.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    # draft; needs to have constants factored out
    # draft
    # - factor out constants (including output filename)
    # - find more efficient way of appending ndarrays

    import numpy as np
    import cv2
  5. celoyd created this gist Jun 12, 2014.
    20 changes: 20 additions & 0 deletions slit.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # draft; needs to have constants factored out

    import numpy as np
    import cv2
    from sys import argv

    v = cv2.VideoCapture(argv[1])
    rows = np.zeros((1, 1920, 3))
    n = 0
    while n < 8000:
    # try:
    _, frame = v.read()
    print n
    #print frame[0].shape
    rows = np.vstack((rows, np.reshape(frame[655], (1, 1920, 3)) ))
    n += 1
    # except:
    # break

    cv2.imwrite('dingo.png', rows)