Guest User

Untitled

a guest
Apr 18th, 2015
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. import time
  4.  
  5. class VideoCamera(object):
  6.     def __init__(self):
  7.         # Using OpenCV to capture from device 0. If you have trouble capturing
  8.         # from a webcam, comment the line below out and use a video file
  9.         # instead.
  10.         self.status = "Sharing ?"
  11.         self._image = np.zeros((100,200))
  12.         self.video = cv2.VideoCapture(0)
  13.        
  14.         #success, self._image = self.video.read()
  15.         # If you decide to use video.mp4, you must have this file in the folder
  16.         # as the main.py.
  17.         # self.video = cv2.VideoCapture('video.mp4')
  18.    
  19.     def __del__(self):
  20.         self.video.release()
  21.    
  22.     def get_frame(self):
  23.         success, image = self.video.read()
  24.         # We are using Motion JPEG, but OpenCV defaults to capture raw images,
  25.         # so we must encode it into JPEG in order to correctly display the
  26.         # video stream.
  27.         ret, jpeg = cv2.imencode('.jpg', image)
  28.         self.string = jpeg.tostring()
  29.         self._image = image
  30.         return jpeg.tostring()
  31.    
  32.     def GetBw(self):
  33.         image = self._image
  34.         # We are using Motion JPEG, but OpenCV defaults to capture raw images,
  35.         # so we must encode it into JPEG in order to correctly display the
  36.         # video stream.
  37.         ret, jpeg = cv2.imencode('.jpg', image)
  38.         self.string = jpeg.tostring()
  39.         return jpeg.tostring()
Advertisement
Add Comment
Please, Sign In to add comment