Ask Your Question
0

imread returns empty Mat

asked 2015-07-28 07:26:47 -0600

jakr13 gravatar image

updated 2015-07-28 07:29:27 -0600

hello everyone,

I have been working on OpenCV 2.4.7 with Visual Studio 2012 express edition for quite a long time and it was working without any flaws. I recently upgraded to OpenCV 2.4.9 and given the path in the environment variables as mentioned. Then I tried running a sample program of loading images from a specific path with the include, library directories and the additional dependencies added to the project properties. The Mat is null even after the imread function. Then I tried upgrading to OpenCV 2.4.10 and its the same with this version too. Then I installed OpenCV 3.0.0, the sample code is working perfectly.

I am wondering why it was not working with OpenCV 2.4.9 and 2.4.10?

The problem was only with windows systems. I have tried in Windows 7 and Windows 8.1. In Linux it works perfectly. Since I tried all the solutions online, Can anyone tell me whats the problem? is it problem with the opencv 2.4.9? I can use 3.0.0 but I want some functions from 2.4.9, so I need to use 2.4.9. Please suggest mesome solution.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    Mat image;  
image = imread("C:\\Desktop\\Lighthouse.jpg", IMREAD_COLOR); 
    if( image.empty() )                      
    {
       cout <<  "Could not open or find the image" << std::endl ;
       return -1;
    }
    namedWindow( "Display window", WINDOW_AUTOSIZE ); 
    imshow( "Display window", image );                
    waitKey(0); 
    return 0;
}

In Environment Variables I added OPENCV_DIR = C:\OpenCV249\build and Path = %OPENCV_DIR%\x86\vc12\bin

In Project properties I have added Additional Include Directories = $(OPENCV_DIR)\include, Additional Library Directories = $(OPENCV_DIR)\x86\vc12\lib and

`Additional Dependencies = opencv_calib3d249.lib
                                         opencv_contrib249.lib
                                         opencv_core249.lib
                                         opencv_features2d249.lib
                                         opencv_flann249.lib
                                         opencv_gpu249.lib
                                         opencv_highgui249.lib
                                         opencv_imgproc249.lib
                                         opencv_legacy249.lib
                                         opencv_ml249.lib
                                         opencv_nonfree249.lib
                                         opencv_objdetect249.lib
                                         opencv_photo249.lib
                                         opencv_stitching249.lib
                                         opencv_ts249.lib
                                         opencv_video249.lib
                                         opencv_videostab249.lib
                                         opencv_superres249.lib
                                         opencv_ocl249.lib`
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-07-28 07:37:00 -0600

You need to be carefull when switching in between 2.4 versions and 3.0 version, since variables all got different names. Namely looking at image = imread("C:\\Desktop\\Lighthouse.jpg", IMREAD_COLOR); you should be aware that:

  • For the 2.4 repo's it needs to be image = imread("C:\\Desktop\\Lighthouse.jpg", CV_IMREAD_COLOR); with the CV prefix. This did change around 2.4.10 or 2.4.11 where the newer variables where introduced.
  • For the 3.0 repos you need indeed image = imread("C:\\Desktop\\Lighthouse.jpg", IMREAD_COLOR);

Can you see if this works?

edit flag offensive delete link more

Comments

No, its the same. I used 1 instead, its the same.

jakr13 gravatar imagejakr13 ( 2015-07-28 07:47:36 -0600 )edit
2

O and how about that path, afaik there is no Desktop folder right under C drive ... you sure that is correct?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-28 08:10:40 -0600 )edit

the path is "C:\Users\jakr13\Desktop\Lighthouse.jpg". I didn't copy that properly in my program. Still there is no solution yet!!!

jakr13 gravatar imagejakr13 ( 2015-07-28 23:43:00 -0600 )edit

its double slash

jakr13 gravatar imagejakr13 ( 2015-07-28 23:45:25 -0600 )edit

So you mean you solved it? Or just want to point out you are using double slash?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-29 02:29:23 -0600 )edit

I have the same issue. imread always returns empty on version 3.4

le0 gravatar imagele0 ( 2018-05-20 09:15:44 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-28 07:26:47 -0600

Seen: 10,270 times

Last updated: Jul 28 '15