简体   繁体   中英

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)

After Getting the image convert it to numpy array(ie 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM