Reputation: 3
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
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
Reputation: 19873
You need to understand about escape characters
try this
Mat im = imread("D:\\OpenCV\\opencv\\build\\doc\\opencv-logo.png");
Upvotes: 1