屏幕截图python 3.6.6 opencv和枕头不起作用

时间:2018-10-16 01:22:41

标签: python python-3.x opencv python-imaging-library

我正在尝试进行屏幕捕获,并且只提供黑屏Black screen

这是我的代码:

import numpy as np
from PIL import ImageGrab
import cv2

while(True):
    printscreen_pil =  ImageGrab.grab(bbox=(781, 925, 814, 941))
    printscreen_numpy =   np.array(printscreen_pil.getdata(),dtype='uint8')\
    .reshape((printscreen_pil.size[1],printscreen_pil.size[0],3)) 
    cv2.imshow('window',printscreen_numpy)



    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break

1 个答案:

答案 0 :(得分:1)

请注意,bbox为(x1,y1,x2,y2),因此(781、925、814、941)是一个狭窄的屏幕。

这是我的示例:

def triangle(n, choice):

    k = 2*n-2
    for i in range(0, n):
        for j in range(0, k):
            print(end = ' ')

        k = k-1

        for t in range(0, i+1):
            print(choice, end = " ")
        print("\r")



def main():

    n = int(input("Input a number: "))
    choice = input("Enter a character to draw: ")
    triangle(n, choice)



main()