0

so i'm using opencv in python to look at a specific part of screen using this code:

import numpy as np  
from PIL import ImageGrab  
import cv2  

while(True):  
  printscreen_pil =  ImageGrab.grab(bbox=(852,530,911,575))  
  printscreen =   np.array(printscreen_pil.getdata(),dtype='uint8')\  
  .reshape((printscreen_pil.size[1],printscreen_pil.size[0],3))   
  cv2.imshow('window',cv2.cvtColor(printscreen, cv2.COLOR_BGR2GRAY))  
  if cv2.waitKey(25) & 0xFF == ord('q'):  
    cv2.destroyAllWindows()  
    break

I want to give an output whenever this part of the screen matches an image. I'm stuck and reading up on 100 different tutorials but I'm stuck at the moment.

  • Is [this](https://stackoverflow.com/questions/27343997/using-pil-python-image-library-to-detect-image-on-screen) answers your question ? – nakE Jan 14 '20 at 19:49
  • 1
    Please indent your code correctly - it makes a difference in Python. If you can't be bothered to write it properly or check it, you won't incentivise folk to help you. – Mark Setchell Jan 14 '20 at 20:28
  • Please note PIL grabs in RGB, not BGR. – Mark Setchell Jan 14 '20 at 20:29
  • it's pointless using `getdata()` to convert the image to a list, then go to Numpy, then `reshape()` it back to an array. Just use `npim = np.array(printscreen_pil)` – Mark Setchell Jan 14 '20 at 20:32

0 Answers0