0

Is it possible to grayscale a portion of your screen in real time with cv2?

I know how grayscale images but can we grayscale the screen? if you know how to Geryscale a portion of your screen then please add code!

Capt.Pyrite
  • 851
  • 7
  • 24

2 Answers2

2

cv2 doesn't have write access to your screen buffer and therefore can't change the color of what you see on your screen. You should be able to take a screenshot and manipulate it, however. See Python take a screenshot of the screen and save it to a buffer.

Marcel
  • 958
  • 1
  • 7
  • 18
2

I found a Way to gray-scale a portion of my screen!

my code:

from PIL import ImageGrab
import cv2
from numpy import array
import time

while True:
    Screen = array(ImageGrab.grab(bbox=(13, 32,805, 623)))
    gray = cv2.cvtColor(Screen, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray, 20, 30)
    edges_high_thresh = cv2.Canny(gray, 60, 120)

    
    k = cv2.waitKey(30) & 0xff

    if k == 27:
        cv2.destroyAllWindows()
        break
    
    
    cv2.imshow('Frame', edges)
Capt.Pyrite
  • 851
  • 7
  • 24