繁体   English   中英

OpenCV 中的 findContours 函数错误

[英]findContours function error in OpenCV

我正在尝试运行以下代码(仅发布其中的一部分)

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>

using namespace cv;
using namespace std;

/// Global variables
Mat erosion_dst, dilation_dst,adt,dst;
Mat threshold_output;

int erosion_elem = 0;
int erosion_size = 15;
int dilation_elem = 0;
int dilation_size = 0;
int const max_elem = 2;
int const max_kernel_size = 21;

/** Function Headers */
void Erosion( int, void* );
void Dilation( int, void* );

Mat src; Mat src_gray;
Mat denoised,blur_image;
int thresh = 100;
int max_thresh = 255;
RNG rng(12345);

// Function header
//void thresh_callback(int, void* );

vector<vector<Point> > contours;

vector<Vec4i> hierarchy;
// Approximate contours to polygons + get bounding rects and circles


/* @function main */
int main( int argc, char** argv )
{   
    tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();


    int count; 
    char *outText;


    // Initialize tesseract-ocr with English, without specifying tessdata path
    if (api->Init(NULL, "eng")) {
        fprintf(stderr, "Could not initialize tesseract.\n");
        exit(1);
    }

    // Load source image and convert it to gray
    src = imread("swine.jpg");
    fastNlMeansDenoisingColored(src, denoised,10,10,7,21 );

    GaussianBlur(denoised,blur_image,Size(5,5),0,0);
    // Convert image to gray and blur it
    cvtColor(blur_image, src_gray, COLOR_BGR2GRAY );


    // Create Window
    //char* source_window = "Source";
    //namedWindow( source_window, CV_WINDOW_AUTOSIZE );

    //imshow( source_window, src );
    adaptiveThreshold(src_gray, adt, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 11, 2);
    imwrite("Adaptive_thresholding.tif",adt);

    //Erosion
    Erosion(0,0);

    //Thresholding for contours
    //createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
    //thresh_callback( 0, 0 );
    // Detect edges using Threshold
    threshold( erosion_dst, threshold_output, thresh, 255, THRESH_BINARY );

    // Find contours
    imwrite("thresh_out.jpg",threshold_output);
    findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

    vector<Rect> boundRect( contours.size() );
    vector<vector<Point> > contours_poly( contours.size() );
    vector<Point2f> ContArea(contours.size());

现在,当我尝试编译上述内容时,它给了我以下错误:

test_rect.cpp: In function ‘int main(int, char**)’:
test_rect.cpp:88:55: error: ‘CV_RETR_TREE’ was not declared in this scope
  findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
                                                       ^
test_rect.cpp:88:69: error: ‘CV_CHAIN_APPROX_SIMPLE’ was not declared in this scope
  findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

现在,我尝试搜索解决方案,并且有一篇文章建议更改前两个包含标头以使用<>而不是双引号来搜索当前目录。 但这没有帮助。 因此,如果有人可以帮助我,我将其发布在这里。 谢谢!

如果您使用的是最新版本的 opencv,则从 CV_RETR_TREE 和 CV_CHAIN_APPROX_SIMPLE 中删除 CV。 单击此处了解更多详细信息https://docs.opencv.org/master/df/d0d/tutorial_find_contours.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM