-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture.py
More file actions
37 lines (28 loc) · 973 Bytes
/
capture.py
File metadata and controls
37 lines (28 loc) · 973 Bytes
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
import logging
import cv2 as cv
class VideoStream:
def __init__(self):
self.cap = cv.VideoCapture(0)
if not self.is_open():
logging.error("Failed to open capture device")
"""
Returns raw image directly from the camera without processing
"""
def get_next_frame_raw(self):
ret, frame = self.cap.read()
return cv.flip(frame, 1)
"""
Returns processed image frame
"""
def get_next_frame(self):
frame = self.get_next_frame_raw()
frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
frame = cv.GaussianBlur(frame, (15, 15), 0)
_, thresh = cv.threshold(frame, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)
frame = cv.cvtColor(thresh, cv.COLOR_GRAY2BGR)
cv.rectangle(frame, (340, 180), (639, 479), (105,187,1), 7)
return frame
def is_open(self):
return self.cap.isOpened()
def destroy(self):
self.cap.release()