Skip to content

fix(io): read and write images at non-ASCII paths on Windows - #669

Open
mh-masum6875 wants to merge 1 commit into
roboflow:developfrom
mh-masum6875:fix/non-ascii-image-paths
Open

mh-masum6875 wants to merge 1 commit into
roboflow:developfrom
mh-masum6875:fix/non-ascii-image-paths

Conversation

@mh-masum6875

Copy link
Copy Markdown
Contributor

On Windows, OpenCV opens paths in the ANSI code page, so it can't read or write an image whose path has characters outside ASCII. In trackers that breaks every place frames come from image files:

--- folder "séquence" (same for "動画", "видео")
frames_from_source    OSError: Failed to read image: ...
load_mot_frame_image  OSError: Failed to decode image: ...
load_rgb_frame        RuntimeError: cv2.imread failed for frame: ...
load_rgb_image        FileNotFoundError: Could not read image: ...
save_rgb_image        RuntimeError: Could not save visualization: ...

So trackers track on an image folder, MOT sequences and the trackers inspect commands all fail for a dataset stored under such a folder, which on Windows is often just the user name in the home path. A non-ASCII file name in an ASCII folder is written under a garbled name instead (café.png comes out as café.png).

A small private module, trackers/io/_image.py, now wraps the read and the write. For these paths it reads or writes the file bytes with NumPy and decodes or encodes them with OpenCV. Every other path, and every other platform, still goes straight to cv2.imread and cv2.imwrite. The five call sites use it.

Added tests/io/test_image.py. On Windows the three frame-source cases fail with the call sites reverted and pass with the change; on Linux and macOS OpenCV already handles these paths, so they pass either way. tests/io and tests/cli (not integration): 422 passed. Ruff check and format are clean on the touched files; I didn't run the full pre-commit suite.

Not covered: video files and video output go through cv2.VideoCapture / cv2.VideoWriter, which have the same limitation and no in-memory route.

Added a changelog entry under Unreleased.

OpenCV opens Windows paths in the ANSI code page. Image-folder sources,
MOT img1 frames and the inspect commands could not read a frame under a
folder with an accented, Cyrillic or CJK name, and saving a
visualization there failed or left a file with a garbled name.

For these paths, read and write the file bytes with NumPy and decode or
encode them with OpenCV. Other paths still go straight to cv2.imread
and cv2.imwrite.
@Borda
Borda requested a balanced review from Copilot November 13, 2026 09:40
@Borda Borda added the bug Something isn't working label Nov 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the Windows non-ASCII image-path fix.

No open issues 🎉

What changed in this PR

Fixes image reads and writes at non-ASCII paths on Windows across frame loading and inspection commands. Other paths and platforms retain the existing OpenCV behavior; video input and output are unchanged.

Changes:

  • Adds private image helpers that use NumPy file I/O with OpenCV decoding and encoding for affected Windows paths.
  • Updates all five image-loading and saving call sites.
  • Adds regression tests and an Unreleased changelog entry.
File Description
tests/​io/​test_image.py Tests non-ASCII paths, filename preservation, missing files, and frame sources.
src/​trackers/​io/​video.py Uses the read helper for image-folder frames.
src/​trackers/​io/​frames.py Uses the read helper for MOT frame images.
src/​trackers/​io/​_image.py Adds Windows-aware image read and write helpers.
src/​trackers/​cli/​inspect/​_common.py Routes inspection image loading and saving through the helpers.
src/​trackers/​cli/​_detections.py Uses the read helper when loading RGB frames.
CHANGELOG.md Documents the Windows non-ASCII image-path fix.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants