# Imread returns null

**URL:** <https://forum.opencv.org/t/imread-returns-null/6174>\
**Category:** C++\
**Tags:** imgcodecs\
**Created:** [November 12, 2021, 7:24pm UTC](https://forum.opencv.org/t/imread-returns-null/6174 "2021-11-12T19:24:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nascimento210](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/nascimento210/32/3703_2.png) [@nascimento210](https://forum.opencv.org/u/nascimento210)\
**Post date:** [November 12, 2021, 7:24pm UTC](https://forum.opencv.org/t/imread-returns-null/6174/1 "2021-11-12T19:24:17Z")

</div>

My code runs normaly in visual studio but when I try to run on vscode with a makefile I start to receive some errors and throws exceptions thats because imread returns a empty cv::mat  
This is the code part of cv::imread:

```auto
#include <iostream>
#include <stdio.h>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/imgproc.hpp>
#include <math.h>

#include "Funcs.h"
#include "cvui.h"

#define WINDOW_NAME	"Rows and Columns"

int main()
{
	// cvui
	cv::Mat frame = cv::Mat(900, 1300, CV_8UC3);
	cv::Mat display1;
	cv::Mat display2 = cv::Mat(520, 600, CV_8U, cv::Scalar(0, 0, 0));
	
	int colorCount = 0;
	std::vector<std::string> cores = { "Amarelo","Azul", "Vermelho", "Verde", "Rosa" };

	// fonts of frame
	cv::Mat imgdefault = cv::imread("C/Users/tisie/Documents/opencvtest/img.lena.jpg", cv::IMREAD_COLOR);
	cv::Mat imgstatic = cv::imread("./model1.png", cv::IMREAD_COLOR);
	cv::VideoCapture vid("ball_move.mp4");
	cv::VideoCapture webC(0);
	int pathChose = 0;

	// perspective
	int mouse_count = 0;
	int cornerx[4] = {0};
	int cornery[4] = {0};
	cv::Mat_<float> dst = (cv::Mat_<float>(4, 2) <<
		0, 0, 600, 0,
		0, 520, 600, 520);
	bool applyPerspective = false;
	bool applyMask = false;

```

and this is my make file:

```auto
cmake_minimum_required(VERSION 3.0.0)
project(opencvtest VERSION 0.1.0)

set(CMAKE_TOOLCHAIN_FILE "C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_PREFIX_PATH "C:/dev/vcpkg/installed/x64-windows/share")
set(OpenCV_DIR "C:/dev/vcpkg/installed/x64-windows/share/opencv")

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS})

add_library(
    CVUI
    cvui.h
    cvui.cpp
)

add_library(
    funcoes
    Funcs.h
    Funcs.cpp
)

add_executable(opencvtest main.cpp)
link_directories(${OpenCV_LIB_DIR})
target_link_libraries( opencvtest PRIVATE ${OpenCV_LIBS} funcoes CVUI )

```

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [November 12, 2021, 9:14pm UTC](https://forum.opencv.org/t/imread-returns-null/6174/2 "2021-11-12T21:14:46Z")

</div>

Hi,  
Don’t you forget a : ?

> [@nascimento210](#):
>
> ```auto
> cv::Mat imgdefault = cv::imread("C/Users/tisie/Documents/opencvtest/img.lena.jpg", cv::IMREAD_COLOR);
> 
> ```

---

<div class="post-metadata">

**Author:** ![nascimento210](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/nascimento210/32/3703_2.png) [@nascimento210](https://forum.opencv.org/u/nascimento210)\
**Post date:** [November 13, 2021, 1:41pm UTC](https://forum.opencv.org/t/imread-returns-null/6174/3 "2021-11-13T13:41:04Z")

</div>

yes, but this isn’t the error, I changed it but the error still perceived, I have already tried with full path and local path, but nothing changes

---

<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:** [November 13, 2021, 3:58pm UTC](https://forum.opencv.org/t/imread-returns-null/6174/4 "2021-11-13T15:58:45Z")

</div>

I doubt that. something’s going on and you aren’t telling.

**debug** your program. that means step through it and look at variables. you can figure out trivially where things go wrong… e.g. _which_ imread fails.

show that you actually DO use absolute paths (show _the code_ you execute, not any code you didn’t execute). and show that the files are actually there.

these issues are always the same.

---

<div class="post-metadata">

**Author:** ![Etruscus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/etruscus/32/3834_2.png) [@Etruscus](https://forum.opencv.org/u/Etruscus)\
**Post date:** [November 22, 2021, 2:00pm UTC](https://forum.opencv.org/t/imread-returns-null/6174/6 "2021-11-22T14:00:49Z")

</div>

Hi,  
try to put C:\ … in image file path and rename img.lena.jpg to lena.jpg.  
May be the parser confuse .lena as a image file suffix.

---

<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:** [November 22, 2021, 2:11pm UTC](https://forum.opencv.org/t/imread-returns-null/6174/7 "2021-11-22T14:11:29Z")

</div>

> [@Etruscus](#):
>
> May be the parser confuse .lena as a image file suffix.

imread() does not parse file suffixes, instead it looks at “magic bytes” in the file

nice try, but no cookie 😉

---

<div class="post-metadata">

**Author:** ![Etruscus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/etruscus/32/3834_2.png) [@Etruscus](https://forum.opencv.org/u/Etruscus)\
**Post date:** [November 22, 2021, 5:23pm UTC](https://forum.opencv.org/t/imread-returns-null/6174/8 "2021-11-22T17:23:50Z")

</div>

Oops! Thanks for the info. Next time i will give a look to source code before 😉
