Imread returns null

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:

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

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_executable(opencvtest main.cpp)
target_link_libraries( opencvtest PRIVATE ${OpenCV_LIBS}  funcoes CVUI  )

Don’t you forget a : ?


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

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.

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.

1 Like

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

nice try, but no cookie :wink:

1 Like

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