Beispiel #1
0
def main():
    while True:
        original_img = grab_screen()
        # 1. convert to gray
        image = grayscale(crop(original_img))
        # 2. apply gaussian filter
        image = gaussian_blur(image, 7)
        # 3. canny
        image = canny(image, 50, 100)
        # 4. ROI
        image = region_of_interest(
            image,
            np.array([[(0, 190), (0, 70), (187, 0), (613, 0), (800, 70),
                       (800, 190)]], np.int32))
        # 5. Hough lines
        lines = hough_lines(image)
        # 6. construct lane
        lane, stop_line = construct_lane(lines)
        # 7. Place lane detection output on the original image
        original_img[280:-130, :, :] = draw_lane(original_img[280:-130, :, :],
                                                 lane, stop_line, [0, 255, 0],
                                                 [0, 255, 0])

        cv2.imshow("Frame", original_img)
        key = cv2.waitKey(1) & 0xFF
        if key == ord("q"):
            cv2.destroyAllWindows()
            break
Beispiel #2
0
def main():
    while True:
        screen = grab_screen()
        screen = yolo_detection(screen, 0)

        cv2.imshow("Frame", screen)
        key = cv2.waitKey(1) & 0xFF
        if key == ord("q"):
            cv2.destroyAllWindows()
            break
def main():
    while True:
        screen = grab_screen()
        screen, color_detected, obj_distance = yolo_detection(screen, 0)

        if color_detected:
            print("Color detected: " + color_detected)
        if obj_distance != 1:
            print("Distance to obstacle: {}".format(obj_distance))

        cv2.imshow("Frame", screen)
        key = cv2.waitKey(1) & 0xFF
        if key == ord("q"):
            cv2.destroyAllWindows()
            break
Beispiel #4
0
def main():
    numbers = []
    record = False
    i = 0
    empty = 0

    while True:
        time.sleep(0.2)

        keys = key_check()
        if 'T' in keys:
            record = not record
        elif 'Z' in keys:
            np.save('digits.npy', numbers)

        image = grab_screen("Grand Theft Auto V")

        # speed
        screen, resized, speed, direct = img_process("Grand Theft Auto V")

        vis = image[567:576, 18:28, :]
        print(direct, speed)
        vis = cv2.cvtColor(vis, cv2.COLOR_RGB2GRAY)
        # ret, vis = cv2.threshold(vis, 140, 255, cv2.THRESH_BINARY_INV)
        # ret, vis = cv2.threshold(vis, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
        vis = cv2.adaptiveThreshold(vis, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
                                    cv2.THRESH_BINARY, 7, -5)

        if record:
            i += 1
            print(i)
            numbers.append(vis[:, :5])  # num1
            numbers.append(vis[:, 7:12])  # num2
            if empty % 5 == 0:
                numbers.append(vis[:, -5:])  # num3
            empty += 1

        vis = cv2.resize(vis, None, fx=10, fy=10)
        cv2.imshow("Frame", vis)
        key = cv2.waitKey(1) & 0xFF
        # cv2.waitKey()

        # if the `q` key was pressed, break from the loop
        if key == ord("q"):
            break