I installed OpenCV 4.8.1_5 on macOS Monterey using Home-brew.
It doesn't seem to have installed the samples folder containing images.
So the following line fails:
std::string image_path = samples::findFile("starry_night.jpg");
with the error:
terminating with uncaught exception of type cv::Exception: OpenCV(4.8.1) /tmp/opencv-20231130-24939-eigxkv/opencv-4.8.1/modules/core/src/utils/samples.cpp:64: error: (-2:Unspecified error) OpenCV samples: Can't find required data file: starry_night.jpg in function 'findFile'
I have downloaded the samples folder and don't know where to place it. Where should I place it ?
Also, on investigation it seems I must set some environmental variables. If I look at the source of samples namespace I see :
Search directories:
1. Directories passed via `addSamplesDataSearchPath()`
2. OPENCV_SAMPLES_DATA_PATH_HINT environment variable
3. OPENCV_SAMPLES_DATA_PATH environment variable
If parameter value is not empty and nothing is found then stop searching.
4. Detects build/install path based on:
a. current working directory (CWD)
b. and/or binary module location (opencv_core/opencv_world, doesn't work with static linkage)
5. Scan `<source>/{,data,samples/data}` directories if build directory is detected or the current directory is in source tree.
6. Scan `<install>/share/OpenCV` directory if install directory is detected.
I am confused. Can you please tell me:
- Where do I place the samples folder ?
- What commands I need to execute to set the above environment variables ?
I have to save the samples folder to the share directory.
Example:
usr/local/Cellar/opencv/4.8.1_5/share/opencv4/samples
Then it works fine.