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.

51 lines
1.6 KiB

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