簡體   English   中英

不存在的g ++ openCV編譯錯誤

[英]g++ openCV compile error on line that doesn't exist

我正在嘗試使用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;
}

“我該怎么做才能糾正這一點?”

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM