Example #1
0
def video_record(video):
    meta = MetaData.from_video(video)
    cap = cv2.VideoCapture(video)
    arrow = Arrow(meta.width)
    cpt_frame = 0
    while cap.isOpened():
        ret, frame = cap.read()
        cpt_frame += 1
        if ret:
            try:
                processed_img = process_img(frame, meta)
                lines = find_lines(processed_img)
                l1, l2 = separate_lines(lines)
                p = intersect_droit(l1, l2)
                arrow.add_point(int(p.x))

                processed_img = cv2.cvtColor(processed_img, cv2.COLOR_GRAY2BGR)

                cv2.imshow('window', processed_img)
                draw_infos(frame, p, l1, l2)
                draw_arrow(frame, arrow, meta.width)
                cv2.imshow('window', frame)

            except:
                pass
        # draw_arrow(frame, arrow, meta.width)

        # cv2.imshow('window', frame)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()
Example #2
0
def screen_record():
    x, y, w, h = 0, 50, 1024, 768
    meta = MetaData.from_screen(w - x, h - y)
    arrow = Arrow(meta.width)
    last_time = 0
    with mss() as sct:
        # Part of the screen to capture
        monitor = {"top": y, "left": x, "width": w, "height": h}
        while True:
            frame = numpy.array(sct.grab(monitor))
            try:
                processed_img = process_img(frame, meta)
                lines = find_lines(processed_img)
                p = separate_lines(lines)
                cv2.circle(frame, (int(p.x), int(p.y)), 2, [0, 255, 255], 10)
                arrow.add_point(int(p.x))
            except:
                pass

            draw_arrow(frame, arrow, meta.width)
            cv2.imshow("OpenCV/Numpy normal", frame)

            fps = "fps: {}".format(1 / (time.time() - last_time))
            last_time = time.time()
            print(fps)

            # Press "q" to quit
            if cv2.waitKey(50) & 0xFF == ord("q"):
                cv2.destroyAllWindows()
                break