[Python] Encoding and deconding images fromwebcam in python

Discussão em 'Python' iniciado por Stack, Setembro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a script that collect the webcam feed and stream it to a remote device. In order to scale down the problem I am working now in a simplified script that cut the socket. However when I encode and then decode the image from the camera the decoding procedure fails.

    In particular, the variable frame2 = None, causing an error in imshow because the image has dimension 0.

    This s my code:

    cap = cv2.VideoCapture(0)
    ret, frame = cap.read()
    img_as_text = base64.b64encode(frame)
    cv2.imshow('starter', frame)

    nparr = np.frombuffer(base64.b64decode(img_as_text), np.uint8)
    frame2 = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
    cv2.imshow('Receiver', frame2)

    Continue reading...

Compartilhe esta Página