Opencv2 cvtColor()不起作用

时间:2013-04-16 09:03:37

标签: qt opencv

我在Ubuntu 12.04上使用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;
}

我正在为我的OpenCV使用Qt-creator 用--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

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:19)

cvtColor

中声明的

opencv2/imgproc/imgproc.hpp

请记住, #include 不是#import

#include <opencv2/imgproc/imgproc.hpp>

答案 1 :(得分:8)

或者,如果您正在测试内容并且不关心过度使用包含,那么您只需要一行:

#include <opencv2/opencv.hpp>

它将包含大多数opencv2标头。

相关问题