Skip to content

Support I/O functionality through std::istream/ostream #15675

@alalek

Description

@alalek

OE-XX Support I/O functionality through std::istream/ostream

  • Status: Draft

Introduction and Rationale

OpenCV library includes functionality for I/O. Currently it is file-name based.

Current approach has several issues:

  • lack of cross-platform Unicode symbols support (only UTF-8 file paths may work)
  • it requires files (no direct access to Java packed resources from .JAR/.AAR) or has workarounds like imdecode()

Proposed solutions

Extend functionality of existed I/O functions and their internal backends:

  • imread/imwrite
  • FileStorage
  • DNN's network reader

Expected changes (in case of data reading):

  • C++: add overload which accepts std::istream
  • Python: add wrapper/implementation over std::istream for Python-based file/stream handles (like open() calls)
  • Java: add wrapper/implementation over std::istream for Java InputStream / ByteBuffer / etc

Handling of Unicode files paths responsibility would be moved on the side of C++ standard library (through robust std::wstring or std::filesystem::path).
Similar idea is for Python/Java code.

Extra: Python/Java may support network(HTTP) input streams.

In-memory handling would be improved too (through std::istream wrapper).

Possible issues

Not all image readers backends may support new feature (depends on 3rdparty).

Impact on existing code, compatibility

No impact is expected on existing C++ code.

References

Issues/PRs about I/O: #4292 #5631+comment #13368(PR)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions