def main(): # img = cv2.imread('s.png') img = screen_grab.grab_screen() while True: hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) l = 3 lower = (l, 0, 0) higher = (4, 255, 255) mask = cv2.inRange(hsv, lower, higher) #(0,0,210), (0,0,255)) mask = cv2.erode(mask, None, iterations=2) mask = cv2.dilate(mask, None, iterations=2) cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2] process(cnts) time.sleep(0.5)
def screen_record(): region = (0,0,1920,1080) batch_size = 100 save_image_on = True address = "dataset\\" loop = 0 data_set = [] while(True): last_time = time.time() img_og = grab_screen( region=region ) width = region[2] - region[0] height = region[3] - region[1] img = cv2.resize( img_og , (int(width/10), int(height/10)) ) #img = img[ 0:58 , 0:192 ]#croped data_set += cal_stuff( img ) if (len(data_set) % batch_size) == 0: if save_image_on: cv2.imwrite(address + "images\\" + str(loop+1) + ".png" ,img) np.save(address + "temps\\"+ "data-set_" + str(loop+1) +".npy", data_set) data_set = [] print("saved!") time_taken = time.time()-last_time print("FPS: " + str(1/time_taken)) loop += 1 if keyboard.is_pressed("space"): print("stoped!") join_files( address , batch_size ) loop = 0 data_set = [] play_sound() pause() return
import cv2 import numpy as np import driving_algorithms import screen_grab import time import process_image from typing import Tuple, List pressed = False last_time = time.time() while True: # store raw pixel data into np array screen = np.array(screen_grab.grab_screen(region=(0, 100, 950, 800))) processed = process_image.process_image(screen) lanes = process_image.lane_lines(processed) if lanes is not None: pressed = driving_algorithms.drive_max_dist(lanes, (950, 800), pressed) # for line in lanes: # cv2.line(processed, (line[0], line[1]), (line[2], line[3]), (255, 0, 0), 5) # cv2.imshow('test', processed) print(f'Loop took {time.time() - last_time} seconds') last_time = time.time() if cv2.waitKey(1) & 0xFF == ord('q'): cv2.destroyAllWindows() break
def get_screen(): img = screen_grab.grab_screen() img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) return img