-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture.py
49 lines (36 loc) · 1.18 KB
/
capture.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from PIL import ImageGrab
from PIL import Image
import cv2
import numpy as np
import time
from game import Game
class Capture:
def __init__(self):
pass
def record_screen(self):
game= Game()
game.play_game()
time.sleep(2)
crashed = game.get_crashed()
last_time=time.time()
while( not crashed):
# control frame rate
# time.sleep(.1)
# The bounding box is a (left_x, top_y, right_x, bottom_y) tuple
printscreen = np.array( ImageGrab.grab(bbox=(0,255,1365,515)))
print("time : {} seconds".format(time.time()-last_time))
# cv2.imshow('window',printscreen)
# if cv2.waitKey(25) & 0xFF == ord('q'):
# cv2.destroyAllWindows()
# break
# to save as image
# im = Image.fromarray(printscreen)
# im.save(str(time.time())+".jpeg")
last_time=time.time()
crashed=game.get_crashed()
return printscreen
def main():
cp=Capture()
return cp.record_screen()
if __name__ == "__main__":
main()