• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pyautogui.screenshot函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: screen_shot

def screen_shot(left_corner=None, right_corner=None):
    if (left_corner is not None) and (right_corner is not None):
        region=(left_corner[0],left_corner[1],right_corner[0]-left_corner[0],right_corner[1]-left_corner[1])
        pil_image = pyautogui.screenshot(region=region)
    else:
        pil_image = pyautogui.screenshot()
    opencv_image = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2BGR)
    return opencv_image
开发者ID:sedlamat,项目名称:Game_BM,代码行数:8,代码来源:game_bm.py


示例2: screenshot

	def screenshot(self):
		self.fmaximizeUO()
		if self.os == "Linux":
			command("import -window $(xdotool getwindowfocus -f) /tmp/screen.png & xdotool click 1")
			return "/tmp/screen.png"
		elif self.os == "Windows":
			pyautogui.screenshot("C:\\Windows\\Temp\\screen.png")
			return "C:/Windows/Temp/screen.png"
开发者ID:ZDDM,项目名称:Voyageur-chan,代码行数:8,代码来源:bot.py


示例3: func

        def func():
            self.screenshot_button.config(state='disabled')

            for second in reversed(range(4)):
                self.screenshot_label.config(
                    text='Deselect the game window %s' % second)
                if second != 0:
                    time.sleep(1)

            region = []
            for second in reversed(range(4)):
                self.screenshot_label.config(
                    text='Place the mouse at the top left\nof the game\'s title bar %s' % second)
                if second != 0:
                    time.sleep(1)
            constant_top_left = pyautogui.position()
            region.extend(constant_top_left)
            for second in reversed(range(4)):
                self.screenshot_label.config(
                    text='Place the mouse at the bottom right\nof the game\'s title bar %s' % second)
                if second != 0:
                    time.sleep(1)
            constant_bottom_right = pyautogui.position()
            region.extend(
                (constant_bottom_right[0] - constant_top_left[0],
                 constant_bottom_right[1] - constant_top_left[1])
            )
            self.deselected_screenshot = pyautogui.screenshot(region=region)
            pyautogui.click()
            self.selected_screenshot = pyautogui.screenshot(region=region)

            for second in reversed(range(4)):
                self.screenshot_label.config(
                    text='Place mouse at the top left\nof the entire game window %s' % second)
                if second != 0:
                    time.sleep(1)
            top_left = pyautogui.position()
            for second in reversed(range(4)):
                self.screenshot_label.config(
                    text='Place mouse at the bottom right\nof the entire game window %s' % second)
                if second != 0:
                    time.sleep(1)
            bottom_right = pyautogui.position()

            self.screen_size = [
                constant_top_left[0] - top_left[0],
                constant_top_left[1] - top_left[1],
                bottom_right[0] - constant_bottom_right[0],
                bottom_right[1] - constant_bottom_right[1]
            ]

            self.screenshot_taken = True
            self.screenshot_label.config(text='Screenshot Taken')
            self.screenshot_button.config(
                state='normal', text='Retake Screenshot')
开发者ID:jaronoff97,项目名称:play_as_one,代码行数:55,代码来源:PlayAsOne.py


示例4: checkItem

 def checkItem(self, x, y, img=None):
     pyautogui.moveTo(x, y, duration=0.1)
     pyautogui.moveTo(x+1, y, duration=0.1)
     pyautogui.moveTo(x, y, duration=0.1)
     im = pyautogui.screenshot(region=(0, 0, 800, 600))
     if img is not None:
         # TODO check they are not the same
         pass
     time.sleep(0.1)
     return im
开发者ID:artofboom,项目名称:fmbot,代码行数:10,代码来源:char.py


示例5: click

 def click(self, x, y, button, press):
     if button == 1:
         if press:
             self.a.append(self.m.position())
             if(len(self.a) == 2):
                 #print(self.a)
                 x1,y1,x2,y2 = self.a[0][0],self.a[0][1],self.a[1][0],self.a[1][1]
                 pyautogui.screenshot('C:/Python27/output.png',(x1,y1,x2-60,y2-150))
                 self.a = []
                 self.stop()
     else:  # Exit if any other mouse button used
         self.stop()
