将轮廓传递给方法/功能-类型是什么?

时间:2019-03-02 11:28:26

标签: c++ opencv

如何将轮廓传递给方法/功能?轮廓的类型是什么?

std::vector<std::vector<cv::Point>> contours;
cv::findContours(diff, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
detect_contour_shape(contours[0]);

int Txtbin::detect_contour_shape(const std::vector<cv::Point>& contour, double precision=0.05){
    std::vector<cv::Point> approx;
    cv::approxPolyDP(contour, approx, cv::arcLength(contour, true) * precision, true);

    switch(approx.size()){
        case 4:
            return SHAPE_RECT;

        default:
            return SHAPE_UNKNOWN;
    }
}

错误

In file included from txtbin.cpp:11:0:
txtbin.hpp: In member function ‘void Txtbin::remove_noise(cv::Mat&)’:
txtbin.hpp:209:39: error: no matching function for call to ‘Txtbin::detect_contour_shape(__gnu_cxx::__alloc_traits<std::allocator<std::vector<cv::Point_<int> > > >::value_type&)’
    if(detect_contour_shape(contours[i]) == SHAPE_RECT){
                                       ^
txtbin.hpp:209:39: note: candidate is:
In file included from txtbin.hpp:6:0,
                 from txtbin.cpp:11:
txtbin.h:61:7: note: int Txtbin::detect_contour_shape(const std::vector<cv::Point_<int> >&, double)
   int detect_contour_shape   (const std::vector<cv::Point>& contour, double precision);
       ^
txtbin.h:61:7: note:   candidate expects 2 arguments, 1 provided

Txtbin类

class Txtbin{
    public:
        Txtbin();

        const std::string VERSION   = "0.3.8";
        const int BLOCKSIDE         = 11;
        const double THRESHOLD      = 0.85;

        const int HIERARCHY_NEXT    = 0;
        const int HIERARCHY_PREV    = 1;
        const int HIERARCHY_CHILD   = 2;
        const int HIERARCHY_PARENT  = 3;

        const int SHAPE_UNKNOWN     = -1;
        const int SHAPE_RECT        = 0;

        void set_input              (const std::string& s);
        void set_output             (const std::string& s);
        void set_height             (int h);
        void set_width              (int w);
        void set_crop               (bool c);
        void set_deskew             (bool d);
        void set_remove_boxes       (bool r);
        void set_margin             (double m);
        void set_blockside          (int b);
        void set_threshold          (int t);
        void set_verbose            (bool v);
        void run                    ();

    private:
        std::string input           = "";
        std::string output          = "output.png";

        int max_width               = 0;
        int max_height              = 0;
        bool is_crop                = false;
        bool is_deskew              = false;
        bool is_remove_boxes        = false;
        double margin               = 0;
        int blockside               = BLOCKSIDE;    //  set greater for larger fonts in image
        bool is_verbose             = false;
        double contrast             = 0.01;         //  set smaller for lower contrast image
        double thresholding         = THRESHOLD;    //  set lower for darker images

        cv::Mat src;
        cv::Mat src_down;
        int down_multiplier;

        std::vector<std::vector<cv::Point>> text_contours;

        cv::Mat calc_block_mean_variance(cv::Mat& img);
        Textblock detect_textblock      ();
        int detect_contour_shape        (const std::vector<cv::Point>& contour, double precision);
        void remove_boxes               (cv::Mat& img);
        void remove_noise               (cv::Mat& img);
        void downsize                   ();
        cv::Mat morph_structures        (const cv::Mat& img, int kernel_type, int morph_type, int kernel_size);
        cv::Mat empty_mask              (const cv::Mat& img);
        std::string base_output         ();
        void error                      (const std::string& s);
};

0 个答案:

没有答案