123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- // Identifier.cpp : 定义 DLL 应用程序的导出函数。
- //
- #include "stdafx.h"
- #include "Identifier.h"
- #include "Util.h"
- #include "PageMatcher.h"
- #include "ResultReader.h"
- #include "../lib/myqr/include/GetQRCode.h"
- namespace identify{
- IDENTIFIER_API int PraseQRCode_Normal2(IplImage* img, std::string & resultString)
- {
- return PraseQRCode_Normal(img, resultString);
- }
- // 这是已导出类的构造函数。
- // 有关类定义的信息,请参阅 Identifier.h
- CIdentifier::CIdentifier()
- {
- m_bUseQr = false;
- m_isMuBanLoaded = false;
- }
- void CIdentifier::SetUseQr(bool bUseQr, const std::string&strQr)
- {
- m_bUseQr = bUseQr;
- m_strQr = strQr;
- }
- int CIdentifier::Identify2(const IplImage* img, OMR_RESULT* out_result)
- {
- int ret;
- MATCH_REUSLT match_result;
- ret = pm.Identify(img, match_result);
- if (ret != IDF_SUCCESS){
- OMR_RESULT * r = (OMR_RESULT*)out_result;
- r->identified = FALSE;
- return ret;
- }
- int page_index = match_result.schema_index;
- cv::Mat transform(2, 3, CV_64F, match_result.transfrom);
- double scale = match_result.scale;
- ret = rr.ReadResult(img, page_index, transform, scale, match_result.dir, out_result);
- if (ret == IDF_SUCCESS){
- OMR_RESULT * r = (OMR_RESULT*)out_result;
- r->identified = TRUE;
- return ret;
- }
- return ret;
- }
- CIdentifier::~CIdentifier(void)
- {
- }
- void CIdentifier::LoadMuban2(const boost::shared_ptr<const ISCH_Schema>& schema)
- {
- m_schema = schema;
- pm.SetSchemaPages(schema);
- rr.SetSchemaPages(schema);
- m_isMuBanLoaded = true;
- }
- int CIdentifier::GetMubanPageCount()
- {
- return m_schema == NULL ? 0 : m_schema->size();
- }
- int CIdentifier::Identify3(const IplImage* img, int schema_index, const std::vector<Point2f>& muban, const std::vector<Point2f>& shijuan, OMR_RESULT* out_result)
- {
- if (muban.size() != 3 || shijuan.size() != 3)return IDF_FAILURE;
- MATCH_REUSLT match_result;
- {
- cv::Mat transform = getAffineTransform(muban, shijuan);
- Point2f src[3] = { Point2f(0, 0), Point2f(1000, 0), Point2f(0, 1000) };
- Point2f dst[3] = { warpAffinePoint<Point2f, Point2f>(src[0], &transform), warpAffinePoint<Point2f, Point2f>(src[1], &transform), warpAffinePoint<Point2f, Point2f>(src[2], &transform) };
- double d_src[3] = { GetDistance(src[0], src[1]), GetDistance(src[0], src[2]), GetDistance(src[1], src[2]) };
- double d_dst[3] = { GetDistance(dst[0], dst[1]), GetDistance(dst[0], dst[2]), GetDistance(dst[1], dst[2]) };
- double scales[3] = { d_dst[0] / d_src[0], d_dst[1] / d_src[1], d_dst[2] / d_src[2] };
- double dscale[3] = { abs(scales[0] - scales[1]), abs(scales[0] - scales[2]), abs(scales[1] - scales[2]) };
- double scale = max(max(dscale[0], dscale[1]), dscale[2]);
- if (scale > 0.15)return IDF_FAILURE;
- double m_Scaler0 = d_dst[0] / d_src[0];
- match_result.matched = true;
- match_result.schema_index = schema_index;
- float x = dst[1].x - dst[0].x;
- float y = dst[1].y - dst[0].y;
- int dir;
- if (abs(x) > abs(y)){
- if (x > 0){
- dir = ROTATION_0;
- }
- else{
- dir = ROTATION_180;
- }
- }
- else{
- if (y > 0){
- dir = ROTATION_270;
- }
- else{
- dir = ROTATION_90;
- }
- }
- match_result.dir = dir;
- match_result.matched_count = 0;
- match_result.scale = m_Scaler0;
- match_result.total_count = 0;
- memcpy(match_result.transfrom, transform.data, sizeof(match_result.transfrom));
- }
- int page_index = match_result.schema_index;
- cv::Mat transform(2, 3, CV_64F, match_result.transfrom);
- double scale = match_result.scale;
- int ret = rr.ReadResult(img, page_index, transform, scale, match_result.dir, out_result);
- if (ret == IDF_SUCCESS){
- OMR_RESULT * r = (OMR_RESULT*)out_result;
- r->identified = TRUE;
- return ret;
- }
- return IDF_SUCCESS;
- }
- }
|