g ++ openCV编译错误在线并不存在

时间:2014-07-27 06:09:01

标签: c++ opencv compiler-errors g++

我正在尝试使用gcc test.cpp -o test编译并运行以下程序。但是我收到了这个错误:

In file included from test.cpp:4:
/usr/local/include/opencv/cvaux.hpp:49:10: error: 'cvaux.h' file not found with <angled>
      include; use "quotes" instead
#include <cvaux.h>
         ^
1 error generated. 

虽然这条线不在程序中。我该怎么做才能纠正这个问题?

程序:

// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.hpp>

int main(int argc, char** argv)
{
    IplImage * pInpImg = 0;

    // Load an image from file - change this based on your image name
    pInpImg = cvLoadImage("my_image.jpg", CV_LOAD_IMAGE_UNCHANGED);
    if(!pInpImg)
        {
        fprintf(stderr, "failed to load input image\n");
        return -1;
        }

    // Write the image to a file with a different name,
    // using a different image format -- .png instead of .jpg
    if( !cvSaveImage("my_image_copy.png", pInpImg) )
        {
        fprintf(stderr, "failed to write image file\n");
        }

    // Remember to free image memory after using it!
    cvReleaseImage(&pInpImg);

    return 0;
}

1 个答案:

答案 0 :(得分:5)

&#34;我该怎么做才能纠正这个问题?&#34;

改为使用c ++ api:

// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;

int main(int argc, char** argv)
{   
    // Load an image from file - change this based on your image name
    Mat img = imread("my_image.jpg", CV_LOAD_IMAGE_UNCHANGED);

    if(img.empty())
    {
        fprintf(stderr, "failed to load input image\n");
        return -1;
    }

    // this is just to show, that you won't have to pre-alloc
    // result-images with c++ any more..
    Mat gray;
    cvtColor(img,gray,CV_BGR2GRAY);

    // Write the image to a file with a different name,
    // using a different image format -- .png instead of .jpg
    if( ! imwrite("my_image_gray.png", gray) )
    {
        fprintf(stderr, "failed to write image file\n");
    }

    // no need to release anything with c++ !   
    return 0;
}