Guest User

camera_opencv.py

a guest
Nov 4th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import cv2
  2. from base_camera import BaseCamera
  3.  
  4.  
  5. class Camera(BaseCamera):
  6.     video_source = 0
  7.  
  8.     @staticmethod
  9.     def set_video_source(source):
  10.         Camera.video_source = source
  11.  
  12.     @staticmethod
  13.     def frames(id): # when I do that I got that error which I mention above
  14.         # I WANT TO RECEIVE THE fid IN THIS FUNCTION and print it here
  15.         print(id) # But I get an error
  16.         camera = cv2.VideoCapture(Camera.video_source)
  17.         if not camera.isOpened():
  18.             raise RuntimeError('Could not start camera.')
  19.  
  20.         while True:
  21.             # read current frame
  22.             _, img = camera.read()
  23.  
  24.             # encode as a jpeg image and return it
  25.             yield cv2.imencode('.jpg', img)[1].tobytes()
Advertisement
Add Comment
Please, Sign In to add comment