Pierre Marsaa
Pierre Marsaa

Reputation: 381

Screenshot of a specific location in python

I'm trying to do a piece of code that takes a picture of a specific place on the screen. I can take a picture of the screen, but not of a specific place.

My goal is to take a picture where the top left point is at this position: (536, 76)

and the bottom right point is at this position: (998, 791)

Here's what I have so far, which takes a screenshot

import PIL

snapshot = PIL.ImageGrab.grab()

save_path = "C:\\Users\\pierr\\Pictures\\Screenshots\\oui_" + str(i) + ".jpg"  

snapshot.save(save_path)

Upvotes: 2

Views: 4740

Answers (1)

Veer
Veer

Reputation: 211

After Getting the image convert it to numpy array(i.e opencv format of image) by using check here for extra information

image = numpy.array(snapshot) 

From this numpy array access the part of image with

image[start_y:end_y, start_x:end_x] in your case image[76:791, 536:998] and then u can save image using cv2.imwrite()

Upvotes: 2

Related Questions