开发者ID:sahil865gupta,项目名称:Tuts-Robo,代码行数:12,代码来源:click.py


示例6: screenCapture

def screenCapture(savePath):
    global SAVE_SCREEN_MAP_PATH
    # hwnd = 0
    # hwndDC = win32gui.GetWindowDC(hwnd)
    # mfcDC=win32ui.CreateDCFromHandle(hwndDC)
    # saveDC=mfcDC.CreateCompatibleDC()
    # saveBitMap = win32ui.CreateBitmap()
    # saveBitMap.CreateCompatibleBitmap(mfcDC, size[0], size[1])
    # saveDC.SelectObject(saveBitMap)
    # saveDC.BitBlt((0,0),SCREEN_SIZE, mfcDC, SCREEN_POS, win32con.SRCCOPY)
    # saveBitMap.SaveBitmapFile(saveDC,SAVE_SCREEN_MAP_PATH)
    # Image.open(SAVE_SCREEN_MAP_PATH).save(SAVE_SCREEN_MAP_PATH[:-4]+".png")
    pyautogui.screenshot(SAVE_SCREEN_MAP_PATH)
开发者ID:fengxxx,项目名称:ImagePin,代码行数:13,代码来源:_imagePinUtil.py


示例7: shoot

def shoot(x1,y1,x2,y2, *args, **kwargs):
    """Takes screenshot at given coordinates as PIL image format, the converts to cv2 grayscale image format and returns it"""
    # creates widht & height for screenshot region
    w = x2 - x1
    h = y2 - y1
    # PIL format as RGB
    img = pyautogui.screenshot(region=(x1,y1,w,h)) #X1,Y1,X2,Y2
    #im.save('screenshot.png')

    # Converts to an array used for OpenCV
    img = np.array(img)

    try:
        for arg in args:
            if arg == 'hsv':
                # Converts to BGR format for OpenCV
                img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
                hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
                return hsv_img

            if arg == 'rgb':
                rgb_img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
                return rgb_img
    except:
        pass

    cv_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    return cv_gray
开发者ID:jjvilm,项目名称:osrmacro,代码行数:28,代码来源:Screenshot.py


示例8: screenshotThread

def screenshotThread():
    OOO="                                           "
    global req
    global alive
    printer.p(OOO+"screenshotThread === checking in...")
    n=0
    while alive:
        #if time.time()-start>20: alive=False #autorestart
        if myID==IDcheck and req==1:
            #pyautogui.screenshot("screenshot.png")
            img=pyautogui.screenshot()
            try:
                img.save(abspath+"screenshot.jpg", "JPEG", quality=0, optimize=True, progressive=False)
                n+=1
            except:
                printer.p(OOO+"screenshotThread === couldn't save it?")
                pass
                
            try:
                files = {'media': open(abspath+'screenshot.jpg', 'rb')}
                r=requests.post('http://'+ip+'/zerog/upload.php', files=files)
                printer.p(OOO+"screenshotThread === screenshot#"+str(n))
            except:
                printer.p(OOO+"screenshotThread === couldn't upload it?")
                pass
        else: time.sleep(5)
        
    printer.p(OOO+"screenshotThread === ...checking out")
开发者ID:jayagopaldaz,项目名称:zerog,代码行数:28,代码来源:cooperate.py


示例9: locateAllOnScreen

def locateAllOnScreen(needleImg):
    # Take a screenshot image of the desktop and save it
    img = pyautogui.screenshot( "desktop.png")

    # Allow image to be saved prior to continuing
    time.sleep(5)
    
    # Allow opencv2 to read both images
    haystackImg = cv2.imread( "desktop.png")
    grayImg = cv2.cvtColor( haystackImg, cv2.COLOR_BGR2GRAY)
    needleImg = cv2.imread( needleImg ,0)
    width , height = needleImg.shape[::-1]
    
    # Use thresholding to find multiple matches
    res = cv2.matchTemplate( grayImg, needleImg, cv2.TM_CCOEFF_NORMED)
    threshold = 0.8
    matchCoords = np.where( res >= threshold)
    
    #Uncomment to view the rectangular match regions
    #for pt in zip(*matchCoords[::-1]):
    #    cv2.rectangle( haystackImg, pt, (pt[0] + width, pt[1] + height), (0,0,255), 2)
    
    # Save the resulting image as a png image
    #cv2.imwrite('result.png', haystackImg )

    return matchCoords
