python cv2 screen capture

import numpy as np
import cv2
from PIL import ImageGrab

while True:
    img = ImageGrab.grab(bbox=(0, 1000, 100, 1100)) #x, y, w, h
    img_np = np.array(img)
    frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
    cv2.imshow("frame", frame)
    if cv2.waitKey(1) & 0Xff == ord('q'):
        break
    
cv2.destroyAllWindows()

Here is what the above code is Doing:
1. We’re creating a while loop that will run forever.
2. We’re using ImageGrab to grab the screen.
3. We’re converting the image to a numpy array.
4. We’re converting the image to grayscale.
5. We’re displaying the image.
6. If we press the q key, the while loop will break.
7. We’re destroying all the windows.