当前位置: 首页>>代码示例>>Python>>正文


Python pyautogui.screenshot方法代码示例

本文整理汇总了Python中pyautogui.screenshot方法的典型用法代码示例。如果您正苦于以下问题:Python pyautogui.screenshot方法的具体用法?Python pyautogui.screenshot怎么用?Python pyautogui.screenshot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyautogui的用法示例。


在下文中一共展示了pyautogui.screenshot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: imagesearch_count

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def imagesearch_count(image, precision=0.9):
    img_rgb = pyautogui.screenshot()
    if is_retina:
        img_rgb.thumbnail((round(img_rgb.size[0] * 0.5), round(img_rgb.size[1] * 0.5)))
    img_rgb = np.array(img_rgb)
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    template = cv2.imread(image, 0)
    w, h = template.shape[::-1]
    res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
    loc = np.where(res >= precision)
    count = 0
    for pt in zip(*loc[::-1]):  # Swap columns and rows
        # cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2) // Uncomment to draw boxes around found occurrences
        count = count + 1
    # cv2.imwrite('result.png', img_rgb) // Uncomment to write output image with boxes drawn around occurrences
    return count 
开发者ID:drov0,项目名称:python-imagesearch,代码行数:18,代码来源:imagesearch.py

示例2: _region_to_image

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def _region_to_image(region) -> Image or ScreenshotError:
    # On Linux, try to use pyautogui to take screenshots, and revert to mss if it fails.
    # On Windows/Mac, do the reverse.
    try:
        if OSHelper.is_linux():
            try:
                grabbed_area = _pyautogui_screenshot(region)
            except ScreenshotError as e:
                logger.debug(e)
                grabbed_area = _mss_screenshot(region)
        else:
            try:
                grabbed_area = _mss_screenshot(region)
            except ScreenshotError as e:
                logger.debug(e)
                grabbed_area = _pyautogui_screenshot(region)
    except ScreenshotError as e:
        logger.error("Screenshot failed: %s" % e)
        raise ScreenshotError("Cannot create screenshot: %s" % e)
    return grabbed_area 
开发者ID:mozilla,项目名称:iris,代码行数:22,代码来源:screenshot_image.py

示例3: take_a_screenshot

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def take_a_screenshot(self):
        '''Takes a screenshot of the screen.

        This keyword is run on failure if it is not overwritten when
        `importing` the library.

        Screenshots are saved to the current working directory or in the
        ``screenshot_folder`` if such is defined during `importing`.

        The file name for the screenshot is the current suite name with a
        running integer appended. If this keyword is used outside of Robot
        Framework execution, file name is this library's name with running
        integer appended.
        '''
        target_dir = self.screenshot_folder if self.screenshot_folder else ''
        if not isinstance(target_dir, str):
            raise ScreenshotFolderException('Screenshot folder is invalid: '
                                            '"%s"' % target_dir)
        path = self._make_up_filename()
        path = abspath(path_join(target_dir, path))
        LOGGER.info('Screenshot taken: {0}<br/><img src="{0}" '
                    'width="100%" />'.format(path), html=True)
        ag.screenshot(path) 
开发者ID:eficode,项目名称:robotframework-imagehorizonlibrary,代码行数:25,代码来源:_screenshot.py

示例4: Screenshot

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def Screenshot(self, width):
        self.SetForeground()
        size = self.root.AXSize
        pos = self.root.AXPosition
        pyautogui.screenshot('Screenshot.png', (pos[0], pos[1], size[0], size[1])).save('Screenshot.png')
        f = open(r'Screenshot.png', 'rb')
        deflated = zlib.compress(f.read())
        ls_f = base64.b64encode(deflated)
        f.close()
        return [ls_f, "png.deflate"]

        # self.root.ToBitmap().ToFile('Screenshot.bmp')
        # f = open(r'Screenshot.bmp', 'rb')
        # ls_f = base64.b64encode(f.read())
        # f.close()
        # return [ls_f, "bmp"] 
开发者ID:AirtestProject,项目名称:Poco,代码行数:18,代码来源:OSXUI.py

示例5: screen_game

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def screen_game(region, save_to=None):
	x, y, width, height = region
	try:
		raw = root.get_image(x, y, width, height, X.ZPixmap, 0xffffffff)
		if hasattr(Image, 'frombytes'):
			# for Pillow
			screenshot = Image.frombytes('RGB', (width, height), raw.data, 'raw', 'BGRX')
		else:
			# for PIL
			screenshot = Image.fromstring('RGB', (width, height), raw.data, 'raw', 'BGRX')
		if save_to is not None:
			screenshot.save(save_to + '.png')
	except:
		filename = save_to + '.png' if save_to is not None else None
		screenshot = pyautogui.screenshot(filename, region)
	return screenshot

# Return pixel color of given x, y coordinates 
开发者ID:AXeL-dev,项目名称:Dindo-Bot,代码行数:20,代码来源:tools.py

示例6: ScreenShot

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def ScreenShot():
    global pics_names
    import pyautogui
    def generate_name():
        return ''.join(random.choice(string.ascii_uppercase
                       + string.digits) for _ in range(7))
    name = str(generate_name())
    pics_names.append(name)
    pyautogui.screenshot().save(name + '.png') 
开发者ID:D4Vinci,项目名称:PyLoggy,代码行数:11,代码来源:PyLoggy.py

示例7: getpixel

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def getpixel(self,x, y):
        return screenshot().getpixel((x, y)) 
开发者ID:ClintOxx,项目名称:PUBG-Battlepoint-FarmBot,代码行数:4,代码来源:FarmBot.py

