def main(): scale = 16000.0 # Vjoy stuff. vj.open() while (True): #speed = Get_Speed(clf) # Get current speed. , # I'll leave the speed cap deactivated as a default #Cap_Speed(speed) # Make sure we aren't going too fast. , # I'll leave the speed cap deactivated as a default screen = grab_screen(region=ROI) #Screenshot part of window. screen = np.array(screen) #Make screenshot into array. screen = cv2.resize(screen, (120, 60)) #Resize to a 120x60 pic. pic_array = screen.reshape(60, 120, 3) prediction = model.predict({'input_pic': [pic_array]})[0] steer = (prediction[2] - prediction[0])**3 setJoy(steer + 0.024, 0, scale) # +0.024 Helps fix joystick offset. vj.close()
def main(): print("vJoy Opening") vj.open() time.sleep(0.5) # place_waypoints() print("Scanning Memory") scanner = HeapScanner(0x034B0000) wp1d_addr = scanner.scan_memory("2.1 m") wp1a_addr = scanner.scan_memory("-54.91") wp2a_addr = scanner.scan_memory("+99.91") print('Creating pipelines') # GRIP generated pipelines for cones and mobile goals cone_pipeline = ConePipeline() rmg_pipeline = RedMobileGoalPipeline() bmg_pipeline = BlueMobileGoalPipeline() print('Running pipeline') last_time = time.time() while True: have_frame, frame = grab_screen() if have_frame: # GRIP frame processing cone_pipeline.process(frame) rmg_pipeline.process(frame) bmg_pipeline.process(frame) # Final processing (coloring, etc.) images = [ frame, extra_processing_cones(cone_pipeline), extra_processing_red_mobile_goals(rmg_pipeline), extra_processing_blue_mobile_goals(bmg_pipeline), blank_image.copy() ] for i in range(len(images)): images[i] = cv2.resize(images[i], None, fx=0.6, fy=0.6, interpolation=cv2.INTER_AREA) r = num_from_distance_string(scanner.read_memory(wp1d_addr, 6)) theta = num_from_angle_string(scanner.read_memory(wp2a_addr, 6)) wp1_t = num_from_angle_string(scanner.read_memory(wp1a_addr, 6)) if r is not None and theta is not None and wp1_t is not None: theta = radians(theta) x = r * fabs(mp.cos(theta)) y = x * mp.tan(theta) # To write to joystick call set_joy # set_joy(xval, yval) # Show all filters in 4x4 grid cv2.imshow( 'Filters', np.hstack([ np.vstack([np.hstack(images[0:2]), np.hstack(images[2:4])]), np.vstack([images[4], blank_image_scaled]) ])) if cv2.waitKey(10) == 27: print('Capture closed') cv2.destroyAllWindows() cleanup_gui_helper() vj.close() return else: print("fps: ", int(1 / (time.time() - last_time))) last_time = time.time()
rows = [] rowtotal = 0 for i in range(height): for j in range(width): rowtotal += thresholded[i][j] rows.append(rowtotal / width) rowtotal = 0 #most white row middlecol = False for i in range(height): if thresholded[i][width // 2] == 255: middlecol = True break if middlecol: heightcalib = rows.index(max(rows)) calibrateflag = True print("Calibrated!") print("Press 'q' to quit.") else: print("Error: make sure you hand is centered in frame.") setJoy(xPos, yPos, scale) # free up memory camera.release() cv2.destroyAllWindows() # calling this function requests that the background listener stop listening #stop_listening(wait_for_stop=False) setJoy(0, 0, scale) vj.close()