Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Why my program cannot open image? How show working path? VS2010

$
0
0
To be more exact, I can open it when I start in working directory via command line. If I am debugging using Visual Studio project, then the path or file is not found: #include #include #include #include // to check file if exists #include // console line output and input #include using namespace cv; using namespace std; int main( int argc, char** argv ) { string imageName("lena.jpg"); // by default ... problem with this image if( argc > 1) { imageName = argv[1]; } Mat image; ifstream f(imageName.c_str()); bool i = f.good(); std::cout << "File exists? \r\n" << i ; image = cv::imread(argv[1], IMREAD_COLOR); // Read the file if( image.empty() ) // Check for invalid input { std::cout << "Could not open or find the image" << std::endl ; return -1; } cv::namedWindow( "Display window", WINDOW_AUTOSIZE ); cv::imshow( "Display window", image ); cv::waitKey(0); // Wait for a keystroke in the window return 0; } I added a function to test if file exist because I am not sure if result from image.empty() is false due to codec not found or due to path not found. But printing the result prints 1 in any case. So I am solving 3 things: - how to print working path? - how to make sure if the file was not found because of codec problem (format not recognised) or due to file does not exist? - how to set working path to work in correct path? Currently in project Debuger is set to $(ProjectDir) but is it "project" directory or "project/Debug" or "project/project" or "project/project/Debug"? Seams it should be logicat to set it to "$(ProjectDir)/Debug" - well but this path does not work too!

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>