2013-04-16 21 views
7

我在Ubuntu 12.04上使用OpenCV2。我可以成功運行圖像讀取顯示代碼。 但是我不能運行內置函數的代碼,例如。 cvtColor()Opencv2 cvtColor()不起作用

#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp> 

#include <stdio.h> 

int main(int argc, char *argv[]) 
{ 
    cv::Mat image = cv::imread("img.jpg"); 

    if(image.data == NULL) 
    { 
     printf("file cannot be loaded\n"); 
     return 1; 
    } 

    cv::namedWindow("My"); 
    cv::imshow("My", image); 

    cv::Mat result; 
    cv::cvtColor(image, result, CV_BGR2Luv); 

    cv::imwrite("outImg.jpg", result); 

    cv::waitKey(0); 

    return 0; 
} 

我使用Qt的創造者爲我的OpenCV 與--libs編譯後,--cflags我獲得以下編譯器錯誤:

make: Entering directory `/home/swaroop/Work/ai-junkies/cuda/uc_davis/opencv2.x/OpenCV2Test' 
g++ -g -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4 -I/usr/include/opencv -I. -o main.o main.cpp 
main.cpp: In function 'int main(int, char**)': 
main.cpp:22:29: error: 'CV_BGR2Luv' was not declared in this scope 
main.cpp:22:39: error: 'cvtColor' was not declared in this scope 

請幫我解決這個問題。在opencv2/imgproc/imgproc.hpp

宣佈

回答

16

cvtColor記住它的的#include沒有#IMPORT

#include <opencv2/imgproc/imgproc.hpp> 
+0

你是對的。我不得不#include 。 – mkuse

+0

有沒有一種簡單的方法可以知道(不詢問)包含哪些頭文件? – PaulrBear

6

或者,如果你正在測試的東西,而不是關心矯枉過正的包括,你可以簡單地有一個line:

#include <opencv2/opencv.hpp> 

它會包含大部分的opencv2頭文件。