feat: streaming via socket io and redis
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from io import BytesIO
|
||||
from typing import Optional
|
||||
|
||||
import cv2
|
||||
from PIL import Image
|
||||
|
||||
@@ -9,6 +11,16 @@ class Camera:
|
||||
def __init__(self):
|
||||
self.capture = cv2.VideoCapture(0)
|
||||
|
||||
def get_image(self) -> Optional[bytes]:
|
||||
return_code, image = self.capture.read()
|
||||
if not return_code:
|
||||
return None
|
||||
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
jpg = Image.fromarray(image_rgb)
|
||||
byte_stream = BytesIO()
|
||||
jpg.save(byte_stream, 'JPEG')
|
||||
return bytes(byte_stream.getbuffer())
|
||||
|
||||
def generate_images(self):
|
||||
try:
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user