Richard
Richard

Reputation: 31

Screen capture in python

This isn't a HTML parsing Question. This is about taking a look at pixels on the screen itself.

How would I, with python, look at all the pixels in a programs window.

Following advice, I am narrowing my OS field to win32. If a X-Platform solution exists, this is the place.

Upvotes: 3

Views: 4260

Answers (2)

Istiyak
Istiyak

Reputation: 723

You can try this. It's needed Python 3.x or Python 2.x (worked with both 32 bit and 64 bit)

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

last_time = time.time()
while(True):
    screen = ig.grab(bbox=(50,50,800,640))
    print('Loop took {} seconds',format(time.time()-last_time))
    cv2.imshow("test", np.array(screen))
    last_time = time.time()
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break

Upvotes: 1

Eli Bendersky
Eli Bendersky

Reputation: 273766

From that answer, I find the approach using PyQt most promising:

import sys
from PyQt4.QtGui import QPixmap, QApplication
app = QApplication(sys.argv)
QPixmap.grabWindow(QApplication.desktop().winId()).save('test.png', 'png')

Now you're just left with a "little" task of actually comprehending what's going on in that picture. Welcome to the amazing world of image processing. In python PIL may help you.

Upvotes: 3

Related Questions