3

我试图部署一个简单的 Qt Opencv 应用程序,以下是代码:

Qt:.pro 文件:

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = opencvVideoTest
TEMPLATE = app

SOURCES += main.cpp\
    mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

INCLUDEPATH = -I/usr/local/include

LIBS += -lm -lopencv_core -lopencv_highgui -lopencv_imgproc

主窗口.cpp:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    cv::Mat img;

   cv::VideoCapture cap("BMWM5.avi");

   if(cap.isOpened()){

   for(;;){
       cap.read(img);
       cv::resize(img,img,cv::Size(604,480));
       cv::imshow("Opencv", img);
       cv::waitKey(33);
   }
   }
   else{

   }


}

MainWindow::~MainWindow()
{
    delete ui;
}

上面的代码片段在具有 Opencv 2.4.3、ffmpeg 1.1.2 和 Qt 5.0.1 的开发机器上运行良好。当我在使用 macdeployqt 和输出之前尝试部署、运行 otool 时会发生这种情况:

>   /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
 version 169.3.0)   /usr/local/opt/opencv/lib/libopencv_core.2.4.3.dylib
 (compatibility version 2.4.0, current version 2.4.3)
 >  /usr/local/opt/opencv/lib/libopencv_highgui.2.4.3.dylib
 (compatibility version 2.4.0, current version 2.4.3)
>   /usr/local/opt/opencv/lib/libopencv_imgproc.2.4.3.dylib
   (compatibility version 2.4.0, current version 2.4.3)
>   /usr/local/Qt5.0.1/5.0.1/clang_64/lib/QtWidgets.framework/Versions/5/QtWidgets
  (compatibility version 5.0.0, current version 5.0.1)
>   /usr/local/Qt5.0.1/5.0.1/clang_64/lib/QtGui.framework/Versions/5/QtGui
  (compatibility version 5.0.0, current version 5.0.1)
>   /usr/local/Qt5.0.1/5.0.1/clang_64/lib/QtCore.framework/Versions/5/QtCore
  (compatibility version 5.0.0, current version 5.0.1)
>   /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
  (compatibility version 1.0.0, current version 1.0.0)
>   /System/Library/Frameworks/AGL.framework/Versions/A/AGL
  (compatibility version 1.0.0, current version 1.0.0)
>   /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current
  version 56.0.0)

macdeployqt 输出后的 otool:

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    @executable_path/../Frameworks/libopencv_core.2.4.3.dylib (compatibility version 2.4.0, current version 2.4.3)
  @executable_path/../Frameworks/libopencv_highgui.2.4.3.dylib (compatibility version 2.4.0, current version 2.4.3)
  @executable_path/../Frameworks/libopencv_imgproc.2.4.3.dylib (compatibility version 2.4.0, current version 2.4.3)
  @executable_path/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets

(兼容版本 5.0.0,当前版本 5.0.1)@executable_path/../Frameworks/QtGui.framework/Versions/5/QtGui(兼容版本 5.0.0,当前版本 5.0.1)@executable_path/../Frameworks /QtCore.framework/Versions/5/QtCore(兼容版本 5.0.0,当前版本 5.0.1) /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL(兼容版本 1.0.0,当前版本 1.0. 0) /System/Library/Frameworks/AGL.framework/Versions/A/AGL(兼容版本1.0.0,当前版本1.0.0) /usr/lib/libstdc++.6.dylib(兼容版本7.0.0,当前版本56.0.0)

但是在部署它之后,当我尝试在用户的机器上运行应用程序时,它崩溃了,也没有报告错误,在 Windows 中曾经发生过完全相同的事情,但是当我将 opencv_ffmpeg.dll 复制到 exe 文件夹中时,它工作正常。我在这里尝试使用相同的逻辑并失败了,然后我将所有ffmpeg及其依赖项的每个lib文件手动添加到项目文件夹中,但仍然失败。还有其他解决方案吗,请帮忙?我是mac dpeloyment的新手。我错过或忽略了什么?

4

0 回答 0