def telemetry(sid, data):
    # The current steering angle of the car
    steering_angle = data["steering_angle"]
    # The current throttle of the car
    throttle = data["throttle"]
    # The current speed of the car
    speed = data["speed"]
    speed = float(speed)
    # The current image from the center camera of the car
    imgString = data["image"]
    image = Image.open(BytesIO(base64.b64decode(imgString)))
    image_array = np.asarray(image)

    # Add the preprocessing step
    image_array = preprocess_image(image_array)

    transformed_image_array = image_array[None, :, :, :]
    # This model currently assumes that the features of the model are just the images. Feel free to change this.
    steering_angle = float(model.predict(transformed_image_array,
                                         batch_size=1))

    throttle = 0.1

    print(steering_angle, throttle)
    send_control(steering_angle, throttle)
Exemple #2
0
def telemetry(sid, data):
    if data:
        # The current steering angle of the car
        steering_angle = data["steering_angle"]
        # The current throttle of the car
        throttle = data["throttle"]
        # The current speed of the car
        speed = data["speed"]
        # The current image from the center camera of the car
        imgString = data["image"]
        image = Image.open(BytesIO(base64.b64decode(imgString)))

        image_array = np.asarray(image)

        # Custom Preprocessing
        image_array = preprocess_image(image_array)

        steering_angle = float(
            model.predict(image_array[None, :, :, :], batch_size=1))

        throttle = controller.update(float(speed))

        print(steering_angle, throttle)
        send_control(steering_angle, throttle)

        # save frame
        if args.image_folder != '':
            timestamp = datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S_%f')[:-3]
            image_filename = os.path.join(args.image_folder, timestamp)
            image.save('{}.jpg'.format(image_filename))
    else:
        # NOTE: DON'T EDIT THIS.
        sio.emit('manual', data={}, skip_sid=True)
Exemple #3
0
def telemetry(sid, data):

    # The current steering angle of the car
    steering_angle = data["steering_angle"]
    # The current throttle of the car
    throttle = data["throttle"]
    # The current speed of the car
    speed = data["speed"]
    speed = float(speed)
    # The current image from the center camera of the car
    imgString = data["image"]
    image = Image.open(BytesIO(base64.b64decode(imgString)))
    image_array = np.asarray(image)

    # Add the preprocessing step
    image_array = preprocess_image(image_array)

    transformed_image_array = image_array[None, :, :, :]
    # This model currently assumes that the features of the model are just the images. Feel free to change this.
    steering_angle = float(model.predict(transformed_image_array,
                                         batch_size=1))

    # The driving model currently just outputs a constant throttle. Feel free to edit this.
    # ADD PD control to make the car move at a constant speed.
    TargetSpeed = 5
    Error = (TargetSpeed - speed)
    Difference = Error - PID.preError
    throttle = Error * 0.2 + Difference * 10
    if throttle < 0:
        throttle = 0
    print(steering_angle, throttle, speed, PID.preError)
    send_control(steering_angle, throttle)
    PID.preError = Error
Exemple #4
0
def telemetry(sid, data):
    # The current steering angle of the car
    steering_angle = data["steering_angle"]
    # The current throttle of the car
    throttle = data["throttle"]
    # The current speed of the car
    speed = data["speed"]
    # The current image from the center camera of the car
    imgString = data["image"]
    image = Image.open(BytesIO(base64.b64decode(imgString)))
    image_array = np.asarray(image)

    # Add the preprocessing step to match the process from training
    image_array = preprocess_image(image_array)

    transformed_image_array = image_array[None, :, :, :]

    steering_angle = float(model.predict(transformed_image_array, batch_size=1))

    # Try to maintain speed close to goal speed
    goal_speed = 25.0
    diff = goal_speed - float(speed)
    # Proportional control
    c_p = 0.6
    throttle = max(diff * c_p, 0)


    print(steering_angle, throttle)
    send_control(steering_angle, throttle)
Exemple #5
0
def telemetry(sid, data):

    global current_throttle
    global prev_speed

    # The current steering angle of the car
    steering_angle = data["steering_angle"]
    # The current throttle of the car
    throttle = data["throttle"]
    # The current speed of the car
    speed = data["speed"]
    # The current image from the center camera of the car
    imgString = data["image"]
    image = Image.open(BytesIO(base64.b64decode(imgString)))
    image_array = np.asarray(image)
    image_array = preprocess_image(image_array)

    transformed_image_array = image_array[None, :, :, :]
    # This model currently assumes that the features of the model are just the images. Feel free to change this.
    steering_angle = float(model.predict(transformed_image_array,
                                         batch_size=1))
    print(steering_angle)
    # The driving model currently just outputs a constant throttle. Feel free to edit this.
    speed = float(speed)
    if speed < 15:
        if speed < prev_speed + 0.5:
            current_throttle += 0.03
        else:
            current_throttle = 0.2
    else:
        current_throttle = 0.0

    prev_speed = speed
    print(steering_angle, current_throttle)
    send_control(steering_angle, current_throttle)
