【发布时间】:2013-07-04 06:05:57
【问题描述】:
很抱歉提出这样一个初学者问题,但我对 openCV 和 VC++2010 真的很陌生。我在网上搜索了答案,但没有找到合适的答案。
构建OReilly-LearningOpenCV这本书的第一个项目“First Program-Display a Picture”,遇到了这些错误:
1-error C2664: 'cvLoadImage' : cannot convert parameter 1 from '_TCHAR *' to 'const char *'
2-IntelliSense: argument of type "_TCHAR *" is incompatible with parameter of type "const char *"
代码如下:
#include "stdafx.h"
#include "opencv\highgui.h"
int _tmain(int argc, _TCHAR* argv[])
{ IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
system("pause");
return 0;
}
这是我从 Microsoft Visual Studio 2010 得到的信息:
1>------ Build started: Project: FirstProgram_DisplayAPicture3, Configuration: Debug x64 ------
1>Build started 7/6/2013 11:13:00 AM.
1>InitializeBuildStatus:
1> Touching "x64\Debug\FirstProgram_DisplayAPicture3.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1> FirstProgram_DisplayAPicture3.cpp
1>FirstProgram_DisplayAPicture3.cpp(9): error C2664: 'cvLoadImage' : cannot convert parameter 1 from '_TCHAR *' to 'const char *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.68
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
可能需要的其他信息:
我制作了一个 win32 控制台应用程序,并在向导的第二页中选择了预编译头设置。
我已将项目的平台更改为 x64,因为我使用的是 win7x64 作为操作系统。
我已将 openCV 库正确链接到我的项目。
我刚刚介绍了 highgui.lib 作为附加依赖项
任何帮助将不胜感激。
我该怎么做才能解决这两个错误?
编辑部分:
请注意,这些错误发生在第 6 行,我的意思是 IplImage* img = cvLoadImage( argv[1] );
我根据 Roger Rowland 的建议编辑的部分:
根据 Roger Rowland 所说,我将项目的 Character Set 属性更改为 Not Set。上面提到的两个错误得到了解决,但是这些错误上升了。
错误 LNK1120:1 个未解决的外部问题
错误 LNK2019:函数 main 中引用的未解析的外部符号 cvReleaseImage
我该如何解决这个问题?
【问题讨论】:
-
您的项目属性显然指定了 UNICODE,因此要么更改项目属性,要么修改您的代码以在带引号的字符串周围使用
_T宏,例如cvShowImage(_T("Example1"), img ); -
感谢@Roger Rowland,但我测试了您的建议并尝试在引用字符串周围使用 T。错误增加到 5 个数字。我的意思是除了第 6 行“IplImage* img = cvLoadImage(argv[1]);”产生了上面的两个错误,我们将有一个错误 IntelliSense: argument of type "const wchar_t *" is incompatible with parameter of type "const char *" 在每行有引号的字符串,我没有' t 理解您说 _enhance the project properties 的目的
-
您需要在 T 前加一个下划线,或者使用
TEXT("string")代替_T("string")。如果做不到,请在 VS2010 解决方案资源管理器面板中右键单击您的项目,从菜单中选择 Properties,然后在 Configuration Properties/General 下找到它说 Character Set 并将其更改为 Not Set。 -
@Roger Rowland using TEXT("string") 将产生错误 IntelliSense: identifier "TEXT" is undefined 并且粗略的我使用了 _T 而不仅仅是 T。这里有一种错字,但我还没有尝试更改项目属性,我现在就这样做。
-
@Roger Rowland 我尝试更改项目属性。它省略了提到的两个错误,但出现了另外两个错误。请查看“我根据 Roger Rowland 的建议编辑的部分”我会在一分钟内更新它。
标签: visual-studio-2010 opencv image-processing char type-conversion