<commit_before>import numpy as np
import cv2

# open video TODO:loop through all videos in folder
cap = cv2.VideoCapture('videos-input/F000G26.mp4')

# read the first video frame
ret, frame1 = cap.read()

# set up the output video file
height, width, layers = frame1.shape
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('videos-output/F000G26-output.avi',fourcc, 20.0, (width,height))

prvs = cv2.cvtColor(frame1,cv2.COLOR_BGR2GRAY)
hsv = np.zeros_like(frame1)
hsv[...,1] = 255

while(1):
    ret, frame2 = cap.read()
    next = cv2.cvtColor(frame2,cv2.COLOR_BGR2GRAY)

    flow = cv2.calcOpticalFlowFarneback(prvs,next, None, 0.5, 3, 15, 3, 5, 1.2, 0)

    mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1])
    hsv[...,0] = ang*180/np.pi/2
    hsv[...,2] = cv2.normalize(mag,None,0,255,cv2.NORM_MINMAX)
    rgb = cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR)

    cv2.imshow('frame2',rgb)
    
    out.write(rgb)

    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break
    elif k == ord('s'):
        pass
        # cv2.imwrite('opticalfb.png',frame2)
        # cv2.imwrite('opticalhsv.png',rgb)
    prvs = next


cap.release()
out.release()
cv2.destroyAllWindows()<commit_msg>iterating through all input videos and outputting optical flow avi files works<commit_after>import os
import numpy as np
import cv2
for input_video in os.listdir('videos-input'):
    print 'processing ' + input_video
    cap = cv2.VideoCapture('videos-input/' + input_video)
    # read the first video frame
    ret, frame1 = cap.read()
    # set up the output video file
    height, width, layers = frame1.shape
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    out = cv2.VideoWriter('videos-output/' + input_video.replace('mp4', 'avi'),
                           fourcc,
                           20.0,
                           (width,height))
    prvs = cv2.cvtColor(frame1,cv2.COLOR_BGR2GRAY)
    hsv = np.zeros_like(frame1)
    hsv[...,1] = 255
    while(1):
        ret, frame2 = cap.read()
        try:
            next = cv2.cvtColor(frame2,cv2.COLOR_BGR2GRAY)
        except:
            break
        flow = cv2.calcOpticalFlowFarneback(prvs,next, None, 0.5, 3, 15, 3, 5, 1.2, 0)
        mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1])
        hsv[...,0] = ang*180/np.pi/2
        hsv[...,2] = cv2.normalize(mag,None,0,255,cv2.NORM_MINMAX)
        rgb = cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR)
        out.write(rgb)
        k = cv2.waitKey(30) & 0xff
        if k == 27:
            break
        prvs = next
    cap.release()
    out.release()
{'fraction_non_alphanumeric': 0.1469435736677116, 'fraction_numerical': 0.05329153605015674, 'mean_word_length': 2.5606694560669454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '25757', 'n_tokens_mistral': 1034, 'n_tokens_neox': 968, 'n_words': 194}