0

I would like to take a screenshot with a certain range of the screen, and then I would like to check the pixel values of certain lines (eg x_axis from 400 to 800). I tried multiple ways like the imagegrab, gdi32.GetPixel and some more. It seems reading pixels values take a lot of time, so I even tried converting it into a list, something like this

im = ImageGrab.grab(box)
pixels = list(im .getdata())

Even this does not seem fast. Is there something I'm doing wrong?

1 Answer 1

1

ImageGrab returns pixels in PIL format (the Python Imaging Library: http://effbot.org/imagingbook/image.htm), and .getdata() already returns the pixels as a sequence. By wrapping it in list() again you are doing the same (expensive) operation twice. You can just do:

im = ImageGrab.grab(box)
pixels = im.getdata()

And iterate through your pixels in your favorite way.

Sign up to request clarification or add additional context in comments.

3 Comments

hey, thanks a lot.... but could you let me know if I use this for color in im.getdata(): how can I iterate in such a way that I only check every one pixel out of three
Do you mean you want to to process a pixel, then not process 2, then process a pixel, not process 2, etc?
What about this: for index, pixel in enumerate(pixels): if index % 3 == 0: # do something?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.