Ramsha Asim
Ramsha Asim

Reputation: 3

opencv and visual studio 2010 cannot load image from a subdirectory

im new to open cv. im using Open CV 2.4.9 with visual Studio 2010. Im using a basic program to open an image. the problem is that when i put the image file on the main drive (eg: D:\image.png), it works correctly. but when i move the image to a subdirectory (eg:D:\OpenCV\opencv\build\doc\opencv-logo.png), the output says "image cannot be loaded"

where am i going wrong. please help me out

here is the code that im using:

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

using namespace cv;
using namespace std;

int main()
{
    Mat im = imread("D:\OpenCV\opencv\build\doc\opencv-logo.png");
    if (im.empty()) 
    {
        cout << "Cannot load image!" << endl;
        return -1;
    }
    imshow("Image", im);
    waitKey(0);
}

Upvotes: 0

Views: 526

Answers (2)

Shwetha
Shwetha

Reputation: 150

You will have to escape the \ character. You have to do this :

Mat im = imread("D:\\OpenCV\\opencv\\build\\doc\\opencv-logo.png")

Upvotes: 1

Eric
Eric

Reputation: 19873

You need to understand about escape characters

try this

Mat im = imread("D:\\OpenCV\\opencv\\build\\doc\\opencv-logo.png");

Upvotes: 1

Related Questions