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

时间:2014-07-28 02:45:53

标签: c++ macos opencv homebrew

我正在尝试在我的mac上设置openCV(与自制软件一起安装)并运行以下命令。

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文件与图片一起在右边第2位。我没有看到程序如何找不到文件,因为名称和位置似乎是正确的。

enter image description here

test.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;
}

2 个答案:

答案 0 :(得分:2)

想出来。将/usr/local/Cellar/opencv/2.4.9/lib中的.dylib文件复制并粘贴到/usr/lib

答案 1 :(得分:-1)

将所有lib文件(即.dll格式)复制到项目文件夹中。它将从该文件夹中读取所有neccessar文件