如何为示例文件夹设置 OpenCV 环境变量?

问题描述 投票:0回答:1

我使用 Home-brew 在 macOS Monterey 上安装了 OpenCV 4.8.1_5。

它似乎没有安装包含图像的示例文件夹。

因此以下行失败:

std::string image_path = samples::findFile("starry_night.jpg");

出现错误:

以 cv::Exception 类型的未捕获异常终止: OpenCV(4.8.1) /tmp/opencv-20231130-24939-eigxkv/opencv-4.8.1/modules/core/src/utils/samples.cpp:64: 错误:(-2:未指定错误)OpenCV 示例:找不到所需数据 文件:“findFile”函数中的 starry_night.jpg

我已经下载了示例文件夹,但不知道将其放在哪里。 我应该把它放在哪里?

另外,经过调查,我似乎必须设置一些环境变量。如果我查看示例名称空间的来源,我会看到:

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.

我很困惑。你能告诉我吗:

  • 我应该将示例文件夹放在哪里?
  • 我需要执行什么命令来设置上述环境变量?
c++ opencv macos-monterey
1个回答
0
投票

我必须将示例文件夹保存到共享目录。

示例:

usr/local/Cellar/opencv/4.8.1_5/share/opencv4/samples

然后就可以正常工作了。

© www.soinside.com 2019 - 2024. All rights reserved.