首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV中的imread

OpenCV中的imread
EN

Stack Overflow用户
提问于 2014-12-11 13:29:43
回答 4查看 4.5K关注 0票数 0

我发现这个问题在这里被问了很多次,但我还没有找到这个问题的任何解决方案或变通办法。下面是我的代码(从这里复制:http://docs.opencv.org/doc/tutorials/introduction/display_image/display_image.html):

代码语言:javascript
复制
#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对其进行了编译,得到了不同的结果(两者都不起作用)。使用VS2008编译的程序在imread()有运行时错误,另一个显示消息“无法打开或找到图像”。

有人能帮我吗?

EN

回答 4

Stack Overflow用户

发布于 2014-12-11 15:41:25

这里的问题是C++中不存在您的main() function._tmain。main需要。

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

  1. 在解决方案资源管理器中右键单击项目,然后从菜单中选择属性
  2. 转到配置属性->调试
  3. 在属性列表中设置命令参数。

希望这能解决你的问题!

代码语言:javascript
复制
#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;
}
票数 1
EN

Stack Overflow用户

发布于 2014-12-11 13:46:14

将argv1设置为已知的图片页面"C:\test.jpg“

票数 0
EN

Stack Overflow用户

发布于 2014-12-11 15:25:32

好了,我已经读完了所有的评论,我将回答主要问题和次要问题。

为什么我的代码不能在VS2008中运行?

您的代码不能在VS2008中运行的原因是因为您使用的是2010年的编译库,至少我认为这是一个相当准确的假设。如果你想要完全准确,那么对于你正在使用的编译器,可以使用build the libraries,

什么是tmain &什么是main

This堆栈溢出问题比我回答这个问题要好得多,但它实际上是一个特定于windows的main,实际上并不存在于C++中。它会在编译时被编译器移除,并被转换为main。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27415978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档