在vs2012中使用opencv加载和显示图像

Loading and displaying image using opencv in vs2012


感谢大家的回复!
我在命令参数中添加了 ..\wavFile.wav 。

但是我还是不能使用命令window。
它仍然弹出并立即关闭。
可能是因为我使用控制台应用程序 运行 这个程序?
还是有其他原因?


我是 opencv 的新手,我尝试了以下代码来加载和显示图像
(使用 visual studio 2012)
我 运行 它使用调试模式,但我总是得到 window 显示
用法:display_image ImageToLoadAndDisplay,window 立即关闭
(好像 argc 总是等于 2?)
window 不会留在那里等待加载我的图像的命令。

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
   if( argc != 2)
    {
      cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
      return 0;
    }
    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;
    }
    cvNamedWindow( "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;
 }

可能是一个很愚蠢的问题,但我真的想了很久都想不通。
希望可以有人帮帮我!非常感谢!

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

来源:

Mozilla.org FAQ on debugging Mozilla on Windows 在这里很有趣。

简而言之,Visual Studio 调试器可以从命令行在程序上调用,允许在调用命令行程序时直接在命令行上指定命令行参数。

对于 Visual Studio 8 或 9

,这看起来像以下内容

devenv /debugexe 'program name' 'program arguments' 也可以使用 explorer action 在 Visual Studio 调试器中启动程序。

来源:Debugging with command-line parameters in Visual Studio