Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- import time
- class VideoCamera(object):
- def __init__(self):
- # Using OpenCV to capture from device 0. If you have trouble capturing
- # from a webcam, comment the line below out and use a video file
- # instead.
- self.status = "Sharing ?"
- self._image = np.zeros((100,200))
- self.video = cv2.VideoCapture(0)
- #success, self._image = self.video.read()
- # If you decide to use video.mp4, you must have this file in the folder
- # as the main.py.
- # self.video = cv2.VideoCapture('video.mp4')
- def __del__(self):
- self.video.release()
- def get_frame(self):
- success, image = self.video.read()
- # We are using Motion JPEG, but OpenCV defaults to capture raw images,
- # so we must encode it into JPEG in order to correctly display the
- # video stream.
- ret, jpeg = cv2.imencode('.jpg', image)
- self.string = jpeg.tostring()
- self._image = image
- return jpeg.tostring()
- def GetBw(self):
- image = self._image
- # We are using Motion JPEG, but OpenCV defaults to capture raw images,
- # so we must encode it into JPEG in order to correctly display the
- # video stream.
- ret, jpeg = cv2.imencode('.jpg', image)
- self.string = jpeg.tostring()
- return jpeg.tostring()
Advertisement
Add Comment
Please, Sign In to add comment