Reputation: 107
i am trying to do screen capture and it is only providing a black 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
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