Exemple #6
0
def telemetry(sid, data):
    # The current steering angle of the car
    steering_angle = data["steering_angle"]
    # The current throttle of the car
    throttle = data["throttle"]
    # The current speed of the car
    speed = data["speed"]
    speed = float(speed)
    # The current image from the center camera of the car
    imgString = data["image"]
    image = Image.open(BytesIO(base64.b64decode(imgString)))
    image_array = np.asarray(image)

    # Add the preprocessing step
    image_array = preprocess_image(image_array)

    transformed_image_array = image_array[None, :, :, :]
    # This model currently assumes that the features of the model are just the images. Feel free to change this.
    steering_angle = float(model.predict(transformed_image_array, batch_size=1))

    # The driving model currently just outputs a constant throttle. Feel free to edit this.
    throttle = (17.0 - speed)*0.5

    print(steering_angle, throttle)
    send_control(steering_angle, throttle)
    
    # save frame
    if args.image_folder != '':
        timestamp = datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S_%f')[:-3]
        image_filename = os.path.join(args.image_folder, timestamp)
        image.save('{}.jpg'.format(image_filename))
Exemple #7
0
def plot_image_res(data_point):
    image = get_image(data_point)
    image_small = model.preprocess_image(image).astype(np.uint8)

    plt.subplot(1, 2, 1)
    plt.imshow(image)
    plt.axis("off")
    plt.title("original resolution")
    plt.subplot(1, 2, 2)
    plt.imshow(image_small)
    plt.axis("off")
    plt.title("reduced resolution")
    plt.show()
Exemple #8
0
def telemetry(sid, data):
    if data:
        # The current steering angle of the car
        steering_angle = data["steering_angle"]
        # The current throttle of the car
        throttle = data["throttle"]
        # The current speed of the car
        speed = data["speed"]
        speed = float(speed)
        # The current image from the center camera of the car
        imgString = data["image"]
        image = Image.open(BytesIO(base64.b64decode(imgString)))
        image_array = np.asarray(image)

        # Add the preprocessing step
        image_array = preprocess_image(image_array)

        transformed_image_array = image_array[None, :, :, :]
        # This model currently assumes that the features of the model are just the images. Feel free to change this.
        steering_angle = float(
            model.predict(transformed_image_array, batch_size=1))

        # min_speed = 8
        # max_speed = 10
        # if float(speed) < min_speed:
        #     throttle = 1.0
        # elif float(speed) > max_speed:
        #     throttle = -1.0
        # else:
        #     throttle = 0.1

        # Faster
        throttle = (17.0 - speed) * 0.5

        print(steering_angle, throttle)
        send_control(steering_angle, throttle)

        # save frame
        if args.image_folder != '':
            timestamp = datetime.utcnow().strftime('%Y_%m_%d_%H_%M_%S_%f')[:-3]
            image_filename = os.path.join(args.image_folder, timestamp)
            image.save('{}.jpg'.format(image_filename))
    else:
        # NOTE: DON'T EDIT THIS.    <--- BUT I WILL!
        sio.emit('manual', data={}, skip_sid=True)
Exemple #9
0
def preprocess():
    if request.method == 'POST':
        print("preprocess request recieved")
        f = request.get_json(force=True)
        filename = f['filename']
        print(filename)
        for python_filename in os.listdir(registerPath):
            print(python_filename)
            if python_filename == filename:
                print('file found under register directory')
            else:
                print('file missing under register directory')


#File saved to location defined under upload folder
        vector = preprocess_image(os.path.join(registerPath, python_filename))
        print(vector)
        return dumps(vector)
Exemple #10
0
import pandas as pd
import os
from model import (preprocess_image)

dataset = []
for filename in os.listdir('data'):  # loop through all the files and folders
    print(filename)
    if os.path.isdir(os.path.join(
            os.path.abspath("data"),
            filename)):  # check whether the current object is a folder or not
        path = 'data/' + filename
        for img in os.listdir(path):
            feature_vector = preprocess_image(path + '/' + img)
            dataset.append(list(feature_vector) + [filename])

dataset_df = pd.DataFrame(dataset)
dataset_df.to_csv('data/training_data.csv')
def proprocessed_image(image):
    return preprocess_image(image)