<< return to Vizycam.com

Kritter Camera Stream reduce frame size

When working with Kritter like:

camera = kritter.Camera(hflip=True, vflip=True)
stream = camera.stream()
frame = stream.frame()[0]

How do you set the resolution of the stream / frame? I see that in kritter.Kvideo we can set width so is that the same for stream?

I ended up doing this:

                   scale_percent = 50 # percent of original size
                   width = int(frame.shape[1] * scale_percent / 100)
                   height = int(frame.shape[0] * scale_percent / 100)
                   dim = (width, height)
                   resized = cv2.resize(frame, dim, interpolation = cv2.INTER_AREA)
                   encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 90]
                   img = base64.b64encode(cv2.imencode('.jpg', resized,encode_param)[1]).decode()

This works to reduce the size to get under the 64 KiB limitation of the websocket send.

It depends on what you want to do. If you’re just interested in reducing the size of the video frames, you can scale each video frame before you send it to the video component with push_frame():

frame = cv2.resize(frame, (width, height))  # use opencv2 resize
video.push_frame(frame)  # video is the video component

If you just to scale the video in the browser, you can set the width when you instantiate the video component:

video = kritter.Kvideo(width=width)

Hope this helps.


Thank you! That is essentially what I ended up doing. I was looking at the other examples and taking bits and pieces to get done. I have a fair bit of experience with OpenCV so I just quickly went that route.