1

我正在尝试制作我的屏幕的“视频”,以便 opencv 可以对其进行分析,并且到目前为止它运行良好,但是当我进入全屏模式时,程序停止记录或分析,这停止工作。你能帮助我吗?

from mss import mss
import cv2
from PIL import Image
import numpy as np
from time import time
from pynput.mouse import Button, Controller

mon = {'top': 370, 'left':675, 'width':15, 'height':20}
mouse = Controller();
sct = mss()
upper_purple = np.array([[255, 81, 255]])
lower_purple = np.array([[96, 35, 84]])
while 1:
    
    
    begin_time = time()
    sct_img = sct.grab(mon)
    img = Image.frombytes('RGB', (sct_img.size.width, sct_img.size.height), sct_img.rgb)
    img_hsv = cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
    height, widht, channel_color = img_hsv.shape
    cv2.imshow('test', np.array(img_hsv))
    for y in range (0, height):
        for x in range (0, widht):
            red = img_hsv.item(y, x, 0)
            green = img_hsv.item(y, x, 1)
            blue = img_hsv.item(y, x, 2)
            offset = red - blue
            if ((img_hsv[y][x] >= lower_purple).all() and (img_hsv[y][x] <= upper_purple).all()):
                mouse.click(Button.left, 1)
                print("SHOOT")
    print('This frame takes {} seconds.'.format(time()-begin_time))
    
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break

4

0 回答 0