1

I'm trying to make a "video" of my screen, so that the opencv can analyze it, and so far it works well, however when I go into full screen mode, the program stops recording or analyzing, this stops working. Can you help me?

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

Tiger-222
  • 6,677
  • 3
  • 47
  • 60

0 Answers0