开发者ID:Astroua,项目名称:CARTAvis,代码行数:26,代码来源:ImageUtil.py


示例10: color_height

def color_height(measure_start):
    screenshot = pyautogui.screenshot()
    height = 0
    start_color = screenshot.getpixel((measure_start))
    while screenshot.getpixel((measure_start[0] + height, measure_start[1])) == start_color:
        height += 1
    return height
开发者ID:JacobTheEldest,项目名称:galaxies-solver,代码行数:7,代码来源:gui_recognition.py


示例11: cv2_match

def cv2_match(tmp, threshold=0.8, grayscale="auto"):
    if grayscale == "auto":
        if len(tmp.shape) == 2:
            grayscale = True
        else:
            grayscale = False
    q = p.screenshot()
    w = cv2.cvtColor(np.array(q), cv2.COLOR_RGB2BGR)
    if grayscale:
        w = cv2.cvtColor(w, cv2.COLOR_BGR2GRAY)
        if len(tmp.shape) >= 3:
            tmp = cv2.cvtColor(tmp, cv2.COLOR_BGR2GRAY)
    else:
        if len(tmp.shape) < 3:
            tmp = cv2.cvtColor(tmp, cv2.COLOR_GRAY2BGR)
    res = cv2.matchTemplate(w, tmp, cv2.TM_CCOEFF_NORMED)
    res = np.where(res > threshold)
    dis = min(tmp.shape[:2]) / 2
    l = int(tmp.shape[1] / 2)
    h = int(tmp.shape[0] / 2)
    result = []
    for i in range(len(res[0])):
        pos = (res[1][i] + l, res[0][i] + h)
        flag = True
        for j in result:
            if get_dis(pos, j) < dis:
                flag = False
                break
        if flag:
            result.append(pos)
    return result
开发者ID:qzane,项目名称:wanga.me,代码行数:31,代码来源:main.py


示例12: color_width

def color_width(measure_start):
    screenshot = pyautogui.screenshot()
    width = 0
    start_color = screenshot.getpixel((measure_start))
    while screenshot.getpixel((measure_start[0] + width, measure_start[1])) == start_color:
        width += 1
    return width
开发者ID:JacobTheEldest,项目名称:galaxies-solver,代码行数:7,代码来源:gui_recognition.py


示例13: Start

def Start(pos):
    pyautogui.FAILSAFE = False
    global root, running
    im=pyautogui.screenshot()
    pos['text']=str(pyautogui.position())
    rgb['text']=str(im.getpixel(pyautogui.position()))
    root.update_idletasks()
    root.after(10, lambda:Start(pos))
开发者ID:tushutripathi,项目名称:posRGB,代码行数:8,代码来源:posRGB.py


示例14: read

 def read(self):
     img = pyautogui.screenshot()
     if self.bbox:
         img = img.crop(self.bbox)
     img = np.asarray(img)
     img = cv2.resize(img, (self.width, self.height))
     img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
     return (self._is_opened, img)
开发者ID:ExceptionError,项目名称:resultoon,代码行数:8,代码来源:capture.py


示例15: screenShot

def screenShot():
	"""function for the taking the screen shot of current window"""
	BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
	img_path = os.path.join(BASE_DIR,r'raw_data\screenshot')
	#print img_path
	img_name = '{0}_{1}.{2}'.format('screnshot',time.strftime('%d%m%y_%I%M%S'),'jpg')
	im1 =pyautogui.screenshot(os.path.join(img_path,img_name))
	voiceOut.Speak("your screen is successfully captured")
	return
开发者ID:ShivaGuntuku,项目名称:Jarvis,代码行数:9,代码来源:simpleScript.py


示例16: screenshotOpencv

