123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #pragma once
- #include <opencv.hpp>
- #include <map>
- #include <opencv2\imgproc\imgproc.hpp>
- #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<int, int>&,bool is_base=false);
- // virtual double angle_fit_base(map<int, int>&);// 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<int, int> m_an2width;
- // map<int, int> m_an2widthBase;
- // // 图像处理函数
- // // 返回min_idx左侧x,max_idx右侧x
- // int imgproc(
- // Mat&,
- // vector<int>& hist,
- // int& min_idx,
- // int& max_idx);
- // int imgprocBase(
- // Mat&,
- // vector<int>& hist,
- // int& min_idx,
- // int& max_idx);
- //
- // // 清理释放m_pImginfo
- // void clear_imginfo();
- //
- // //茎分叉点y值系列
- // vector<int> m_fork_ys;
- //
- // //茎最低点y值系列
- // vector<int> m_end_ys;
- //
- // //叶展宽度系列
- // vector<int>m_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<int, int>&,bool is_base=false);
- // double angle_fit_base(map<int, int>&);// for base matter
- //protected:
- // //zero_cross_detect()
- // //过零点检测,用于确定是否单调(增或减),局部最小,局部最大,
- // //并返回局部极值index
- // void zero_cross_detect(
- // vector<int>&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<double>&x, //sorted, ascending
- // vector<double>&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<double>&x, //sorted, ascending
- // vector<double>&y,
- // bool is_base=false);
- //};
- // CCotyledonAngle
- // 顶部拍照砧木,通过子叶角度识别,提供机构旋转角度
- class CCotyledonAngle{
- public:
- CCotyledonAngle(ConfigParam&, CGcvLogger* pLog=0);
- virtual ~CCotyledonAngle();
- int angle_recognize(ImgInfo*,
- PositionInfo& posinfo
- );
- void set_image_saver(CImStoreManager** ppis)
- {
- m_ppImgSaver=ppis;
- }
- protected:
- //global configure parameters
- ConfigParam& m_cparam;
- CGcvLogger* m_pLogger;
- string m_imgId;
- CImStoreManager** m_ppImgSaver;
- //all image size
- cv::Mat m_grayImg;
- cv::Mat m_binImg;
- int m_width;
- int m_height;
- cv::Mat m_openImg; // for save
- //返回图片,用于调试
- ImgInfo* m_pImginfoOpen;//fork-y, right-x
- ImgInfo* m_pImginfoAngle;//corners, reference-point, candidate box
-
- //
- typedef struct {
- double area;
- double centx;
- double centy;
- cv::RotatedRect minrect_ellips;
- vector<cv::Point> contours;
- } t_leaf;
- void img_segment(cv::Mat&img);
- double fit_error_ellipse(cv::RotatedRect&ellipse_rect,vector<cv::Point>& pts);
- void get_ellipse_param(cv::RotatedRect&ellipse_rect, //input
- float&A, float&B, float&C, float&F); //output
- void clear_imginfo();
- };
- };
|