123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #pragma once
- #include <opencv2/opencv.hpp>
- #include <opencv2/xfeatures2d.hpp>
- #include "identify_struct.h"
- #include "schema_struct.h"
- #include <vector>
- #include <boost/smart_ptr.hpp>
- using namespace std;
- using namespace cv;
- using namespace cv::ml;
- using namespace cv::xfeatures2d;
- using namespace identify::schema;
- using namespace identify::result;
- using namespace identify::analysis;
- namespace identify{
- class CResultReader
- {
- public:
- CResultReader(void);
- ~CResultReader(void);
- bool m_nBxuanxiang;
- public:
- int ReadResult(const IplImage* img, int schemaIndex, cv::Mat transform, double scale, int dir, OMR_RESULT* out_result);
- int ReadResult(int shemaIndex);
- void SetSchemaPages(boost::shared_ptr<const ISCH_Schema>schema);
- private:
- //模板
- boost::shared_ptr<const ISCH_Schema>schemaPages;
- //源图像
- const IplImage *src;
- int m_pageDirection;
- double m_Scaler0;
- Mat m_AffineTransform;//防射变换(由模板变换到图像)
- AnalyseResult anlyseResult;
- int dianshu_meihaomi;
- OMR_RESULT* omr_result;
- std::vector<cv::Point2f> point_muban;
- std::vector<cv::Point2f> point_shijuan;
- cv::Ptr<cv::ml::KNearest> knn;
- private:
- template<typename T1, typename T2 >
- double GetDistance(T1 point1, T2 point2)
- {
- double dx = point1.x - point2.x;
- double dy = point1.y - point2.y;
- return sqrt(dx*dx + dy*dy);
- }
- //截取图像
- int ClipImg(const ISCH_SCHEMA_PAGE& schemaPage);
- /************************************************************************/
- /* 设置识别结果默认值 */
- /************************************************************************/
- void SetDefaultOMR_Result(OMR_RESULT& omr_result);
- template<typename T1, typename T2> T2 warpAffinePoint(T1& src, Mat * map_matrix);
- template<typename T1> CvRect GetResultRect(T1& item);
- template<typename T1> CvRect GetJiaoZhengResultRect(T1& item);
- template<typename T1, typename T2> T2 GetJiaoZhengResultPoint(T1& point);
- template<class T> void SaveRect(CvRect& rect, T& result);
- //读取二维码
- int ReadBarCode(const ISCH_SCHEMA_PAGE& schemaPage);
- unsigned char(*_GetGray)(const IplImage * dst, int x, int y);
- unsigned char GetGray(const IplImage * dst, int x, int y);
- //获取全局背景灰度,通过统计所有涂点周围像素(灰度不小于160)的灰度平均值获得
- int caculate_global_background(const ISCH_SCHEMA_PAGE& schemaPage);
- //计算涂点属性
- int caculate_cell_property(ISCH_SCHEMA_PAGE& schemaPage, ISCH_SCHEMA_ITEM &item, const IplImage * dst, int &cellSize, double &refArea, double &avg_gray, int &grayNum, double &mo_hu_du, double &gao_heidu, int &char_area_size, int& char_area_black_count, double& char_area_avg_gray, int & diheidushu);
- int caculate_item_property(const ISCH_SCHEMA_PAGE& schemaPage, const ISCH_SCHEMA_ITEM &item, const IplImage * dst, AnalyseResult::itemResult& item_result);
- void GetCorrectedRect(CvRect &rr, const IplImage * src, int tembackcolor);
- //分析全局属性
- int analyseOmrPanoramic(ISCH_SCHEMA_PAGE& schemaPage);
- /************************************************************************/
- /* 生成OMR涂点字符串(客观题填涂判断) 2014年11月28日10:54:19 */
- /************************************************************************/
- int GenerateOmrStr(const ISCH_SCHEMA_PAGE& schemaPage);
- //读取客观题分数
- int ReadKeGuanTi(const ISCH_SCHEMA_PAGE &schemaPage);
- int ReadDingWeiDian(const ISCH_SCHEMA_PAGE& schemaPage);
- void caculate_item_global_property(const ISCH_SCHEMA_PAGE & schemaPage);
- int findAssitLocate(const ISCH_SCHEMA_PAGE& schemaPage);
- //读取填空题,和主观题分数
- int ReadQuestionScore(const ISCH_SCHEMA_PAGE &schemaPage);
- //获取图像指定区域红色点数(主观题) 去除长直线和周边像素 减少直线边缘偏色影响
- int GetZhuGuanTiRedCount(IplImage * dst, const CvRect& rect, const CvRect& normal_rect, int * red_counts, int * red_in_counts, int count);
- //获取图像指定区域红色点数(填空题)
- int GetTianKongTiRedCount(IplImage * dst, const CvRect& rect_normal, const CvRect& rect_detect);
- BOOL GetRedBinary(IplImage * dst, const CvRect& rect_detect, IplImage ** red_binary);
- };
- }
|