def screenshotOpencv(allConfigs):
    #This function is taking a screenshot with pyautogui which gets a Pillow image
    #Then it makes sure it is transformed in an opencv format
    position = allConfigs['position']
    im = pyautogui.screenshot()
    if position['crop_window'] == 'yes':
        im = im.crop((position['window_start_x'],position['window_start_y'], position['window_end_x'], position['window_end_y']))
    open_cv_image = cv2.cvtColor(np.array(im), cv2.COLOR_RGB2BGR)
    return open_cv_image
开发者ID:starcraft04,项目名称:swauto,代码行数:9,代码来源:functions_screenshot.py


示例17: locateOnScreen

def locateOnScreen(needleImg):
    # Take a screenshot image of the desktop and save it
    img = pyautogui.screenshot("desktop.png")
    # Allow image to be saved prior to continuing
    time.sleep(5)
    # Get the matching coordinates
    matchCoords = get_match_coordinates( needleImg, "desktop.png")

    return matchCoords
开发者ID:Astroua,项目名称:CARTAvis,代码行数:9,代码来源:ImageUtil.py


示例18: test_global_prefs

def test_global_prefs(cartavisInstance, cleanSlate):
    """
    Test that object specific settings can also act globally.
    Set the animator to jump. Save the preferences. Open two animators. Restore the preferences.
    Check the second animator is also set to jump.
    """
    # Set the animator to jump 
    settingsButton = ImageUtil.locateCenterOnScreen( "test_images/animatorSettingsCheckBox.png")
    assert settingsButton != None
    pyautogui.click( x=settingsButton[0], y=settingsButton[1])

    # Click the jump radio button
    jumpButton = ImageUtil.locateCenterOnScreen('test_images/jumpButton.png')
    assert jumpButton != None
    pyautogui.doubleClick( x=jumpButton[0], y=jumpButton[1])

    # Save a snapshot. Make sure preferences are checked and 
    # layout and data are not checked
    s = cartavisInstance.newSnapshot('some_session_id','tSnapshotPreferences', False, True, False, '')
    s.save()

    # Find an image window and change it into an animator
    imageWindow = ImageUtil.locateCenterOnScreen('test_images/imageWindow.png')
    assert imageWindow != None
    pyautogui.rightClick( x=imageWindow[0], y=imageWindow[1])
    pyautogui.press('right')
    pyautogui.press('right')
    pyautogui.press('down')
    pyautogui.press('return')
    time.sleep(2)

    # Find the settings button on the animator and click it so the jump will be visible 
    settingsButton = ImageUtil.locateCenterOnScreen('test_images/settingsCheckBox.png')
    assert settingsButton != None
    pyautogui.click( x=settingsButton[0], y=settingsButton[1])

    # Restore the preferences
    s[0].restore()

    # Check that both animators are not displaying jump
    # Verify that the animator jump end behaviour is checked in the screenshot after the tests have been run
    pyautogui.screenshot('layout_check/bothAnimatorsJump.png')
    s[0].delete()
开发者ID:astrilet,项目名称:CARTAvis,代码行数:43,代码来源:test_snapshot.py


示例19: detect_position

 def detect_position(self):
     screen = ag.screenshot()
     for name, offset_x, offset_y in [('start', 288, 252), ('select_title', 28, 24)]:
         position = self.find_image(screen, self.images[name])
         if position != None:
             x, y = position
             x -= offset_x
             y -= offset_y
             self.set_position(x, y)
             return (x, y)
     return None
开发者ID:binderwang,项目名称:chainer-dqn,代码行数:11,代码来源:game.py


示例20: moveCharToTheLeftOfFM

 def moveCharToTheLeftOfFM(self):
     CharIsLeft = False
     pyautogui.keyDown('left')
     while not CharIsLeft:
         im = pyautogui.screenshot(region=(0, 0, 800, 600))
         left = im.getpixel((9, 138))
         if 212 < left[0] and left[0] < 224:
             if 200 < left[1] and left[1] < 208:
                 if 14 < left[2] and left[2] < 18:
                     CharIsLeft = True
     pyautogui.keyUp('left')
开发者ID:artofboom,项目名称:fmbot,代码行数:11,代码来源:char.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyautogui.size函数代码示例发布时间:2022-05-25
下一篇:
Python pyautogui.press函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap