def __init__(self):
        ## Read setting infomation file
        self.config = configparser.ConfigParser()
        self.config.read('./connection.ini', 'UTF-8')
        # Settig for server
        self.SERVER_IP = self.config.get('server', 'ip')
        self.SERVER_PORT = int(self.config.get('server', 'port'))
        # Setting for streaming condition
        self.IMG_FPS = int(self.config.get('packet', 'image_fps'))
        self.HEADER_SIZE = int(self.config.get('bytes', 'header_size'))
        self.IMAGE_WIDTH = int(self.config.get('pixels', 'image_width'))
        self.IMAGE_HEIGHT = int(self.config.get('pixels', 'image_height'))
        self.IMAGE_QUALITY = int(self.config.get('pixels', 'image_quality'))
        self.PHOTO_IMG_X = int(self.config.get('pixels', 'photo_image_x'))
        self.PHOTO_IMG_Y = int(self.config.get('pixels', 'photo_image_y'))
        self.PHOTO_IMG_W = int(self.config.get('pixels', 'photo_image_w'))
        self.PHOTO_IMG_H = int(self.config.get('pixels', 'photo_image_h'))
        # Setting for debug string
        self.INDENT = '    '

        ## For control FPS
        self.start_time = time.perf_counter()
        self.fps = 0.0
        self.delay_time = 0.0

        ## For D3Dshot module
        self.d = d3dshot.create(capture_output="numpy")
        x = 0
        y = 0
        width = self.IMAGE_WIDTH
        height = self.IMAGE_HEIGHT
        self.d.capture(region=(x, y, x + width, y + height))
Exemple #2
0
    def test_take_img_during_10_seconds(self):
        import time
        import d3dshot
        import os
        from datetime import datetime, timezone

        d = d3dshot.create()
        start = time.time()
        end = 0
        i = 0
        print("hello")
        # without current date 180 imgs => 18 img/s
        """while end - start < 10: 
            name = "gross_"+str(i)
            d.screenshot_to_disk(directory=os.path.join("Speedtest", "CourtTermMemory"), file_name=name + ".jpg")
            end = time.time()
            i += 1
        """
        # with current date and deleting on the directory 169 imgs => 16.9 imgs/s
        # with current date on the directory 183 imgs => 18 imgs/s
        while end - start < 10:
            d.screenshot_to_disk(
                directory=os.path.join("Speedtest", "CourtTermMemory"),
                file_name=datetime.today().strftime("%Y%m%d%H%M%S%f") + ".jpg")
            end = time.time()
            i += 1
Exemple #3
0
    def __init__(self, playing_as, text_background_color):
        self.playing_as = playing_as
        self.text_background_color = text_background_color
        self.phase_duration = PHASE_DURATIONS[playing_as]
        self.rotation = ROTATIONS[playing_as]
        self.rotation_size = len(self.rotation)
        self.rotation_millis = self.rotation_size * 4000
        self.update_every = 5 # frames
        self.timer = self.update_every
        self.time_left = 0
        self.phase = self.rotation[0]
        self.next_phase = self.rotation[1]
        self.rotation_start_ticks = 0
        self.tick = 0
        self.show = False

        screenshoter = d3dshot.create(capture_output="numpy")
        screenshoter.display = screenshoter.displays[0]
        width, height = screenshoter.display.resolution
        self.screenshoter = screenshoter
        self.screenshoter_region = round(width*33/96), round(height*5/6), round(width*63/96), round(height*32/36)
        self.templates = self.get_buff_templates()

        self.recognition_thread = StoppableThread(target=self.recognise_loop)
        self.recognition_thread.start()
Exemple #4
0
    def __init__(self, freq, ouput_dir_path):
        self.output_path = ouput_dir_path
        self.freq = freq
        self.tracked_keys = TRACKED_KEYS
        self.screenshoter = d3dshot.create()

        self.udp_socket = socket.socket(family=socket.AF_INET,
                                        type=socket.SOCK_DGRAM)
        self.udp_socket.bind(('', 20777))
Exemple #5
0
class WindowServer:
    """
    Records the game window, and allows to create instance to process it
    """
    Screen = None
    windowOffset = None
    hwnd = None
    status = Status.STOPPED
    d3: d3dshot.D3DShot = d3dshot.create(capture_output="numpy")
    monitor_top_left = None
Exemple #6
0
def setup_d3dshot(display_id=0, fps=30, region=None):
    # Captures will be np.ndarray of dtype uint8 with values in range (0, 255)
    dshot = d3dshot.create(capture_output="numpy")
    dshot.display = dshot.displays[display_id]
    # start 'high-speed' capture
    # note: we do this to decouple capture of the screen from the ROS event
    # and processing loop. Captures will be read from the d3dshot queue
    if not dshot.capture(target_fps=fps, region=region):
        raise ValueError(f"Failed to start d3dshot capture (unknown reason)")
    return dshot
Exemple #7
0
 def __init__(self, display):
     self.__d = d3dshot.create(capture_output="numpy")
     self.__d.displays[display]
     self.__dx = 999999
     self.__dy = 999999
     self.__speed = 0
     self.__dt = 999999
     self.__ableToMeasure = False
     self.__stopwatch = None
     self.__dino = None
     self.__initCaptureScreen()
def create(capture_output="numpy",
           frame_buffer_size=60,
           display=1,
           top: int = 40,
           left: int = 0,
           width: int = 560,
           height: int = 1000):
    global d
    d = d3dshot.create(capture_output, frame_buffer_size)
    d.display = d.displays[display]
    d.capture(region=(left, top, left + width, top + height))
Exemple #9
0
def run():
    d = d3dshot.create(capture_output="numpy_float")
    d.capture(region=(0, 0, 1920, 1080))
    s = Aura(ip, port, length, brightness, offset)
    s.send()
    time.sleep(1)
    while 1:
        # last_time = time.time()
        s.set(image_to_signal(down_up_sample(d.get_latest_frame(), scale)))
        s.send()
        time.sleep(1 / fps)
Exemple #10
0
def vidCap():
    d = d3dshot.create(capture_output="numpy", frame_buffer_size=900)
    print("Initiating Buffer")
    d.capture(target_fps=30)
    while True:
        if (keyboard.is_pressed(PyLightSettings.recordButton)):
            d.stop()
            vidMake(d.frame_buffer)
            break
        if (keyboard.is_pressed(PyLightSettings.exitButton)):
            break
    def __init__(self):
        # Init frame grabber
        self.f = d3dshot.create(frame_buffer_size=150, capture_output="numpy")
        print("Found primary display. Resolution: {} x {}".format(
            self.f.display.resolution[0], self.f.display.resolution[1]))

        # Calc scale factor and offset for image resize
        self.factor = self.f.display.resolution[0] // TARGET_INPUT_WIDTH
        self.offset = self.factor // 2

        self.f.capture(target_fps=60)
        time.sleep(1)  # Pause for init time
class Server:
    d = d3dshot.create()

    def __init__(self, ip, port):
        self.ip = ip
        self.port = port

    async def main(self, websocket, path):
        await SendReceive(websocket, self.d).run()

    def start_server(self):
        start_server = websockets.serve(self.main, self.ip, self.port)
        loop = asyncio.get_event_loop()
        loop.run_until_complete(start_server)
        loop.run_forever()
Exemple #13
0
def waitForColours():
    d = d3dshot.create(capture_output="pil")
    win = getMcWin()
    rect = win.rect
    if rect != (0, 0, 1920, 1080):
        rect = (rect[0] + 8, rect[1] + 24, rect[2] - 16, rect[3] - 32)
    rect = (rect[0] + 50, rect[1] + 200, rect[0] + 52, rect[1] + 202)
    root.update()
    img = d.screenshot(region=rect)
    color = img.getpixel((1, 1))
    startTime = time.time()
    while (time.time() - startTime) < 1.5 and not (
            color[0] > 13 and color[0 < 18] and color[1] > 9 and color[1] < 15
            and color[2] > 5 and color[2] < 10):
        img = d.screenshot(region=rect)
        color = img.getpixel((1, 1))
        time.sleep(0.02)
