Example #1
0
def main():
    # type: () -> int
    ''' PIL example using frombytes(). '''

    try:
        with mss() as sct:
            # We retrieve monitors informations:
            monitors = sct.enum_display_monitors()

            # Get rid of the first, as it represents the "All in One" monitor:
            for num, monitor in enumerate(monitors[1:], 1):
                # Get raw pixels from the screen.
                # This method will store screen size into `width` and `height`
                # and raw pixels into `image`.
                sct.get_pixels(monitor)

                # Create an Image:
                size = (sct.width, sct.height)
                img = Image.frombytes('RGB', size, sct.image)

                # And save it!
                output = 'monitor-{0}.png'.format(num)
                img.save(output)
                print(output)

            return 0
    except ScreenshotError as ex:
        print(ex)

    return 1
Example #2
0
def main():
    # type: () -> int
    ''' Usage example. '''

    def on_exists(fname):
        # type: (str) -> None
        ''' Callback example when we try to overwrite an existing
            screenshot.
        '''

        if isfile(fname):
            newfile = fname + '.old'
            print('{0} -> {1}'.format(fname, newfile))
            rename(fname, newfile)

    try:
        with mss() as sct:
            # For MacOS X only
            # sct.max_displays = 32

            print('One screenshot per monitor')
            for filename in sct.save():
                print(filename)

            print("\nScreenshot of the monitor 1")
            print(next(sct.save(mon=1, output='monitor-%d.png')))

            print("\nA screenshot to grab them all")
            print(next(sct.save(mon=-1, output='fullscreen.png')))

            print("\nScreenshot of the monitor 1, with callback")
            print(next(sct.save(mon=1, output='mon-%d.png',
                                callback=on_exists)))

            return 0
    except ScreenshotError as ex:
        print(ex)

    return 1
Example #3
0
finger_to_regression_label(pinky_data, 4)

##test display image
#image = Image.fromarray(images[0].reshape(shape))
#image.show()

## Create a classifier: a support vector regressor
ring = svm.SVR(gamma=0.00006)
ring.fit(ring_images, ring_data)

pinky = svm.SVR(gamma=0.00006)
pinky.fit(pinky_images, pinky_data)

## run the model
while True:
    sct = mss()
    #times 2 on dimensions because retina bs
    input_image = screenshot(340 * 2, 80 * 2, 940 * 2, 820 * 2,
                             sct)  #bounds to be screenshot x1, y1, x2, y2
    input_image = block_reduce(input_image, block_size=(2, 2),
                               func=np.median)  # because retina crap
    input_image = prepare([input_image])

    ring_prediction = ring.predict(input_image)
    pinky_prediction = pinky.predict(input_image)
    print(pinky_prediction)

    ## udp
    msg = str('0' + " " + '0' + " " + '0' + " " + str(ring_prediction[0]) +
              " " + str(pinky_prediction[0]))
    sock.sendto(bytearray(msg, 'utf8'), (UDP_IP, SENDER_UDP_PORT))