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.

77 lines
1.7 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. pthread_setname_np(pthread_self(), "basicVideoAnalizer");
  25. while (m_bThreadStatus < TH_ENDED)
  26. {
  27. while (! m_bDataIsActive && m_bThreadStatus < TH_ENDED)
  28. {
  29. SLEEP(1);
  30. }
  31. if (m_bThreadStatus < TH_ENDED)
  32. {
  33. m_mBufferProtectorMutex.lock();
  34. m_bDetectionStatus = m_fImageAnalyzer(m_oWorkingMat);
  35. m_bDataIsActive = false;
  36. m_mBufferProtectorMutex.unlock();
  37. };
  38. };
  39. }
  40. void basicVideoAnalyzer::pushFrame(cv::Mat * Frame)
  41. {
  42. Mat mOutputMap;
  43. if (m_mBufferProtectorMutex.try_lock())
  44. {
  45. m_oWorkingMat.copyTo(mOutputMap);
  46. Frame->copyTo(m_oWorkingMat);
  47. // cvtColor(*Frame, *Frame, CV_BGR2RGB);
  48. if (! mOutputMap.empty())
  49. {
  50. markup(mOutputMap);
  51. }
  52. m_bDataIsActive = true;
  53. m_mBufferProtectorMutex.unlock();
  54. if (m_bDetectionStatus)
  55. {
  56. // markup(*Frame);
  57. /* Generate Event */
  58. basicEvent * tEvt;
  59. tEvt = createVAEvent(true); // EVT_CLASS_VIDEO, EVT_ALARM, "Motion Detected");
  60. if (tEvt != NULL)
  61. {
  62. m_pEventHeap->broadcast(tEvt);
  63. }
  64. };
  65. };
  66. if (! mOutputMap.empty())
  67. {
  68. if (m_pMediaDestination != NULL)
  69. {
  70. m_pMediaDestination->pushFrame(&mOutputMap);
  71. }
  72. }
  73. }