Exemple #14
0
def init_screen(capture_output="pytorch_float_gpu"):
    capturer = d3dshot.create(capture_output=capture_output,
                              frame_buffer_size=10)
    print('Game Region capture size:')
    print(get_game_screen(capturer, skip_pixels=1).shape)
    print(get_game_screen(capturer, skip_pixels=4).shape)
    time.sleep(0.1)
    print('Mania Region capture size:')
    print(
        str(MANIA_REGION[2] - MANIA_REGION[0]) + ' x ' +
        str(MANIA_REGION[3] - MANIA_REGION[1]))
    print(
        str((MANIA_REGION[2] - MANIA_REGION[0]) // 4) + ' x ' +
        str((MANIA_REGION[3] - MANIA_REGION[1]) // 4))
    print('Taiko Region capture size:')
    print(
        str(TAIKO_REGION[2] - TAIKO_REGION[0]) + ' x ' +
        str(TAIKO_REGION[3] - TAIKO_REGION[1]))
    return capturer
Exemple #15
0
def main(host='0.0.0.0', port=5000):
    #thread = Thread(target=capture_screen)
    #thread.start()
    # d = d3dshot.create(capture_output="numpy", frame_buffer_size=100)
    d = d3dshot.create(capture_output="pil", frame_buffer_size=100)
    #sock = socket()
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind((host, port))
    try:
        sock.listen(5)
        print('Server started.')
        d.capture()
        while 'connected':
            conn, addr = sock.accept()
            print('Client connected IP:', addr)
            #thread = Thread(target=retreive_screenshot, args=(conn,))
            thread = Thread(target=capture_screen, args=(conn, d))
            thread.start()
    finally:
        sock.close()
        d.stop()
Exemple #16
0
    def test_take_img_during_one_hour(self):
        """
        Save one hour images
        """
        import time
        import d3dshot
        import os
        from datetime import datetime

        d = d3dshot.create()
        start = time.time()
        end = 0
        i = 0
        print("hello")
        # TODO How many images has been created ?
        while end - start < 3600:
            d.screenshot_to_disk(
                directory=os.path.join("Speedtest", "OneHour"),
                file_name=datetime.today().strftime("%Y%m%d%H%M%S%f") + ".jpg")
            end = time.time()
            i += 1
Exemple #17
0
    def __init__(self,
                 obs_scale,
                 is_obs_color=True,
                 reward_score=True,
                 num_running_reward=3):
        super().__init__()
        self.reward_score = reward_score
        self.num_running_reward = num_running_reward

        fn_hwnd = win32gui.FindWindow(None, 'Fruit Ninja')
        if fn_hwnd == 0:
            raise ValueError("Fruit Ninja window not detected!")
        self.win_coords = win32gui.GetWindowRect(fn_hwnd)

        # Add offest to not capture window controls
        self.win_coords = list(self.win_coords)
        self.win_coords[0] += 15
        self.win_coords[1] += 35
        self.win_coords[2] -= 35
        self.win_coords[3] -= 35
        self.win_coords = tuple(self.win_coords)

        self.d3d_buff = d3dshot.create(capture_output='numpy')

        self.is_obs_color = is_obs_color
        self._calculate_obs_size(obs_scale)
        self.observation_space = gym.spaces.Box(low=0,
                                                high=255,
                                                shape=(self.obs_size[1],
                                                       self.obs_size[0],
                                                       self.obs_size[2]),
                                                dtype=np.uint8)
        self.action_space = gym.spaces.Box(low=np.array([-1.0, -1.0]),
                                           high=np.array([1.0, 1.0]),
                                           dtype=np.float32)

        self.passoff_time = time.time()
        self.running_reward = []
Exemple #18
0
    def __init__(self, model_name, Dataset, region=(0, 200+33, 800, 450+33), tbbox=(705, 420, 775, 460), dos_save="", use_joystick=True, input_components=[]):
        # init Dataset and model
        self.Dataset = Dataset
        self.model = architectures.load_model(model_name, compile=False)
        architectures.apply_predict_decorator(self.model)
        self.input_components = input_components

        # init udp connection to fh4
        self.speedDetector = UDP_receiver()
        self.speed = 0

        # init recording
        self.region = region

        self.d = d3dshot.create(capture_output="numpy", frame_buffer_size=5)
        self.d.display = self.d.displays[0]
        self.d.capture()

        self.frame = np.zeros((10, 10, 3), dtype=np.float32)
        self.speed_frame = np.zeros((10, 10, 3), dtype=np.float32)

        # init virtual controller
        self.controller = controller(joystick=use_joystick)

        # init recording folder
        if dos_save != "":
            self.dos_save = dos_save
        else:
            self.dos_save = os.getcwd()+"\\recorded\\"
        if not os.path.isdir(self.dos_save):
            os.mkdir(self.dos_save)

        self.running = True
        self.annotations = {
            'direction': 0,
            'speed': 0,
            'throttle': 0,
        }
Exemple #19
0
    def __init__(self, num_screen=2, img_size=640):
        self.mode = 'images'
        self.img_size = img_size
        self.num_screen = num_screen
        self.cap = d3dshot.create(capture_output="numpy")
        self.fps_capture = 0
        self.sources = 'screen_capture'
        self.cap.display = self.cap.displays[
            self.num_screen -
            1]  # the counting method is different for d3dshot
        self.image_cap = self.cap.screenshot()  # guarantee first frame
        self.timer = cv2.getTickCount()
        thread = Thread(target=self.update, args=([self.cap]), daemon=True)
        sz = self.image_cap.shape
        print(' success recording screen:', self.num_screen, '(', sz[0], ',',
              sz[1], ') of', self.cap.display)

        if sz[1] > 1920 or sz[0] > 1080:
            print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
            print(
                "!!!!!!!WARNING! Consider reduce screen resolution below 1920*1080 to increase framerate in capture."
            )
            print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
        thread.start()
Exemple #20
0
 def loop26():
     import d3dshot
     import os
     d = d3dshot.create()
     for i in range(26):
         name = "gross_" + str(i)
         print(name)
         # TODO find the best way
         # first way 9.029s => 2 img/s as a jpg 2.467s => 10 img/s
         #cs = saie.get_current_screen(name+".jpg")
         #saie.save_image_court_term_memory(cs, name + ".jpg")
         # second way 5.343s => 4 img/s as a jpg 2.68s => 10 img/s
         #import pyscreeze
         #pyscreeze._screenshot_win32(name+".png")
         # third way 4.658s => 5 img/s
         #with mss() as sct:
         #    print(sct.shot())
         # rename monitor-1.png to name+".png"import os
         #    os.replace('monitor-1.png', name+".png")
         #sct.save()
         # fourth way 4.909 => 5 img/s as a jpg 15 img/s
         d.screenshot_to_disk(directory=os.path.join(
             "Speedtest", "CourtTermMemory"),
                              file_name=name + ".jpg")
Exemple #21
0
logger = logging.getLogger('collector')

logging.basicConfig(
    level=logging.INFO,
    format='[%(processName)s|%(threadName)s] %(asctime)s %(name)s:%(levelname)s: %(message)s'
)

PORT = 21337

# TODO: refactor into state
START_ID = str(uuid.uuid4())
GAME_ID = START_ID
GAME_STATE = None
STARTED_AT = None

screenshot_producer = d3dshot.create()


def every(delay, task):
    next_time = time.time() + delay
    while True:
        time.sleep(max(0, next_time - time.time()))
        try:
            task()
        except Exception:
            traceback.print_exc()  # TODO: better error handling

        next_time += (time.time() - next_time) // delay * delay + delay


def poll_lor_api():
Exemple #22
0
import d3dshot, cv2
import numpy as np
import time
d = d3dshot.create(capture_output="numpy")
while True:

    lasttime = time.time()

    aaa = cv2.cvtColor(d.screenshot()[0:255, 0:255], cv2.COLOR_BGR2RGB)
    cv2.imshow('a', aaa)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

    print("took {} with fps : {}".format(
        time.time() - lasttime, 1 / (time.time() - lasttime + 0.000001)))
Exemple #23
0
def Launcher():
    def print(line):
        window['output'].update(line)

    sg.theme('black')

    sg.set_options(element_padding=(1, 1),
                   button_element_size=(10, 1),
                   auto_size_buttons=False)

    col1 = [
        [sg.Text('Save Options', font='Calibri 8')],
        [
            sg.Text(' '),
            sg.Text('Filename: ', text_color='blue'),
            sg.Input(size=(12, 1), key='-vFilename-')
        ],
        [
            sg.Text(' ' * 5),
            sg.Text('Folder: ', text_color='blue'),
            sg.Input(size=(12, 1), key='-vFolder-'),
            sg.FolderBrowse(button_color=('white', 'black'),
                            font='Calibri 10',
                            size=(7, 1))
        ],
        [
            sg.Text(' ',
                    size=(30, 1),
                    font='Calibri 8',
                    text_color='red',
                    key='output')
        ],
    ]

    layout = [
        [
            sg.Text('QuickSnip', text_color='blue', font='Forte 14'),
            sg.Text(' ' * 60),
            sg.Button('x', size=(4, 1), button_color=('white', '#fc0303'))
        ],
        [
            sg.Column(col1),
            sg.Text(' ' * 5),
            sg.Button(image_filename='cam5_100x96.png',
                      image_size=(100, 90),
                      border_width=(0),
                      key='snip')
        ],
    ]

    window = sg.Window('QuickSnip',
                       layout,
                       no_titlebar=True,
                       grab_anywhere=True,
                       keep_on_top=True,
                       resizable=True)

    while True:
        event, values = window.read()
        if event == 'x' or event is None:
            break
        if event == 'snip':
            try:
                print('Saving screenshot...please wait')
                window.Refresh()
                d = d3dshot.create()
                vF = values['-vFilename-']
                vP = values['-vFolder-']
                d.screenshot_to_disk(directory=vP, file_name=str(vF + '.png'))
                print(' ')
            except:
                print('ERROR: Enter filename and folder path')
                window.Refresh()
                window.read(timeout=5000)
                print(' ')
Exemple #24
0
def launch_acquisition_image(dict_images):
    d = d3dshot.create(capture_output="numpy")
    d.display = d.displays[monitor]
    while True:
        im = d.screenshot()
        dict_images[str(timestamp())] = im
Exemple #25
0
 def __init__(self, threadID, name):
     threading.Thread.__init__(self)
     self.threadID = threadID
     self.name = name
     self.image = None
     self.d = d3dshot.create(capture_output="numpy", frame_buffer_size=1)
 def __init__(self):
     self.d = d3dshot.create(capture_output='numpy', frame_buffer_size=180)
Exemple #27
0
 def __init__(self):
     print('creating Screenshoter instance...')
     # the frame_buffer_size is set to 3 to ensure thath the
     # screenshot returned by the method screenshot_from_second_ago
     # is at least a second old
     self.d3d = d3dshot.create(capture_output='numpy', frame_buffer_size=4)
Exemple #28
0
 def __init__(self):
     self.grabber = d3dshot.create('numpy')
Exemple #29
0
RESIZE = (64, 64)
SPEED_SCALE = 300
HOST = "127.0.0.1"
PORT = 65432

if __name__ == "__main__":
    device = "cuda" if torch.cuda.is_available() else "cpu"
    print("Using {} device".format(device))

    trackmania_net = TrackmaniaNet(drop_out=0.15)
    trackmania_net.load_state_dict(torch.load("models/model_large_tune.pth"))
    trackmania_net.eval()
    trackmania_net.to(device)

    d = d3dshot.create()
    d.display = d.displays[1]
    width, height = d.display.resolution

    to_tensor = transforms.ToTensor()

    gamepad = vg.VX360Gamepad()
    try:
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind((HOST, PORT))
            s.listen()
            s.setblocking(False)
            while True:
                try:
                    conn, addr = s.accept()
                    with conn:
Exemple #30
0
 def __init__(self):
     self.d3d = d3dshot.create(capture_output='numpy')