12

I am following this tutorial which interacts with the screen but is done for Windows OS since ImageGrab is not available in linux

import numpy as np
from PIL import ImageGrab
import cv2
import time

def screen_record():
    last_time = time.time()
    while(True):
        # 800x600 windowed mode
        printscreen =  np.array(ImageGrab.grab(bbox=(0,40,800,640)))
        print('loop took {} seconds'.format(time.time()-last_time))
        last_time = time.time()
        cv2.imshow('window',cv2.cvtColor(printscreen, cv2.COLOR_BGR2RGB))
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break

Is there any alternative for ImageGrab or is better to switch OS?

Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
lapinkoira
  • 8,320
  • 9
  • 51
  • 94

1 Answers1

18

Use the pyscreenshot library. It's the ImageGrab replacement for linux systems.

import pyscreenshot as ImageGrab
im = ImageGrab.grab()
im2 = np.asanyarray(im)

Hope this will work fine for your code.

msitt
  • 1,237
  • 12
  • 27
Rohit Kalia
  • 198
  • 1
  • 5