You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "basicVideoAnalyzer.h"
  2. basicVideoAnalyzer::basicVideoAnalyzer() :
  3. basicThread(),
  4. basicMediaDestination(),
  5. basicMediaSource(),
  6. m_mBufferProtectorMutex()
  7. {
  8. m_bDetectionStatus = false;
  9. m_bDataIsActive = false;
  10. m_pLog = basicLogCollection::getInstance();
  11. m_pEventHeap = basicEventHeap::getInstance();
  12. }
  13. basicVideoAnalyzer::~basicVideoAnalyzer()
  14. {
  15. m_mBufferProtectorMutex.lock();
  16. m_bDataIsActive = false;
  17. waitThreadEnd(true);
  18. m_mBufferProtectorMutex.unlock();
  19. }
  20. void basicVideoAnalyzer::m_fThreadProc(void)
  21. {
  22. int RetVal;
  23. m_bThreadStatus = TH_WORKING;
  24. while (m_bThreadStatus < TH_ENDED)
  25. {
  26. while (! m_bDataIsActive && m_bThreadStatus < TH_ENDED)
  27. {
  28. SLEEP(1);
  29. }
  30. if (m_bThreadStatus < TH_ENDED)
  31. {
  32. m_mBufferProtectorMutex.lock();
  33. m_bDetectionStatus = m_fImageAnalyzer(m_oWorkingMat);
  34. m_bDataIsActive = false;
  35. m_mBufferProtectorMutex.unlock();
  36. };
  37. };
  38. }
  39. void basicVideoAnalyzer::pushFrame(cv::Mat * Frame)
  40. {
  41. Mat mOutputMap;
  42. if (m_mBufferProtectorMutex.try_lock())
  43. {
  44. m_oWorkingMat.copyTo(mOutputMap);
  45. Frame->copyTo(m_oWorkingMat);
  46. // cvtColor(*Frame, *Frame, CV_BGR2RGB);
  47. if (! mOutputMap.empty())
  48. {
  49. markup(mOutputMap);
  50. }
  51. m_bDataIsActive = true;
  52. m_mBufferProtectorMutex.unlock();
  53. if (m_bDetectionStatus)
  54. {
  55. // markup(*Frame);
  56. /* Generate Event */
  57. basicEvent * tEvt;
  58. tEvt = createVAEvent(true); // EVT_CLASS_VIDEO, EVT_ALARM, "Motion Detected");
  59. if (tEvt != NULL)
  60. {
  61. m_pEventHeap->broadcast(tEvt);
  62. }
  63. };
  64. };
  65. if (! mOutputMap.empty())
  66. {
  67. if (m_pMediaDestination != NULL)
  68. {
  69. m_pMediaDestination->pushFrame(&mOutputMap);
  70. }
  71. }
  72. }