Пример #1
0
 def snapshot(self, filename="tmp.png"):
     w, h = self.get_current_resolution()
     dsp = display.Display()
     root = dsp.screen().root
     raw = root.get_image(0, 0, w, h, X.ZPixmap, 0xffffffff)
     image = Image.frombytes("RGB", (w, h), raw.data, "raw", "BGRX")
     image = pil_2_cv2(image)
     if filename:
         imwrite(filename, image)
     return image
Пример #2
0
    def snapshot(self, filename=None, ensure_orientation=True):
        screen = self.javacap.get_frame_from_stream()
        try:
            screen = string_2_img(screen)
        except Exception:
            # may be black/locked screen or other reason, print exc for debugging
            import traceback
            traceback.print_exc()
            return None

        if filename:
            imwrite(filename, screen)
        return screen
Пример #3
0
 def snapshot(self, filename="tmp.png"):
     from PIL import Image
     sct_img = self.screen.grab(self.screen.monitors[0])
     image = Image.frombytes('RGB', sct_img.size, sct_img.bgra, 'raw',
                             'BGRX')
     if len(self.screen.monitors) > 2 and self.screen.monitors[0].get(
             "height") != self.screen.monitors[1].get("height"):
         output = filename
         image.save(output)
         image = imread(output)
         os.remove(output)
     else:
         image = pil_2_cv2(image)
     imwrite(filename, image)
     return image
Пример #4
0
    def snapshot(self, filename=None, ensure_orientation=True):
        screen = self.adb.snapshot()
        # output cv2 object
        try:
            screen = string_2_img(screen)
        except Exception:
            # may be black/locked screen or other reason, print exc for debugging
            import traceback
            traceback.print_exc()
            return None

        # ensure the orientation is right
        if ensure_orientation and self.display_info["orientation"]:
            screen = rotate(
                screen, self.display_info["orientation"] * 90, clockwise=False)
        if filename:
            imwrite(filename, screen)
        return screen
Пример #5
0
    def snapshot(self, filename="tmp.png"):
        if not filename:
            filename = "tmp.png"

        if self.handle:
            screen = screenshot(filename, self.handle)
        else:
            screen = screenshot(filename)
            if self.application:
                rect = get_rect(self.window)
                screen = crop_image(
                    screen, [rect.left, rect.top, rect.right, rect.bottom])
        if not screen.any():
            if self.application:
                rect = get_rect(self.window)
                screen = crop_image(
                    screenshot(filename),
                    [rect.left, rect.top, rect.right, rect.bottom])
        if filename:
            imwrite(filename, screen)
        return screen
Пример #6
0
    def snapshot(self, filename=None, ensure_orientation=True):

        screen = self.minicap.get_frame()
        try:
            screen = string_2_img(screen)
        except Exception:
            # may be black/locked screen or other reason, print exc for debugging
            import traceback
            traceback.print_exc()
            return None

        # ensure the orientation is right
        if ensure_orientation and self.display_info["orientation"]:
            # minicap screenshots are different for various sdk_version
            if self.adb.sdk_version <= 16:
                h, w = screen.shape[:2]  # cvshape是高度在前面!!!!
                if w < h:  # 当前是横屏,但是图片是竖的,则旋转,针对sdk<=16的机器
                    screen = rotate(
                        screen, self.display_info["orientation"] * 90, clockwise=False)

        if filename:
            imwrite(filename, screen)
        return screen
Пример #7
0
    def snapshot(self, filename=None, ensure_orientation=True):

        self.rotation_watcher.get_ready()
        screen = self.minicap.get_frame_from_stream()

        # output cv2 object
        try:
            screen = string_2_img(screen)
        except Exception:
            # may be black/locked screen or other reason, print exc for debugging
            import traceback
            traceback.print_exc()
            return None

        if ensure_orientation and self.display_info["orientation"]:
            if self.adb.sdk_version <= 16:
                h, w = screen.shape[:2]  # cvshape是高度在前面!!!!
                if w < h:  # 当前是横屏,但是图片是竖的,则旋转,针对sdk<=16的机器
                    screen = rotate(
                        screen, self.display_info["orientation"] * 90, clockwise=False)

        if filename:
            imwrite(filename, screen)
        return screen
Пример #8
0
    def snapshot(self, filename=None, ensure_orientation=True):
        """
        take snapshot
        filename: save screenshot to filename
        """
        strType = False
        data = None

        if self.proxy.cap_method == CAP_METHOD.MINICAP:
            raise NotImplementedError
        elif self.proxy.cap_method == CAP_METHOD.MINICAP_STREAM:
            raise NotImplementedError
        elif self.proxy.cap_method == CAP_METHOD.WDACAP:
            data = self.proxy._neo_wda_screenshot()  # wda 截图不用考虑朝向

        if strType:
            if filename:
                with open(filename, 'wb') as f:
                    f.write(data)
            return data

        # output cv2 object
        try:
            screen = string_2_img(data)
        except:
            # may be black/locked screen or other reason, print exc for debugging
            import traceback
            traceback.print_exc()
            return None

        now_orientation = self.proxy.orientation

        # ensure the orientation is right
        if ensure_orientation and now_orientation in [LANDSCAPE, LANDSCAPE_RIGHT]:

            # minicap screenshots are different for various sdk_version
            if self.proxy.cap_method in (CAP_METHOD.MINICAP, CAP_METHOD.MINICAP_STREAM):
                h, w = screen.shape[:2]  # cvshape是高度在前面!!!!
                if w < h:  # 当前是横屏,但是图片是竖的,则旋转,针对sdk<=16的机器
                    screen = rotate(
                        screen, self.proxy.display_info["orientation"] * 90, clockwise=False)

            # wda 截图是要根据orientation旋转
            elif self.proxy.cap_method == CAP_METHOD.WDACAP:
                # seems need to rotate in opencv opencv-contrib-python==3.2.0.7
                screen = rotate(screen, 90, clockwise=(
                    now_orientation == LANDSCAPE_RIGHT))

        # readed screen size
        h, w = screen.shape[:2]

        # save last res for portrait
        if now_orientation in [LANDSCAPE, LANDSCAPE_RIGHT]:
            self.proxy._size['height'] = w
            self.proxy._size['width'] = h
        else:
            self.proxy._size['height'] = h
            self.proxy._size['width'] = w

        winw, winh = self.proxy.window_size()

        self.proxy._touch_factor = float(winh) / float(h)

        # save as file if needed
        if filename:
            imwrite(filename, screen)

        return screen