import cv2 import numpy as np from tensorflow.keras.models import load_model import WebcamModule as wM import MotorModule as mM ####################################### steeringSen = 0.70 # Steering Sensitivity maxThrottle = 0.22 # Forward Speed % motor = mM.Motor(2, 3, 4, 17, 22, 27) # Pin Numbers model = load_model('/home/pi/Desktop/My Files/RpiRobot/model_V1.h5') ###################################### def preProcess(img): img = img[54:120, :, :] img = cv2.cvtColor(img, cv2.COLOR_RGB2YUV) img = cv2.GaussianBlur(img, (3, 3), 0) img = cv2.resize(img, (200, 66)) img = img / 255 return img while True: img = wM.getImg(True, size=[240, 120]) img = np.asarray(img) img = preProcess(img) img = np.array([img]) steering = float(model.predict(img))
import WebcamModule as wM import DataCollectionModule as dcM import JoyStickModule as jsM import MotorModule as mM import cv2 from time import sleep maxThrottle = 0.25 motor = mM.Motor(2, 3, 4, 17, 22, 27) record = 0 while True: joyVal = jsM.getJS() #print(joyVal) steering = joyVal['axis1'] throttle = joyVal['o']*maxThrottle if joyVal['share'] == 1: if record ==0: print('Recording Started ...') record +=1 sleep(0.300) if record == 1: img = wM.getImg(True,size=[240,120]) dcM.saveData(img,steering) elif record == 2: dcM.saveLog() record = 0 motor.move(throttle,-steering) cv2.waitKey(1)
import cv2 import os import numpy as np import CameraModule as cm import MotorModule as mt from TfLiteInterpreter import Interpreter #### Configuration #################################### steering_sensitivity = 1.9 max_throttle = 0.35 motor = mt.Motor(18, 11, 13, 15, 16, 22) tflite_modelpath = 'model_v1.tflite' ####################################################### def preprocess(img): img = img[174:,:,:] img = cv2.cvtColor(img, cv2.COLOR_BGR2YUV) img = cv2.GaussianBlur(img, (3,3), 0) img = cv2.resize(img, (200, 66)) img = img / 255 return img try: interpreter = Interpreter(tflite_modelpath) while True: img = cm.get_img(False, size=[480,240]) img = preprocess(img) img = np.array([img], dtype=np.float32)