123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- #include "StdAfx.h"
- #include "scan_common.h"
- #include "Identifor.h"
- #include <opencv\cv.h>
- #include <opencv\cxcore.h>
- #include <opencv2\opencv.hpp>
- #include "basic_struct.h"
- #include "shlwapi.h"
- using namespace cv;
- CIdentifor::CIdentifor(void)
- {
- phy_card_number =0000000L;
- m_bUseQr = false;
- }
- void CIdentifor::SetUseQr(bool bUseQr, const std::string&strQr)
- {
- m_bUseQr = bUseQr;
- m_strQr = strQr;
- }
- void CIdentifor::SetOnlineScanType(int nOnlineScanType)
- {
- m_nOnlineScanType = nOnlineScanType;
- }
- CIdentifor::~CIdentifor(void)
- {
- }
- BOOL CIdentifor::SupportPause( void )
- {
- return FALSE;
- }
- ServiceState CIdentifor::OnStarting( void )
- {
- for (int i =0;i<IDENTIFY_WORKER_COUNT;i++)
- {
- m_identify_worker[i].Start();
- }
- for (int i = 0; i < IDENTIFY_WORKER_COUNT; i++)
- {
- while (m_identify_worker[i].GetServiceSate() != running){
- Sleep(10);
- }
- }
- return IService::OnStarting();
- }
- ServiceState CIdentifor::OnRunning( void )
- {
- IplImage * img = NULL;
- IFeeder* feeder = NULL;
- CIdentifyTask* task = NULL;
- feeder_param imgparam;
- bool getImgSuccess =false;
- do
- {
- task=taskMananger->getCurrentIdentifyTask();
- if(task != NULL){
- feeder =task->GetFeeder();
- getImgSuccess =feeder->GetNext(TRUE,img,imgparam);
- if(!getImgSuccess){
- task->getResultBufferManager()->setIdentifyComplete(true);
- taskMananger->getNextIdentifyTask();
- }
- }
- } while (task!=NULL&&task!=taskMananger->MainTask()&&img == NULL);
- if(!getImgSuccess) {
- return stoping;
- }
- CResultManager * m_main_result_buffer =task->getResultBufferManager();
- OMR_RESULT * out_result = m_main_result_buffer->getNextResult();
- CIdentifyWorker * worker = GetWorker();
- worker->SetUseQr(m_bUseQr, m_strQr);
- CString timeString =GetTimeString();
- OMR_RESULT& omr_result= *(out_result);
- omr_result.reset();
- switch(imgparam.type){
- case identyfi_type_normal:
- omr_result.phy_card_number =++phy_card_number;
- break;
- case identyfi_type_reidentify:
- omr_result.phy_card_number = imgparam.phy_number;
- omr_result.paper_id = imgparam.paper_id;
- break;
- case identyfi_type_manualmatch:
- omr_result.phy_card_number = imgparam.phy_number;
- omr_result.paper_id = imgparam.paper_id;
- break;
- }
- if(imgparam.srcimg_type==SRC_IMG_HANDLE_TYPE_COPY){
- string img_path0=imgparam.img_path;
- CStringA img_name = PathFindFileNameA(img_path0.c_str());
-
- CString img_path;
- img_path.Format(_T("%s\\%s"), m_exc_img_dir, CString(img_name));
- char img_path_c[520];
- WideCharToMultiByte(CP_ACP, 0, img_path, -1, img_path_c, 520, NULL, NULL);
- omr_result.img_path = img_path_c;
- omr_result.img_oldpath = imgparam.img_path;
- CopyFile(CString(imgparam.img_path.c_str()),img_path,FALSE);
- }else if(imgparam.srcimg_type==SRC_IMG_HANDLE_TYPE_SAVE){
- CString img_path;
- img_path.Format(_T("%s\\%06d.jpg"), m_exc_img_dir, omr_result.phy_card_number);;
- char img_path_c[520];
- WideCharToMultiByte(CP_ACP, 0, img_path, -1, img_path_c, 520, NULL, NULL);
- omr_result.img_path = img_path_c;
- omr_result.img_oldpath = imgparam.img_path;
- cvSaveImage(omr_result.img_path.c_str(),img);
- }else{
- omr_result.img_path = imgparam.img_path;
- omr_result.img_oldpath = imgparam.img_path;
- }
- switch(imgparam.type){
- case identyfi_type_normal:
- omr_result.paper_id=-1;
- worker->Identify(img,out_result,m_main_result_buffer->getBufferstate(out_result));
- break;
- case identyfi_type_reidentify:
- case identyfi_type_manualmatch:
- omr_result.paper_id = imgparam.paper_id;
- worker->Identify(img, out_result, m_main_result_buffer->getBufferstate(out_result));
- break;
- }
- return running;
- }
- ServiceState CIdentifor::OnPausing( void )
- {
- return IService::OnPausing();
- }
- ServiceState CIdentifor::OnResuming( void )
- {
- return IService::OnResuming();
- }
- ServiceState CIdentifor::OnStoping( void )
- {
- for (int i=0;i<IDENTIFY_WORKER_COUNT;i++)
- {
- m_identify_worker[i].Stop();
- }
- for (int i=0;i<IDENTIFY_WORKER_COUNT;i++)
- {
- while(m_identify_worker[i].GetServiceSate() != stoped){
- Sleep(10);
- }
- }
- return IService::OnStoping();
- }
- int CIdentifor::GetMubanCount()
- {
- return m_schema->size();
- }
- void CIdentifor::SetExcImgDir( CString img_dir )
- {
- m_exc_img_dir = img_dir;
- }
- BOOL CIdentifor::LoadSchema(const boost::shared_ptr<const ISCH_Schema>& schema)
- {
- m_schema = schema;
- for (int i=0;i<IDENTIFY_WORKER_COUNT;i++)
- {
- m_identify_worker[i].LoadSchema(m_schema);
- }
- m_isMubanLoaded = (schema == NULL|| schema->size()==0)?FALSE:TRUE;
- return m_isMubanLoaded;
- }
- BOOL CIdentifor::IsMubanLoaded()
- {
- return m_isMubanLoaded;
- }
- void CIdentifor::IdentifyTaskManager( CIdentifyTaskManager* taskManager )
- {
- this->taskMananger = taskManager;
- }
- CIdentifyWorker * CIdentifor::GetWorker()
- {
- CIdentifyWorker * worker =NULL;
- do{
- for (int i=0;i<IDENTIFY_WORKER_COUNT;i++)
- {
- if(m_identify_worker[i].GetIdentifyState() == CIdentifyWorker::IS_WAITING){
- worker = &m_identify_worker[i];
- break;
- }
- }
- if(worker == NULL)Sleep(10);
- } while(worker ==NULL);
- return worker;
- }
- void CIdentifor::Reset()
- {
- phy_card_number =0000000L;
- }
|