Imread return empty matrix

I am using the C# wrapper but maybe you could have some tracks to follow to help me.

Imread is not working anymore with “.tif” file (48bits) after updating the OpenCvSharp wrapper version from OpenCvSharp3Any-Cpu (wrapper 4.X) to OpenCvSharp4.Windows and .Extensions. The file is 450Mo weight.

My environment :

  • .Net 4.8
  • Windows 10
  • Visual Studio 2019 Profesionnal
  • Nugget Package for OpenCvSharp4.Windows and all dependencies for
    OpenCvSharp4.Extensions (include OpenCvSharp4 and .runtime.win
    (redundancy ?)

For information, the path of my file in the string variable is :
C:\Users\mgauquelin\Downloads\ReferencePiezoVerification_SN404108.tif

The warning message I get:
imread_('C:\Users\mgauquelin\Downloads\ReferencePiezoVerification_SN404108.tif'): can't read data: unknown exception

Here is a sample code of my reading, with a check of the permission to read (always true) after the check the file exists (always true also) :

                bool result;
                string file = "myPath";
                using (FileStream fs = new FileStream(file, FileMode.Open))
                {
                    if (fs.CanRead)
                    {
                        result= true;
                    }
                    else
                    {
                        result= false;
                    }
                }
                mat = OpenCvSharp.Cv2.ImRead(file, ImreadModes.Unchanged);

I tried to open other format of file : ok.
I tried to come back to OpenCvSharp3 : ok.
I read a lot of forums which deal with the file permission, the path of the file. Already check this.

Format of my matrix after imread:
Sans titre

Thank you in advance for any help.

please use either \\ or / as path seperators, even on windows

then, tif is some monster format, not all subsets of it are supported by the libtiff version used under the hood.

maybe you can upload your image somewhere, so other ppl can take a shot at it ?

all your csharp related install info is useless here, but which opencv version is it ?

I already tried with “/” instead of “\” but same result.

If I look at the github project of the C# wrapper, it seems to be the OpenCV 4.5.5 version and before it was the OpenCv 4.0 version.

For the test image, you can download clicking here. It seems to be black but if you auto adjust contrast you will be a dots grid.

1 Like

so, since the error comes from here , it did load the file, parsed the tif header, but could not parse the data correctly.

time to debug, i guess …

i opened an issue i think there is a problem to solve in line opencv/grfmt_tiff.cpp at 4.x · opencv/opencv · GitHub

when I remove this line I opened the file

2 Likes

So I put he finger on a real issue, not something weird with my softwware environment. Great ^.^ I think I have to get back to older wrapper so. Thank you.

just curious about the content of file ReferencePiezoVerification_SN404108.tif

I work on a project which begin 15 years ago so I am totally blind how is save the image. But because it can be read with other software such as XnView or ImageJ (and older C# wrapper), I never ask question about this saving.
The data in the file is on 12 bits only, but can be compressed on 8 bit. It is why we work with 16 bits and we need to adjust the contrast to see the image.

1 Like

indicates that the path is syntactically correct… that’s an OpenCV message and it’s just printing the string, not formatting it to be C syntax.