【问题标题】:OpenCV: Error for failure to load library libopencv_calib3d.2.4.dylibOpenCV:加载库 libopencv_calib3d.2.4.dylib 失败时出错
【发布时间】:2014-07-28 02:45:53
【问题描述】:

我正在尝试在我的 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 文件与图片一起位于右侧第二个。我看不出程序如何找不到文件,因为名称和位置似乎是正确的。

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

【问题讨论】:

    标签: c++ macos opencv homebrew


    【解决方案1】:

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

    【讨论】:

    • 这不是必须的;安装后运行的brew link opencv 应该已经为您将符号链接到 /usr/local/lib 中。您可以尝试再次运行链接步骤(可能使用 --force)以确保一切都在正确的位置。如果您将复制的文件留在 /usr/lib 中,Homebrew 将无法升级它们。
    • 将/usr/local/Cellar/opencv/3.2.0/include/opencv & opencv2 也复制到/usr/local/include 中!
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 2019-02-20
      • 2014-08-18
      • 2019-10-28
      • 1970-01-01
      • 2021-04-14
      • 2019-03-12
      相关资源
      最近更新 更多