R4nsomW4re
R4nsomW4re

Reputation: 107

Screen capture python 3.6.6 opencv and pillow not working

i am trying to do screen capture and it is only providing a black screenBlack screen

here is my code:

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

Upvotes: 0

Views: 580

Answers (1)

chaos
chaos

Reputation: 133

notice that bbox is (x1, y1, x2, y2), so (781, 925, 814, 941) is a narrow screen.

this is my example:

screen_w = 1920
screen_h = 1080 

while True:
    rgb = ImageGrab.grab(bbox=(0, 0, screen_w, screen_h)) #x1, y1, x2, y2
    rgb = np.array(rgb)

    cv2.imshow('window_frame', rgb)

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

Upvotes: 2

Related Questions