Opencv cv2.aruco.detectMarkers

raceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
  File "/mount/src/shrim_msuering-/SSM_app.py", line 50, in <module>
    corners, _, _ = cv2.aruco.detectMarkers(image, aruco_dict, parameters=parameters)
cv2.error: OpenCV(3.4.11) /tmp/pip-req-build-fbivvj01/opencv_contrib/modules/aruco/src/aruco.cpp:1124: error: (-215:Assertion failed) !_image.empty() in function 'detectMarkers'

link to the app is https://ssmapp.streamlit.app

gitreop - GitHub - Danuka97/shrim_msuering-

Hi @Danuka97,

Thanks for posting!

So it seems the error is coming from your code where you’re trying to read the file path of the uploaded file using cv2.imread(uploaded_file.name). Try reading the image from the uploaded file into a format that OpenCV can work with like using byte stream then decoding it into an image like so:

if uploaded_file is not None:
    # Convert the file to an OpenCV image
    file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
    img = cv2.imdecode(file_bytes, 0)  # Read as grayscale
    image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)  # Read as color image

Let me know if this resolves the issue.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.