ラスベガスパイメインコード

1877 ワード

import cv2
import numpy as np

from carCtroller import CarController
from carCtroller import MOTOR_FORWARD, MOTOR_REVERSE

ctr = CarController()

capture = cv2.VideoCapture(-1)
capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

fourcc = cv2.VideoWriter_fourcc(*'X264')
vdwriter =cv2.VideoWriter('./cosmos_load.mp4', fourcc, 30, (640, 480))

font = cv2.FONT_HERSHEY_SIMPLEX

speed = 160

while True:
    key = cv2.waitKey(10)
    # print(key)
    
    ret, frame = capture.read()
    if ret:
        frame = cv2.flip(frame, -1) 
        # print(frame.shape)
        cv2.putText(frame, str(ctr.wheel_direction), (10,450), font, 1, (0, 255, 0), 2, cv2.LINE_AA)
        cv2.imshow('test', frame)
        vdwriter.write(frame)
        
        if key == 119:      # w
            ctr.set_motor_velocity(MOTOR_FORWARD, speed)
        elif key == 115:    # s
            ctr.set_motor_stop(MOTOR_FORWARD, 0)
        elif key == 120:    # x
            ctr.set_motor_velocity(MOTOR_REVERSE, speed)
        elif key == 100:    # d
            ctr.set_wheel_direction(10)
        elif key == 97:     # a
            ctr.set_wheel_direction(-10)
        elif key == 98:     # b
            ctr.play_buzzer()
        elif key == 105:    # i
            ctr.set_camera_tilt(-10)
        elif key == 44:     # <
            ctr.set_camera_tilt(10)
        elif key == 106:    # j
            ctr.set_camera_pan(10)
        elif key == 108:    # l
            ctr.set_camera_pan(-10)
        elif key == 101:
            speed += 5
        elif key == 113:
            speed -= 5
        elif key == -1:
            #ctr.set_motor_velocity(MOTOR_FORWARD, 0)
            pass
        
    if key == 27:
        break
    
capture.release()
vdwriter.release()
cv2.destroyAllWindows()