2012-03-31 58 views
0

我試圖建立這個代碼不能建立OpenCV的文件

#include "stdafx.h" 
#include <iostream> 

#include <math.h> 
#include "opencv2/core/core_c.h" 
#include "opencv2/core/core.hpp" 
#include "opencv2/imgproc/imgproc_c.h" 
#include "opencv2/imgproc/imgproc.hpp" 
#include "opencv2/highgui/highgui_c.h" 
#include "opencv2/highgui/highgui.hpp" 

using namespace std; 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    int pixel; 

    Mat matC1_32S; 

    return 0; 
} 

,我得到一個錯誤:

1>c:\test1\test1\test1.cpp(21): error C2065: 'Mat' : undeclared identifier 
1>c:\test1\test1\test1.cpp(21): error C2146: syntax error : missing ';' before identifier 'matC1_32S' 
1>c:\test1\test1\test1.cpp(21): error C2065: 'matC1_32S' : undeclared identifier 

包括我應該有什麼額外的?還是別的什麼?

+1

;或CV ::涼蓆; – Sam 2012-03-31 18:09:24

回答

3

您沒有爲Mat提供名稱空間。如果您在編譯鏈接到OpenCV的庫這將工作:

#include "stdafx.h" 
#include <iostream> 

#include <math.h> 
#include "opencv2/core/core.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
#include "opencv2/highgui/highgui.hpp" 

using namespace std; 
int _tmain(int argc, _TCHAR* argv[]) { 
    int pixel; 

    cv::Mat matC1_32S; 

    return 0; 
} 

或者你可以_tmain前加using namespace cv;,這樣你就不必每次前言外觀。

此外,你正在過度使用#include語句。你不需要* _c.h文件。 (也許你添加這些,當你試圖找出爲什麼墊未聲明。)

0

感謝您的幫助,但要使其工作實際上我還包括以下

#ifdef _DEBUG 
    #pragma comment(lib, "opencv_core231d.lib") 
    #pragma comment(lib, "opencv_highgui231d.lib") 
    #pragma comment(lib, "opencv_imgproc231d") 
    #pragma comment(lib, "opencv_objdetect231d.lib") 

#else 
    #pragma comment(lib, "opencv_core231.lib") 
    #pragma comment(lib, "opencv_highgui231.lib") 
    #pragma comment(lib, "opencv_imgproc231.lib") 
    #pragma comment(lib, "opencv_objdetect231.lib") 

#endif 

我理解爲什麼我需要使用命名空間cv,但爲什麼我需要這些東西與編譯指示,儘管我在項目屬性中提供了庫路徑。 ('使用命名空間的簡歷中號的VisualStudio使用10

+0

你顯示編譯錯誤的錯誤,'使用namespace cv'會解決它們(儘管我會建議'cv :: Mat'而不是'使用namespace cv')。#pragma comment(lib,「opencv_core231.lib」)''是一個不同的問題,您提供了鏈接器的路徑,但鏈接器仍然不知道鏈接到哪個庫,您需要明確告訴它,也可以通過將庫添加到**項目配置屬性 - >鏈接器 - >輸入 - VisualStudio 10中的附加依賴項** – cxyzs7 2012-04-03 04:10:01

+0

非常感謝您的幫助 – 2012-04-04 00:35:39

0

你必須去properties >> C/C++ >> Avanced >> Compile As並選擇Compile as C++ code /TP 我做到了 它的工作原理