-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopencv_camera.py
30 lines (24 loc) · 895 Bytes
/
opencv_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
import time
import cv2
import numpy as numpy
class Camera(object) : #Populate a queue using Thread?
def __init__(self) :
self.camera = cv2.VideoCapture(0)
self.camera.set(cv2.cv.CV_CAP_PROP_FPS, 60)
self.camera.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1280) #1920)
self.camera.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 720) #1080)
def capture(self) :
ret, frame = self.camera.read()
return frame
def capture_gray(self) :
frame = self.capture()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
return gray
def stream_color(self) :
ret, frame = self.camera.read() #bmp,jpeg
ret, encoded = cv2.imencode('.jpg', frame)
return encoded.tostring()
def stream_gray(self) :
frame = self.capture_gray()
ret, encoded = cv2.imencode('.jpg', frame)
return encoded.tostring()