在 C++ 中使用 OpenCV 的自适应阈值

Adaptive Threshold with OpenCV in c++

我正在尝试在图像中应用自适应阈值,但我不断收到此错误消息:

threshold.cpp: In member function ‘cv::Mat filter::threshold(cv::Mat&, int&)’: threshold.cpp:20:25: error: variable or field ‘AdaptiveThreshold’ declared void void AdaptiveThreshold(img,image_final,255,ADAPTIVE_THRESH_GAUSSIAN_C,CV_THRESH_B

#include <iostream>
#include <string>
#include <math.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <fstream>
#include "filter.h"
#include <typeinfo>
using namespace std;
using namespace cv;
typedef unsigned char uchar;


cv::Mat filter::threshold(cv::Mat& in_image, int& threshold){

    cv::Mat img;
    cv::Mat image_final;
    in_image.convertTo(img, CV_8UC1);
    void     AdaptiveThreshold(img,image_final,255,ADAPTIVE_THRESH_GAUSSIAN_C,CV_THRESH_BINARY,13,0);


return image_final;

}

删除 'void' 因为它是对函数的调用而不是 definition/declaration。

除了删除“void”之外,还将 AdaptiveThreshold 更改为“adaptiveThreshold”。所以你程序中的相应命令如下所示。

adaptiveThreshold(img,image_final,255,ADAPTIVE_THRESH_GAUSSIAN_C,THRESH_BINARY,13,0);

我认为你需要使用

cv::adaptiveThreshold(img,image_final,255,ADAPTIVE_THRESH_GAUSSIAN_C,CV_THRESH_BINARY,13,0);