forked from yamamara/SoteriaDetection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (36 loc) · 1.22 KB
/
main.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
50
import logging
import os
from logging.handlers import TimedRotatingFileHandler
import cv2
# Main camera variable
capture = cv2.VideoCapture(0)
# Initializes and formats logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logFormatter = logging.Formatter("[%(asctime)s] [%(levelname)s/%(name)s] %(message)s")
if not os.path.exists("log"):
os.makedirs("log")
file_handler = TimedRotatingFileHandler("log/soteria.log", when="midnight", interval=1, backupCount=30)
file_handler.suffix = "%m-%d-%Y"
file_handler.setFormatter(logFormatter)
console_handler = logging.StreamHandler()
console_handler.setFormatter(logFormatter)
logger.addHandler(file_handler)
logger.addHandler(console_handler)
if not capture.isOpened():
logger.error("Unable to open camera")
while True:
# Reads the current frame from the camera as a tuple
frame_available, frame = capture.read()
if not frame_available:
break
# Instantiates camera window and updates frame data
cv2.imshow("Webcam", frame)
# Captures keyboard input
key = cv2.waitKey(1)
# Closes window when "esc" key pressed
if key == 27:
break
# Frees resources after window closed
capture.release()
cv2.destroyAllWindows()