【问题标题】:g++ openCV compile error on line that doesn't existg ++ openCV编译错误在线不存在
【发布时间】:2014-07-27 06:09:00
【问题描述】:

我正在尝试使用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;
}

【问题讨论】:

  • 请避免 any 代码,其中包含 IplImages 或使用 opencv/*** c-api 标头。这一切都已弃用,他们已经在 2010 年迁移到 c++。
  • 这段代码是一个奇怪的组合。 .hpps 和 cv2 不都是 C++ 的吗?

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


【解决方案1】:

“我能做些什么来纠正这个问题?”

改用 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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 2020-08-26
    • 2012-12-31
    相关资源
    最近更新 更多