# Imread return empty matrix

**URL:** <https://forum.opencv.org/t/imread-return-empty-matrix/9873>\
**Category:** Uncategorized\
**Tags:** csharp, imgcodecs\
**Created:** [August 17, 2022, 7:23am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873 "2022-08-17T07:23:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathieu\_G](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mathieu_g/32/5873_2.png) [@Mathieu\_G](https://forum.opencv.org/u/Mathieu_G)\
**Post date:** [August 17, 2022, 7:23am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873/1 "2022-08-17T07:23:36Z")

</div>

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) :

```auto
                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](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/6/6ec01ee3352ba2671682af80edd7f39e297f44dc.png)

Thank you in advance for any help.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 17, 2022, 7:59am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873/2 "2022-08-17T07:59:39Z")

</div>

> [@Mathieu\_G](#):
>
> For information, the path of my file in the string variable is :  
> C:\Users\mgauquelin\Downloads\ReferencePiezoVerification\_SN404108.tif

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 ?

---

<div class="post-metadata">

**Author:** ![Mathieu\_G](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mathieu_g/32/5873_2.png) [@Mathieu\_G](https://forum.opencv.org/u/Mathieu_G)\
**Post date:** [August 17, 2022, 8:11am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873/3 "2022-08-17T08:11:40Z")

</div>

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](https://we.tl/t-dmOLNU4KBr). It seems to be black but if you auto adjust contrast you will be a dots grid.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 17, 2022, 9:18am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873/4 "2022-08-17T09:18:14Z")

</div>

so, since the [error comes from here](https://github.com/opencv/opencv/blob/4.x/modules/imgcodecs/src/loadsave.cpp#L431) , it _did_ load the file, parsed the tif header, but could not parse the data correctly.

time to debug, i guess …

---

<div class="post-metadata">

**Author:** ![sturkmen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sturkmen/32/13_2.png) [@sturkmen](https://forum.opencv.org/u/sturkmen)\
**Post date:** [August 17, 2022, 9:20am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873/5 "2022-08-17T09:20:21Z")

</div>

i opened an [issue](https://github.com/opencv/opencv/issues/22388) i think there is a problem to solve in line [opencv/grfmt\_tiff.cpp at 4.x · opencv/opencv · GitHub](https://github.com/opencv/opencv/blob/4.x/modules/imgcodecs/src/grfmt_tiff.cpp#L663)

when I remove this line I opened the file

---

<div class="post-metadata">

**Author:** ![Mathieu\_G](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mathieu_g/32/5873_2.png) [@Mathieu\_G](https://forum.opencv.org/u/Mathieu_G)\
**Post date:** [August 17, 2022, 9:22am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873/6 "2022-08-17T09:22:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sturkmen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sturkmen/32/13_2.png) [@sturkmen](https://forum.opencv.org/u/sturkmen)\
**Post date:** [August 17, 2022, 9:30am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873/7 "2022-08-17T09:30:30Z")

</div>

just curious about the content of file ReferencePiezoVerification\_SN404108.tif

---

<div class="post-metadata">

**Author:** ![Mathieu\_G](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mathieu_g/32/5873_2.png) [@Mathieu\_G](https://forum.opencv.org/u/Mathieu_G)\
**Post date:** [August 17, 2022, 9:34am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873/8 "2022-08-17T09:34:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 17, 2022, 10:26am UTC](https://forum.opencv.org/t/imread-return-empty-matrix/9873/9 "2022-08-17T10:26:59Z")

</div>

> [@Mathieu\_G](#):
>
> The warning message I get:  
> `imread_('C:\Users\mgauquelin\Downloads\ReferencePiezoVerification_SN404108.tif'): can't read data: unknown exception`

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.
