OpenCV C++从 Eclipse 启动时应用程序立即终止
我目前在使用从 Eclipse 启动的 OpenCV 获取一个非常小的应用程序时遇到问题。该应用程序从命令行启动正常,但是当我从 Eclipse 启动它时,它只是立即终止,没有任何输出。我希望至少将“Hello \o/”打印到控制台。
我发现只有当我调用与 OpenCV 相关的方法时才会发生这种情况。因此,如果我注释掉与 OpenCV 相关的所有行,我会看到“Hello \o/”打印到 Eclipse 控制台。
我假设这个问题与在运行时无法找到 OpenCV DLL 有关(我最初在命令行中偶然发现了这个问题,但通过将 OpenCV bin 目录添加到 PATH 变量来解决这个问题)。我尝试将其单独添加到 Eclipse 中的运行配置中,但这没有什么区别。
有什么想法导致这个问题吗?
我的来源:
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "Hello \\o/" << endl;
/* data structure for the image */
IplImage *img = 0;
/* check for supplied argument */
if (argc < 2) {
fprintf(stderr, "Usage: loadimg <filename>\n");
return 1;
}
/* load the image,
use CV_LOAD_IMAGE_GRAYSCALE to load the image in grayscale */
img = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR);
/* always check */
if (img == 0) {
fprintf(stderr, "Cannot load file %s!\n", argv[1]);
return 1;
}
/* create a window */
cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
/* display the image */
cvShowImage("image", img);
/* wait until user press a key */
cvWaitKey(0);
/* free memory */
cvDestroyWindow("image");
cvReleaseImage(&img);
return 0;
}
I'm currently having an issue getting a very small app using OpenCV launching from Eclipse. The application launches fine from the command line, however when I launch it from Eclipse it simply terminates immediately with no output what so ever. I would expect at least "Hello \o/" to be printed to the console.
I've found that it's only when I call a methods related to OpenCV that this happens. So if I was to comment out all the lines related to OpenCV, I would see "Hello \o/" printed to the Eclipse Console.
I'm assuming the issue is something related to not been able to find the OpenCV DLL's at runtime (I stumbled across this problem initially at the command line, but resolved this by adding the OpenCV bin directory to the PATH variable). I've tried adding this to my run configuration individually in Eclipse, but this makes no difference.
Any ideas what is causing this problem?
My Source:
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "Hello \\o/" << endl;
/* data structure for the image */
IplImage *img = 0;
/* check for supplied argument */
if (argc < 2) {
fprintf(stderr, "Usage: loadimg <filename>\n");
return 1;
}
/* load the image,
use CV_LOAD_IMAGE_GRAYSCALE to load the image in grayscale */
img = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR);
/* always check */
if (img == 0) {
fprintf(stderr, "Cannot load file %s!\n", argv[1]);
return 1;
}
/* create a window */
cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
/* display the image */
cvShowImage("image", img);
/* wait until user press a key */
cvWaitKey(0);
/* free memory */
cvDestroyWindow("image");
cvReleaseImage(&img);
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您很可能在
LD_LIBRARY_PATH
(环境变量)中缺少 OpenCV 的 lib 目录。You are most probably missing OpenCV's lib directory in
LD_LIBRARY_PATH
(environment variable).我有同样的问题。我首先检查并纠正了所有路径。
当似乎什么都不起作用时,创建一个新的工作空间对我来说很有效。
I had the same issue. I checked and corrected all the paths first.
When nothing seemed to work, creating a new workspace worked out for me.