0

I have a C++ project and I want to access some data I have saved in folder images. I have tried from calibration.cpp to do:

std::string path = "images/*.jpg";
cv::glob(path, images);

But it gave me an error of not detecting the directory. In order to determine in which directory the execution was looking at I created a dummy text file and save it to see where it got saved. It gets saved in cmake-build-debug , which is a folder created automatically when building the CMakeLists.txt in CLion. Then if I put my images folder in cmake-build-debug it gets seen but I want to have the images folder in parent directory.

  • How can I set the current directory to look for files from there?

My project looks like:

Camera Motion
-- cmake-build-debug
----     ...
-- images
---- image1.png
-- CMakeLists.txt
-- calibration.cpp
# CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(CameraMotion)

set(CMAKE_CXX_STANDARD 14)

find_package( OpenCV REQUIRED )
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(CameraMotion calibration.cpp)
target_link_libraries(CameraMotion ${OpenCV_LIBS})

# calibration.cpp
#include <iostream>

int main()
{
    std::ofstream myfile;
    myfile.open("output.txt");
    myfile << "output\n";
    myfile.close();
    std::string path = "images/*.jpg";

    cv::glob(path, images);
}

When I run the project in CLion it says:

====================[ Build | CameraMotion | Debug ]============================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/hectoresteban/CLionProjects/CameraMotion/cmake-build-debug --target CameraMotion -- -j 4
[100%] Built target CameraMotion
Hector Esteban
  • 1,011
  • 1
  • 14
  • 29

1 Answers1

0

CLion quick CMake tutorial says:

Notice the Generation path field that specifies the location of build results. The default folders are cmake-build-debug for Debug profiles and cmake-build-release for Release profiles. You can always set other locations of your choice.

Why do you want to merge build and source directory? It is more convenient to store build results and sources separate. What if you want to build a release build?

a1ezh
  • 412
  • 3
  • 10
  • My objective is to load a file not to save it so this was just to show the current directory considered by CLion. How can I make the current directory for accessing an input file the one where original CMake is? I have edited the question to clarify my goal – Hector Esteban Apr 12 '20 at 12:05
  • If you simply want to change current working directory for your application, try this: https://stackoverflow.com/a/25836234/3445338 – a1ezh Apr 12 '20 at 12:13