C++ Eclipse OpenCV:生成.exe文件和二进制文件,但没有显示图像

发布于 2024-12-25 00:02:43 字数 1220 浏览 6 评论 0原文

这是我的代码(OpenCV 文档中的第一个 DisplayImage.cpp 代码)

/*
 * DisplayImage.cpp
 *
 *  Created on: Dec 25, 2011
 *      Author: Arcturus */       
 #include <iostream>    
 #include <opencv2\opencv.hpp>

using namespace cv;

using namespace std;

int main(int argc, char** argv){

    Mat image;

    image = imread(argv[1], 1);

    if(argc!=2 || !image.data){

        cout<<"no image data";

        return -1;
    }

    namedWindow("Display Image", CV_WINDOW_AUTOSIZE);

    imshow("Display Image", image);

    waitKey(10000);

    return 0;
}

构建完成,生成可执行文件,生成二进制文件。

我的图像 - blackbuck.bmp - 在 DisplayImage 调试文件夹中。要运行代码,我转到 Run>;运行配置。选择 DisplayImage Debug exe 文件,键入 blackbuck.bmp(也尝试使用绝对路径)并运行它。

在控制台顶部,我收到消息:DisplayImage 调试。而且它根本不显示任何图像。这里可能出了什么问题?

我正在 Eclipse 上使用 CDT 运行它。

谢谢您的宝贵时间!

编辑:问题解决了!!!我必须将所有 dll 文件从库文件夹复制到生成可执行文件的文件夹中。但我仍然不明白为什么。毕竟,链接器已经链接了包含所有 dll 的库文件夹。如果有人能解释一下这一点,对以后的调试会有很大的帮助。谢谢 karl 和 mevotron 的宝贵时间:)

编辑 2:来自 msdn 网站: “使用 DLL 的一个潜在缺点是应用程序不是独立的;它依赖于单独的 DLL 模块的存在。如果进程启动时找不到所需的 DLL,系统将使用加载时动态链接来终止进程并向用户提供错误消息,在这种情况下,系统不会使用运行时动态链接来终止进程,但丢失的 DLL 导出的函数对程序不可用。”

我想这回答了我的问题。也许这意味着 eclipse 使用加载时动态链接。

Here's my code (the first DisplayImage.cpp code in the OpenCV documentation)

/*
 * DisplayImage.cpp
 *
 *  Created on: Dec 25, 2011
 *      Author: Arcturus */       
 #include <iostream>    
 #include <opencv2\opencv.hpp>

using namespace cv;

using namespace std;

int main(int argc, char** argv){

    Mat image;

    image = imread(argv[1], 1);

    if(argc!=2 || !image.data){

        cout<<"no image data";

        return -1;
    }

    namedWindow("Display Image", CV_WINDOW_AUTOSIZE);

    imshow("Display Image", image);

    waitKey(10000);

    return 0;
}

Build complete, executable generated, binaries generated.

I have my image - blackbuck.bmp- in the DisplayImage Debug folder. To run the code, I go to Run> Run Configurations. Select the DisplayImage Debug exe file, key in blackbuck.bmp (also tried it with absolute path) and run it.

On the top of the console, I get the message : DisplayImage Debug. And it displays no image at all. What could be wrong here?

I am running it on Eclipse, using CDT.

Thank you for your time!

EDIT: Problem solved!!! I had to copy all the dll files from the library folder to the folder in which my executable file was being generated. I still do not understand why, though. After all, the linker was already linking the library folder containing all the dlls. If someone could explain this, it would be of great help for future debugging. Thank you karl and mevotron for your time :)

EDIT 2: From the msdn website:
"A potential disadvantage to using DLLs is that the application is not self-contained; it depends on the existence of a separate DLL module. The system terminates processes using load-time dynamic linking if they require a DLL that is not found at process startup and gives an error message to the user. The system does not terminate a process using run-time dynamic linking in this situation, but functions exported by the missing DLL are not available to the program."

I think this answers my question. Perhaps this means eclipse uses load-time dynamic linking.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追我者格杀勿论 2025-01-01 00:02:43

您如何使用 MinGW 编译 OpenCV(即,在 CMake 配置期间设置的 BUILD_TYPESSE* 选项是什么)?我问的原因是 SSE 优化存在一个已知错误,在使用 MinGW 构建版本时会导致 highgui 操作崩溃。请参阅我的其他答案 这里

How did you compile OpenCV with MinGW (i.e., what were your BUILD_TYPE and SSE* options set to during the CMake configuration)? The reason I ask, is that there is a known bug with SSE optimizations that will cause highgui operations to crash when using MinGW built versions. See my other SO answer here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文