[Python] CV2's VideoCapture is causing issues with numpy arrays __str__ dunder

Discussão em 'Python' iniciado por Stack, Março 31, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to capture images from my webcam, but I'm having issues reading from the videocapture.

    from typing import Optional

    import cv2


    def main() -> None:
    videocapture: Optional[cv2.VideoCapture] = None

    try:
    videocapture = cv2.VideoCapture(0)

    if videocapture.isOpened():
    read_successful, image = videocapture.read()

    if read_successful:
    print(image)

    finally:
    if videocapture is not None:
    videocapture.release()

    if __name__ == "__main__":
    main()


    So far I've completely reinstalled the venv.

    I was expecting a numpy array to be printed to the console, instead I see the following stacktrace:

    Traceback (most recent call last):
    File "C:\Users\<CENSORED>\PycharmProjects\trackify-backend\.venv\Lib\site-packages\numpy\_core\arrayprint.py", line 34, in <module>
    from . import numerictypes as _nt
    File "C:\Users\<CENSORED>\PycharmProjects\trackify-backend\.venv\Lib\site-packages\numpy\_core\numerictypes.py", line 102, in <module>
    from ._type_aliases import (
    File "C:\Users\<CENSORED>\PycharmProjects\trackify-backend\.venv\Lib\site-packages\numpy\_core\_type_aliases.py", line 38, in <module>
    allTypes[_abstract_type_name] = getattr(ma, _abstract_type_name)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AttributeError: module 'numpy.core.multiarray' has no attribute 'complexfloating'

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "C:\Users\<CENSORED>\PycharmProjects\trackify-backend\src\pose_tracking.py", line 52, in <module>
    track()
    File "C:\Users\<CENSORED>\PycharmProjects\trackify-backend\src\pose_tracking.py", line 44, in track
    print(image)
    RuntimeError: Unable to configure default ndarray.__str__

    Continue reading...

Compartilhe esta Página