如何让OpenCV在Windows下工作?

发布于 2024-11-10 08:34:49 字数 1993 浏览 1 评论 0 原文

我无法在 Windows 下启动 OpenCV 应用程序。

给定以下简单的 OpenCV 程序:

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>

#include "cv.h"
#include "highgui.h"

char imagename[100] = "sudoku.jpg";

IplImage* img;

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

    cvNamedWindow("Example4", CV_WINDOW_AUTOSIZE);
    IplImage* img = cvLoadImage(imagename);

    cvShowImage("Example4", img);
    cvWaitKey(0);
    cvDestroyWindow("Example4");
    return (0);
}

我可以编译并开始使用预编译的 OpenCV 库版本 2.2,引用的图像出现在窗口中。 (编译确实使用 netbeans 和 cygwin 或自己的 makefile(包含 5 行和 minGW)进行工作。 然后我想在 OpenCV 中使用 C++ 函数调用,但编译不起作用,所以基于 这个答案我决定按照这个安装指南此入门指南。

使用 minGW 和 CMake OpenCV 进行编译,没有任何抱怨。我没有使用任何可选包进行 opencv 编译。

不幸的是,无法启动任何程序,因为只出现一个灰色窗口,之后应用程序崩溃,并且 Windows 给出以下错误消息:

Problem signature:
  Problem Event Name:   APPCRASH
  Application Name: main.exe
  Application Version:  0.0.0.0
  Application Timestamp:    4de3a2d9
  Fault Module Name:    libopencv_highgui220.dll
  Fault Module Version: 0.0.0.0
  Fault Module Timestamp:   4dcd07e6
  Exception Code:   c0000005
  Exception Offset: 0002def4
  OS Version:   6.1.7600.2.0.0.256.4
  Locale ID:    1033
  Additional Information 1: 0a9e
  Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
  Additional Information 3: 0a9e
  Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

可能是什么问题?

我尝试使用我自己的 Makefile 和 Cmake-gui 从 Netbeans 进行编译,并且执行程序的创建没有问题。我已将 opencv bin 目录包含在 PATH 中,以使提到的 libopencv_highgui220.dll 可见。

更新:

按照前面的过程,我在 Windows XP Professional 上得到了完全相同的结果:opencv 和项目构建正常,但运行挂起。本机上没有其他可能干扰我的opencv编译的C、C++、编译器和IDE。

I could not start an OpenCV application under Windows.

Given the following simple OpenCV program:

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>

#include "cv.h"
#include "highgui.h"

char imagename[100] = "sudoku.jpg";

IplImage* img;

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

    cvNamedWindow("Example4", CV_WINDOW_AUTOSIZE);
    IplImage* img = cvLoadImage(imagename);

    cvShowImage("Example4", img);
    cvWaitKey(0);
    cvDestroyWindow("Example4");
    return (0);
}

I can compile and start using a precompiled OpenCV libraries version 2.2, the referenced image appears in a window. (The compilation did work using netbeans and cygwin or own makefile with 5 lines and minGW).
Then I wanted to use C++ function calls in OpenCV but the compilation did not work so based on this answer I have decided to recompile OpenCV following this installation guide and this getting started guide.

Using minGW and CMake OpenCV had been compiled without complaints. I did not use any optional package for opencv compilation.

Unfortunately no program could be started because only a grey window appears and after while the application crashes and the following error message is given by Windows:

Problem signature:
  Problem Event Name:   APPCRASH
  Application Name: main.exe
  Application Version:  0.0.0.0
  Application Timestamp:    4de3a2d9
  Fault Module Name:    libopencv_highgui220.dll
  Fault Module Version: 0.0.0.0
  Fault Module Timestamp:   4dcd07e6
  Exception Code:   c0000005
  Exception Offset: 0002def4
  OS Version:   6.1.7600.2.0.0.256.4
  Locale ID:    1033
  Additional Information 1: 0a9e
  Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
  Additional Information 3: 0a9e
  Additional Information 4: 0a9e372d3b4ad19135b953a78882e789

What could be the problem?

I tried to compile from Netbeans, with my own Makefile and with Cmake-gui and the executives were created without problem. I have included the opencv bin dir in the PATH to make the mentioned libopencv_highgui220.dll visible.

Update:

Following the previous procedure I got the exact same result on a Windows XP Professional: opencv and project building is OK, but running hangs. There are no other C, C++, compilers and IDEs on this machine that may interfere with my opencv compilation.

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

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

发布评论

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

评论(2

久夏青 2024-11-17 08:34:49

我已经在 opencv 论坛上发布了同样的问题,我得到了答案。

问题是我使用 lib 或 bin opencv 目录进行链接和 PATH。使用安装指南,我发现我必须使用 lib 目录作为链接,使用 bin 目录作为 PATH。 lib 中的 dll.a 和 bin 中的 dll 的组合使用对我来说是新的。

所以我按照 CodeBlocks+MinGW 指南一步步解决了问题,而且
当我使用之前在没有 CodeBlocks 的情况下构建的 MinGW opencv 时,C 或 C++ 代码都可以正确运行。

I have posted the same question at opencv forum and I got an answer.

The problem was that I used either the lib or the bin opencv directory for linking and the PATH. Using the install guide it turned out to me that I have to use the lib directory for the linking and bin directory for the PATH. The combined usage of dll.a in lib and dll in bin was new to me.

So I have followed the CodeBlocks+MinGW guide step by step to solve the problem, moreover
when I use my previous MinGW opencv built without CodeBlocks either the C or the C++ code run correctly.

好菇凉咱不稀罕他 2024-11-17 08:34:49

我想我已经找到了在 Windows 中安装 OpenCV 并在大多数 IDE 中使用它的详细说明:http://techarenagadgetz.in/2012/12/configuring-opencv-2-4-2-for-codeblocks-and-similar-ides/

I thk I have found a detailed description for installing OpenCV in Windows and using it in most of the IDEs from here : http://techarenagadgetz.in/2012/12/configuring-opencv-2-4-2-for-codeblocks-and-similar-ides/

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