c++ - OpenCV:无法加载库 libopencv_calib3d.2.4.dylib 时出错

标签 c++ macos opencv homebrew

我正在尝试在我的 Mac 上设置 openCV(使用 Homebrew 软件安装)并运行以下命令。

g++ $(pkg-config --cflags --libs opencv) test.cpp -o Test& ./test

但是,我得到了这个错误:

[1] 7834
dyld: Library not loaded: lib/libopencv_calib3d.2.4.dylib
  Referenced from: /usr/local/Cellar/opencv/2.4.9/include/./test
  Reason: image not found
Trace/BPT trap: 5

作为 openCV 和 C++ 的新手,我不确定该怎么做才能解决这个问题。

文件结构如下。 test.cpp 文件与图片一起从右数第二个。我不明白程序是如何找不到文件的,因为名称和位置似乎是正确的。

enter image description here

测试.cpp:

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, const char** argv )
{
    cout << "test output line" << endl;
     Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'

     if (img.empty()) //check whether the image is loaded or not
     {
          cout << "Error : Image cannot be loaded..!!" << endl;
          //system("pause"); //wait for a key press
          return -1;
     }

     namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
     imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window

     waitKey(0); //wait infinite time for a keypress

     destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"

     return 0;
}

最佳答案

想通了。从 /usr/local/Cellar/opencv/2.4.9/lib 中复制 .dylib 文件并将它们粘贴到 /usr/lib 中。

关于c++ - OpenCV:无法加载库 libopencv_calib3d.2.4.dylib 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24987797/

相关文章:

Android NDK - 在 Application.mk 中使用 APP_STL

c++ - 在 C++ 中更改结构内部元素的方法?

ios - 澄清dispatch_queue,重入和死锁

macos - 需要帮助将 sed 命令从 debian 移植到 OSX

c++ - OpenCV:比较帧相似性的快速方法

c++ - OpenCV 数据类型的类型特征

c++ - 类内的类数组 - 动态数组的问题 (c++)

c++ - 为什么要使用 const 成员函数?

macos - 在 Mac OSX 上部署 Qt 应用程序时缺少文件

image - 使用 cvRetrieveFrame 从 AVI 读取图像