示例8: pixelMatchesColor

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def pixelMatchesColor(self, x, y, expectedRGBColor, tolerance=0):
        pix = self.getpixel(x,y)
        if len(pix) == 3 and len(expectedRGBColor) == 3:  # RGB mode
            r, g, b = pix[:3]
            exR, exG, exB = int(expectedRGBColor[0]), int(expectedRGBColor[1]), int(expectedRGBColor[2])
            return (abs(r - exR) <= tolerance) and (abs(g - exG) <= tolerance) and (abs(b - exB) <= tolerance)
        elif len(pix) == 4 and len(expectedRGBColor) == 4:  # RGBA mode
            r, g, b, a = pix
            exR, exG, exB, exA = expectedRGBColor
            return (abs(r - exR) <= tolerance) and (abs(g - exG) <= tolerance) and (abs(b - exB) <= tolerance) and (
                abs(a - exA) <= tolerance)
        else:
            assert False, 'Color mode was expected to be length 3 (RGB) or 4 (RGBA), but pixel is length %s and expectedRGBColor is length %s' % (
                len(pix), len(expectedRGBColor))


# def printScreen(message):
#     if takeScrenshot:
#         if not os.path.exists(debug_directory):
#             os.makedirs(debug_directory)
#         screenshot('{}/{}{}.png'.format(debug_directory, strftime("%m.%d %H.%M.%S", gmtime()), message)) 
开发者ID:ClintOxx,项目名称:PUBG-Battlepoint-FarmBot,代码行数:23,代码来源:FarmBot.py

示例9: _pyautogui_screenshot

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def _pyautogui_screenshot(region):
    try:
        return np.array(
            screenshot(region=(region.x, region.y, region.width, region.height))
        )
    except (IOError, OSError):
        raise ScreenshotError("Call to pyautogui.screenshot failed.") 
开发者ID:mozilla,项目名称:iris,代码行数:9,代码来源:screenshot_image.py

示例10: screenshot_win

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def screenshot_win():
    try:
        pic = pyautogui.screenshot()
        spath = os.path.expanduser('~') + '/Desktop/screenshot.jpg'
        pic.save(spath)
    except:
        print("Unable to take screenshot.") 
开发者ID:the-ethan-hunt,项目名称:B.E.N.J.I.,代码行数:9,代码来源:screenshot.py

示例11: region_grabber

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def region_grabber(region):
    if is_retina: region = [n * 2 for n in region]
    x1 = region[0]
    y1 = region[1]
    width = region[2] - x1
    height = region[3] - y1

    return pyautogui.screenshot(region=(x1, y1, width, height)) 
开发者ID:drov0,项目名称:python-imagesearch,代码行数:10,代码来源:imagesearch.py

示例12: imagesearch

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def imagesearch(image, precision=0.8):
    im = pyautogui.screenshot()
    if is_retina:
        im.thumbnail((round(im.size[0] * 0.5), round(im.size[1] * 0.5)))
    # im.save('testarea.png') useful for debugging purposes, this will save the captured region as "testarea.png"
    img_rgb = np.array(im)
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    template = cv2.imread(image, 0)
    template.shape[::-1]

    res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
    if max_val < precision:
        return [-1, -1]
    return max_loc 
开发者ID:drov0,项目名称:python-imagesearch,代码行数:17,代码来源:imagesearch.py

示例13: region_shot

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def region_shot(cls,name='seq', seq_id=0, x1=0, y1=0, x2=200, y2=200, color=False, x_val=0):
        sleep(1)
        image = pyautogui.screenshot(region=(x1, y1, x2, y2))
        if not color:
            image = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2GRAY)
        else:
            image = cv2.cvtColor(np.array(image), 2)
        cv2.imwrite('sequential/bw/' + str(name) + str(seq_id) + '.png', image)

        # process image
        im = Image.open('sequential/bw/' + str(name) + str(seq_id) + '.png')
        R, G, B = im.convert('RGB').split()
        r = R.load()
        g = G.load()
        b = B.load()
        w, h = im.size

        # Convert non-black pixels to white
        for i in range(w):
            for j in range(h):
                # if(r[i, j] != 0 or g[i, j] != 0 or b[i, j] != 0):
                if (x_val < r[i, j] < 100 or x_val < g[i, j] < 100 or x_val < b[i, j] < 100):
                    r[i, j] = 0
                    # g[i, j] = 0
                    # Just change R channel

        # Merge just the R channel as all channels
        im = Image.merge('RGB', (R, R, R))
        im.save('sequential/bw/' + str(name) + str(seq_id) + '.png') 
开发者ID:Sunuba,项目名称:roc,代码行数:31,代码来源:Screenshot.py

示例14: _make_up_filename

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def _make_up_filename(self):
        try:
            path = BuiltIn().get_variable_value('${SUITE NAME}')
            path = '%s-screenshot' % path.replace(' ', '')
        except RobotNotRunningError:
            LOGGER.info('Could not get suite name, using '
                        'default naming scheme')
            path = 'ImageHorizon-screenshot'
        path = '%s-%d.png' % (path, self.screenshot_counter)
        self.screenshot_counter += 1
        return path 
开发者ID:eficode,项目名称:robotframework-imagehorizonlibrary,代码行数:13,代码来源:_screenshot.py

示例15: print_internet_state

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import screenshot [as 别名]
def print_internet_state(state=None):
	if state is None:
		state = internet_on()
	return 'Internet is ' + ('on' if state else 'off')

# Take a screenshot of given window 
开发者ID:AXeL-dev,项目名称:Dindo-Bot,代码行数:8,代码来源:tools.py


注:本文中的pyautogui.screenshot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。