Skip to content

cv::imread with OutputArray dst returns with empty output #25694

@cocoa-xu

Description

@cocoa-xu

System Information

OpenCV version: 4.10.0
Operating System / Platform: macOS Sonoma 14.4.1
Compiler & compiler version:

Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Detailed description

When using cv::imread with OutputArray dst given, the output will stay empty. The path to the image and the image file are both valid and can be read by the program and the user.

CV_EXPORTS_W void imread( const String& filename, OutputArray dst, int flags = IMREAD_COLOR );

There is no error message in stdout/stderr. Calling the function with correct parameters doesn't throw any exceptions.

Steps to reproduce

To the best of my understanding, the variable dst is expected to be a valid and non-empty cv::Mat after calling cv::imread in the following code:

#include <stdio.h>
#include <opencv2/opencv.hpp>

int main(int argc, const char** argv) {
    if (argc != 2) {
        printf("[!] Usage: %s <image_path>\n", argv[0]);
        return 1;
    }

    printf("[+] image_path: %s\n", argv[1]);
    cv::Mat dst;
    cv::imread(argv[1], dst, cv::IMREAD_COLOR);
    if (dst.empty()) {
        printf("[!]: dst is empty\n");
        return 1;
    }
    cv::imshow("Image", img);
    cv::waitKey(0);
    return 0;
}

The test file, corridor.jpg is a valid JPEG file (this can be any supported image format, not limited to the JPEG format only) and located in /tmp/ and can be read by anyone. This file is taken from opencv_contrib, in samples/data/corridor.jpg, https://github.com/opencv/opencv_contrib/blob/4.x/samples/data/corridor.jpg

./test /tmp/corridor.jpg
[+] image_path: /tmp/corridor.jpg
[!]: dst is empty

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions