#pragma once #include #include #include #include "data_def_api.h" #include "logger.h" #include "imstorage_manager.h" using namespace std; using namespace cv; namespace graft_cv{ // class COptimalAngle // 1. find the max angle // 2. find the clamp position // 条件:图像0度到180度间,并第一帧为0度时刻,最后一帧为180时刻 // 采用的方法:拼接数据(360度范围),通过找到两个最小点,此两点间的数据用 // 二次曲线拟合,得到对称轴x坐标,即为最优角度 class COptimalAngle { public: COptimalAngle(ConfigParam&, CGcvLogger* pLog=0); virtual ~COptimalAngle(void); int reset(); int append(ImgInfo*, PositionInfo& posinfo ); double infer(PositionInfo& posinfo);// calculate the optimal angle //fit optimal angle based m_an2width virtual double angle_fit(map&,bool is_base=false); virtual double angle_fit_base(map&);// for base matter void set_image_saver(CImStoreManager** ppis) { m_ppImgSaver=ppis; } protected: //global configure parameters ConfigParam& m_cparam; CGcvLogger* m_pLogger; string m_patch_id; CImStoreManager** m_ppImgSaver; int m_imgIndex; string m_imgId; // binary image Mat m_binImg; Mat m_binImgBase; //返回图片,用于调试 ImgInfo* m_pImginfo; ImgInfo* m_pImginfoBase; // 角度-叶展宽度(像素) map m_an2width; map m_an2widthBase; // 图像处理函数 // 返回min_idx左侧x,max_idx右侧x int imgproc( Mat&, vector& hist, int& min_idx, int& max_idx); int imgprocBase( Mat&, vector& hist, int& min_idx, int& max_idx); // 清理释放m_pImginfo void clear_imginfo(); //茎分叉点y值系列 vector m_fork_ys; //茎最低点y值系列 vector m_end_ys; //叶展宽度系列 vectorm_widths; //all image size int m_width; int m_height; }; //COptimalAnglePart, 继承自COptimalAngle //条件:图像0度到90度间,并保证>=90度范围 //方法:0-90度范围必然存在最大值或最小值,通过最大最小值局部数据 // 插值(二次曲线拟合)得到最大角度计算 class COptimalAnglePart: public COptimalAngle{ public: COptimalAnglePart(ConfigParam&, CGcvLogger*pLog=0); virtual ~COptimalAnglePart(); //fit optimal angle based m_an2width double angle_fit(map&,bool is_base=false); double angle_fit_base(map&);// for base matter protected: //zero_cross_detect() //过零点检测,用于确定是否单调(增或减),局部最小,局部最大, //并返回局部极值index void zero_cross_detect( vector&d_sign, //input bool& is_local_max, // whether exists local max int& local_limit_idx // local limit index of original vector ); double limit_min_angle( vector&x, //sorted, ascending vector&y, size_t min_idx ); // 计算y = k1*x + b1和y = k2*x + b2两条直线相交交点,x坐标 double line_cross( double k1, double b1, double k2, double b2); // double opt_angle_part_impl( vector&x, //sorted, ascending vector&y, bool is_base=false); }; };