3

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.

Mike Atlas
  • 8,193
  • 4
  • 46
  • 62
Richard
  • 31
  • 1
  • 3
  • 1
    You're going to need to be much more specific! Do you mean the screen of the python program itself, or something else running? Do you mean the screen or the window of some app? What OS and windowing system do you mean? – Andrew Jaffe Aug 17 '10 at 16:37
  • I mean look at the displayed contents of another application. Windows OS if specifics are required, preferably multi-platform. – Richard Aug 17 '10 at 16:38
  • Please **update** your question with additional information. Windows and "preferably multi-platform" are usually contradictory. Please try to focus on something specific so we can actually help. – S.Lott Aug 17 '10 at 17:29
  • I edited the post title to be screen capture, since, screen scraping really only refers to trying to read the information on the monitor, rather than the pixels themselves. http://en.wikipedia.org/wiki/Data_scraping#Screen_scraping – Mike Atlas Aug 17 '10 at 18:02

2 Answers2

3

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.

Community
  • 1
  • 1
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • The code just worked (on Windows 7 x64 - Python 2.7.5; Pythonxy distrubution). The resulting file is a normal screenshot of the whole screen. Jpeg also available (e.g. ... .save('d:/test.jpg', 'jpeg')) – Mohamad Fakih Aug 13 '13 at 05:18
1

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
Istiyak
  • 693
  • 6
  • 15