Permalink
Switch branches/tags
Nothing to show
Find file Copy path
3276406 Aug 30, 2018
1 contributor

Users who have contributed to this file

48 lines (36 sloc) 1.07 KB
import numpy as np
import cv2
class Camera:
def __init__(self, cam_num):
self.cam_num = cam_num
self.cap = None
self.last_frame = np.zeros((1,1))
def initialize(self):
self.cap = cv2.VideoCapture(self.cam_num)
def get_frame(self):
ret, self.last_frame = self.cap.read()
return self.last_frame
def acquire_movie(self, num_frames):
movie = []
for _ in range(num_frames):
movie.append(self.get_frame())
return movie
def set_brightness(self, value):
self.cap.set(cv2.CAP_PROP_BRIGHTNESS, value)
def get_brightness(self):
return self.cap.get(cv2.CAP_PROP_BRIGHTNESS)
def close_camera(self):
self.cap.release()
def __str__(self):
return 'OpenCV Camera {}'.format(self.cam_num)
if __name__ == '__main__':
cam = Camera(0)
cam.initialize()
print(cam)
frame = cam.get_frame()
print(frame)
cam.set_brightness(1)
print(cam.get_brightness())
cam.set_brightness(0.5)
print(cam.get_brightness())
cam.close_camera()