我正在尝试运行以下代码(仅发布一部分代码)
#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) );
现在,我尝试搜索解决方案,一篇帖子建议更改前两个包含标题,以使用<>
而不是双引号来搜索当前目录。但这没有帮助。因此,如果有人能帮助我,我会在这里发布。谢谢!
答案 0 :(得分:0)
如果您使用的是最新版本的opencv,请从CV_RETR_TREE和CV_CHAIN_APPROX_SIMPLE中删除CV。 点击此处了解更多详细信息https://docs.opencv.org/master/df/d0d/tutorial_find_contours.html