CManualMatchFeeder.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "StdAfx.h"
  2. #include "CManualMatchFeeder.h"
  3. CManualMatchFeeder::CManualMatchFeeder(void)
  4. {
  5. m_img =NULL;
  6. InitializeCriticalSection(&m_img_lock);
  7. }
  8. CManualMatchFeeder::~CManualMatchFeeder(void)
  9. {
  10. DeleteCriticalSection(&m_img_lock);
  11. }
  12. BOOL CManualMatchFeeder::SupportPause()
  13. {
  14. return FALSE;
  15. }
  16. BOOL CManualMatchFeeder::SupportStop()
  17. {
  18. return FALSE;
  19. }
  20. bool CManualMatchFeeder::GetNext( BOOL wait,IplImage* & img, feeder_param& param )
  21. {
  22. do
  23. {
  24. BOOL isStoped = m_serviceState == stoped;
  25. if(m_img!=NULL){
  26. EnterCriticalSection(&m_img_lock);
  27. if(m_img!=NULL){
  28. img = m_img;
  29. param.type = identyfi_type_manualmatch;
  30. param.srcimg_type = SRC_IMG_HANDLE_TYPE_NONE;
  31. param.paper_id = m_param->paper_id;
  32. param.phy_number = m_param->phy_number;
  33. param.schema_index = m_param->schema_index;
  34. param.img_path = m_param->img_path;
  35. for (int i=0;i<3;i++)
  36. {
  37. param.x_m[i]=m_param->x_m[i];
  38. param.y_m[i]=m_param->y_m[i];
  39. param.x_s[i]=m_param->x_s[i];
  40. param.y_s[i]=m_param->y_s[i];
  41. }
  42. // printf("重新扫描加载图片: paper_id=%d phy_number=%d 路径:%s", param.paper_id, param.phy_number, param.img_path);
  43. m_img =NULL;
  44. LeaveCriticalSection(&m_img_lock);
  45. return true;
  46. }
  47. LeaveCriticalSection(&m_img_lock);
  48. }
  49. if(isStoped)return false;
  50. if(wait)Sleep(10);
  51. } while (wait);
  52. return false;
  53. }
  54. ServiceState CManualMatchFeeder::OnStarting( void )
  55. {
  56. m_img =NULL;
  57. m_post_count =0;
  58. return IService::OnStarting();
  59. }
  60. ServiceState CManualMatchFeeder::OnRunning( void )
  61. {
  62. ServiceState nextState = IService::OnRunning();
  63. if(nextState != running) return nextState;
  64. if(m_img==NULL){
  65. if(m_img_list.size()>m_post_count){
  66. m_img =cvLoadImage(m_img_list[m_post_count].img_path,1);
  67. m_param =&m_img_list[m_post_count];
  68. m_post_count++;
  69. return running;
  70. }
  71. return stoping;
  72. }else{
  73. Sleep(10);
  74. return running;
  75. }
  76. }
  77. void CManualMatchFeeder::SetImgList(const std::vector<img_param> & imgs )
  78. {
  79. m_img_list = imgs;
  80. }