-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.py
More file actions
23 lines (23 loc) · 793 Bytes
/
Copy pathcamera.py
File metadata and controls
23 lines (23 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import cv2
camera = None
def init(camera_id=0, width=640, height=480, buffer_size=1):
global camera
camera = cv2.VideoCapture(camera_id, cv2.CAP_V4L)
camera.set(cv2.CAP_PROP_FRAME_WIDTH, width)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
camera.set(cv2.CAP_PROP_BUFFERSIZE, buffer_size)
def take_picture(most_recent=False):
global camera
# most_recent가 True이면 버퍼에 저장되어 있는 프레임을 전부 버리도록 한다.
len = 0 if most_recent == False else camera.get(cv2.CAP_PROP_BUFFERSIZE)
while(len > 0):
camera.grab( ) # 버퍼에 저장되어 있는 프레임을 버린다.
len -= 1
success, image = camera.read( )
if not success:
return None
return image
def final( ):
if camera != None:
camera.release( )
camera = None