예제 #1
0
def main(image="screenshot.png"):
    sg.screengrab(output=image)

    heart, size = [], []
    size = sg.getsize(image)

    nodir = True
    prevrun = False
    while True:
        try:
            start = time.time()
            sg.screengrab(output=image)
            arrow = sg.findarrows(image)
            if not arrow:
                continue
            if nodir and not prevrun:
                heart = sg.findheart(image)
                prevrun = True
            direction = find_direction(*arrow[:2], *heart, size)
            print(direction)
            end = time.time()
            nodir = False
            pyautogui.press(direction)
            print(end - start)
        except ZeroDivisionError:
            prevrun = False
            nodir = True
def main_loop(cv_cap, do_embed):
    cv2.namedWindow("dbg")
    cv2.namedWindow("desktop")
    cv2.namedWindow("cam")

    im_chess = cv2.imread('chess.png')
    im_chess = cv2.cvtColor(im_chess, cv2.COLOR_BGR2GRAY)

    calibrate = True
    sg = screengrab.screengrab()

    while True:
        # Currently screengrab causing issues with OpenCV in linux.
        if (os.name != "posix"):
            s = sg.screen()
            # Transform PIL image to OpenCV Image
            im_screen = cv2.cvtColor(np.asarray(s), cv2.COLOR_RGB2BGR)
            cv2.imshow("desktop", im_screen)
        else:
            cv2.imshow("desktop", im_chess)

        r, im = cv_cap.read()

        # extracts the red color channel.
        im_split = cv2.split(im)[2]
        r, imtresh = cv2.threshold(im_split, 150, 255, cv2.THRESH_BINARY)

        if (calibrate and os.name != "posix"):
            im_harris = cv2.cornerHarris(im_chess, 5, 1, 0.04)
            cv2.imshow("dbg", im_harris)

        cv2.imshow("cam", im)

        # Get key-press event, this is needed for CV events to be processed.
        k = cv2.waitKey(10)

        if (k == 27):
            if do_embed:
                embed()
            break
        elif (k == ord('c')):
            print "Toggling calibration"
            calibrate = not calibrate
예제 #3
0
#! /usr/bin/env python

import screengrab

if __name__ == '__main__':
    sg = screengrab.screengrab()

    s = sg.screen()

    s.show()