OpenCV journey starting off not so good. The CMake build executes and links the executable successfully however the program is unable to find lenna.png when it is in the same directory as main.cpp
Code:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
int main()
{
std::cout << "Found OpenCV cmake package" << std::endl;
cv::Mat image = cv::imread("lenna.png", cv::IMREAD_GRAYSCALE);
if (! image.data)
{
std::cerr << "Image not found" << std::endl;
return 1;
}
const std::string window_name{"lenna"};
cv::namedWindow(window_name);
cv::imshow(window_name, image);
cv::waitKey(0);
return 0;
}
Directory structure:
.
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── compile_commands.json
│ └── Makefile
├── CMakeLists.txt
├── include
│ └── CMakeLists.txt
├── lenna.png
├── libs
└── main.cpp
Output:
john@ubuntu:~/Documents/test/opencv/build$ ./opencv_example
Found OpenCV cmake package
Image not found