forked from kerrywang/automatic_faceCapture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtakeScreenShots.py
31 lines (28 loc) · 956 Bytes
/
takeScreenShots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from PIL import ImageGrab
import time
import numpy as np
import imutils
import cv2
#clear the folder to avoid recapturing images
import os, shutil
#Either put your folder address in this line or comment this part and delete manually
folder = '/Users/kaiyuewang/Downloads/face-alignment/images'
for the_file in os.listdir(folder):
file_path = os.path.join(folder, the_file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
except Exception as e:
print(e)
i = 0
while(True):
img = ImageGrab.grab() #bbox specifies specific region (bbox= x,y,width,height *starts top-left)
img_np = np.array(img) #this is the array obtained from conversion
# img_np = imutils.resize(img_np, width=800)
frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB)
path = "images/screenShot_" + str(i) + ".jpg"
cv2.imwrite(path, frame)
# cv2.waitKey(1)
# cv2.destroyAllWindows()
i += 1
time.sleep(5)