Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to live stream frames? #1

Closed
kivancagaogluu opened this issue May 15, 2022 · 1 comment
Closed

Any way to live stream frames? #1

kivancagaogluu opened this issue May 15, 2022 · 1 comment

Comments

@kivancagaogluu
Copy link

I want to do live stream webcam frames but stuck in for loop pubstub listen.
Is there any way to do this?

Python code

import redis
import base64
import cv2

r = redis.Redis(host="localhost", port=6379, db=0, decode_responses=True)
pubsub = r.pubsub()
pubsub.subscribe("send")

r.set("hello", "world")
r.publish("message", "hello")

print("Waiting for messages...")

cam = cv2.VideoCapture(0)

while True:

    success, frame = cam.read()

    for request in pubsub.listen():
      
        if request["data"] == "img":

            with open("test.jpg", "rb") as img_file:

                my_string = base64.b64encode(img_file.read())
            r.publish("imageBase64", my_string)

        if request["data"] == "imgcv":
            source = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            success, encoded_image = cv2.imencode('.jpg', source)
            content = encoded_image.tobytes()
            r.publish("imageBase64", base64.b64encode(content).decode('ascii'))

@kivancagaogluu
Copy link
Author

My bad. changing success, frame inside of request solved it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant