Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imread not working in Opencv

Tags:

c++

opencv

I'm trying to use the imread function from OpenCV2.2.

My code is very simple.

cv::Mat host= imread("1.bmp", CV_LOAD_IMAGE_GRAYSCALE); 

After that, the host matrix became filled by zeros pointers, i.e. an image has not loaded.

If I use cvLoadImage then it all works properly.

The file exists, and I am not mixing the release and debug libraries. Why imread doesn't work?

like image 304
luckydevil Avatar asked Sep 14 '11 14:09

luckydevil


People also ask

Why is Imread not working?

If you are running in Debug, check that you are also using debug libraries, it fixed our problem. : OpenCV imread(filename) fails in debug mode when using release libraries.

What does Imread do in OpenCV?

imread() Loads an image from a file. The function imread loads an image from the specified file and returns it. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( Mat::data==NULL ).

Can cv2 Imread read PNG?

Any transparency present in the image is not read. To read PNG images with transparency (alpha) channel, use cv2. IMREAD_UNCHANGED as second argument in cv2. imread() function as shown in the following.

How do I read Imread images?

A = imread( filename ) reads the image from the file specified by filename , inferring the format of the file from its contents. If filename is a multi-image file, then imread reads the first image in the file.


2 Answers

Reproduced with opencv 2.4.8.

If you are running in Debug, check that you are also using debug libraries, it fixed our problem. : OpenCV imread(filename) fails in debug mode when using release libraries.

like image 111
Jon Ander Ortiz Durántez Avatar answered Sep 20 '22 00:09

Jon Ander Ortiz Durántez


i was facing the same problem with 2.4.6 . The reason was that while selecting the library , i had selected both the debug version and the release version. When i selected only the debug version for the library everything worked fine

like image 42
user2975919 Avatar answered Sep 21 '22 00:09

user2975919