Example #1
0
File: video.py Project: urobor/mgr
def markframes(downloaded_videos_dir,marked_frames_directory):
    pause = False    
    state = 0
    for i, file_name in enumerate(os.listdir(downloaded_videos_dir)):
        print(enum_formater.format(i+1,file_name), end="... ")
        cap = cv2.VideoCapture(os.path.join(downloaded_videos_dir,file_name))
        mark_file_path = os.path.join(marked_frames_directory,os.path.splitext(file_name)[0] + ".crlf")
        if os.path.exists(mark_file_path):
            print("EXISTS")
            continue
        frames_in_video = cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)
        f = open(mark_file_path, 'w')
        while(True):
            ret, frame = cap.read()
            if not ret:
                break
            cv2.imshow('frame',frame)
            if pause:
                state, pause = get_key(0, pause, state)
            state, pause = get_key(1, pause, state)
            if state == State.frontbus:
                print("FRONT")
                f.write('F\n')
            elif state == State.background:
                print("BACKGROUND")
                f.write('B\n')
            elif state == State.solaris:
                print("SOLARIS")
                f.write('S\n')
            else:
                f.write('\n')
        f.close()
        lines_in_file = count_lines(mark_file_path);
        # suddenly stopped working ;/
        if(frames_in_video != lines_in_file):
            print("ERROR")
            raise Exception("Wrong frames number, video: " + str(frames_in_video) + " != file:" + str(lines_in_file))