c++ - 在 OpenCV 中读取

标签 c++ visual-studio opencv

我发现这个问题在这里已经被问过很多次了,但是我还没有找到解决这个问题的方法。这是我的代码(从这里复制:http://docs.opencv.org/doc/tutorials/introduction/display_image/display_image.html):

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;
using namespace std;


int _tmain(int argc, char** argv)
{
    if( argc != 2)
    {
        cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }

    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );   // Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.

    waitKey(0);                                          // Wait for a keystroke in the window

    return 0;
}

我使用 Visual Studio 2008 和 2010 对此进行了编译,得到了不同的结果(均无效)。使用VS 2008编译的程序在imread()处出现运行时错误,另一个提示“Could not open or find the image”。

谁能帮我解决这个问题?

最佳答案

这里的问题是你的 main() 函数。_tmain 在 C++ 中不存在。主要是。

_tmain 是微软的扩展。这是一个nice explanation这两种方法中。 此外,如果您想在 Visual Studio 中添加默认参数,请按照以下步骤操作。

  1. 在“解决方案资源管理器”中右键单击您的项目,然后从菜单中选择“属性”

  2. 转到配置属性 -> 调试

  3. 在属性列表中设置命令参数。

希望这能解决您的问题!


#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
    if( argc != 2)
    {
        cout <<"No Commandline Aurgument Found!: Usage: display_image ImageToLoadAndDisplay" << endl;
        return -1;
    }
    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file
    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }
    namedWindow( "Display window", WINDOW_AUTOSIZE );   // Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.
    waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
}

关于c++ - 在 OpenCV 中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27415978/

相关文章:

c++ - Turbo C++ cin() 不能与 gets() 一起工作

c++ - 我不明白为什么这个程序会打印 8762 作为结果

c++ - 在一个非常简单的程序中检测到内存泄漏。该怎么办?

c++ - LNK2019 : unresolved extrenal symbol when using std::ifstream

c# - 如何读取程序加载解决方案一部分的文件?

c# - ASP.NET MVC 上的 Rotativa HTML 转 PDF : how to create PDF as a landscape?

opencv - 如何将图像转换为SVM输入文件

c++ - 编译器会内联没有主体的函数吗?

qt - (Qt)一键单击后无法使用的窗口

c++ - 忽略另一个内部的连接组件