-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.py
35 lines (27 loc) · 830 Bytes
/
camera.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
'''
Camera Classifier v0.1 Alpha
Copyright (c) NeuralNine
Instagram: @neuralnine
YouTube: NeuralNine
Website: www.neuralnine.com
'''
import cv2 as cv
class Camera:
def __init__(self):
self.camera = cv.VideoCapture(0)
if not self.camera.isOpened():
raise ValueError("Unable to open camera!")
self.width = self.camera.get(cv.CAP_PROP_FRAME_WIDTH)
self.height = self.camera.get(cv.CAP_PROP_FRAME_HEIGHT)
def __del__(self):
if self.camera.isOpened():
self.camera.release()
def get_frame(self):
if self.camera.isOpened():
ret, frame = self.camera.read()
if ret:
return (ret, cv.cvtColor(frame, cv.COLOR_BGR2RGB))
else:
return (ret, None)
else:
return None