File size: 1,631 Bytes
1bfe214 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
#include "sequence_compensator_imp.h"
namespace Ivs
{
PtrSequenceCompensator CreateSequenceCompensator()
{
return std::make_unique<CSequenceCompensator>();
}
CSequenceCompensator::~CSequenceCompensator()
{
m_matBackgroundMask.release();
m_matBackground.release();
}
void CSequenceCompensator::SetInputMeta(const TInputImageMeta& tInput)
{
m_matCurFrame = tInput.matImage;
m_vecRectObjRegion = tInput.vecObjRegions;
if (m_matBackground.empty())
{
InitBackground();
}
}
void CSequenceCompensator::Process()
{
if (m_matBackgroundMask.empty())
{
return;
}
m_matCurFrame.copyTo(m_matBackground, m_matBackgroundMask);
UpdateBackgroundMask();
}
bool CSequenceCompensator::IsBackgroundRecover()
{
if (m_matBackgroundMask.empty())
{
return false;
}
return cv::countNonZero(m_matBackgroundMask) == 0;
}
cv::Mat CSequenceCompensator::GetBackgroundImage()
{
return m_matBackground;
}
void CSequenceCompensator::InitBackground()
{
m_matCurFrame.copyTo(m_matBackground);
m_matBackgroundMask = cv::Mat::zeros(m_matBackground.size(), CV_8UC1);
for (auto& rectObj : m_vecRectObjRegion)
{
m_matBackgroundMask(rectObj).setTo(255);
}
}
void CSequenceCompensator::UpdateBackgroundMask()
{
cv::Mat matMaskCur = cv::Mat::zeros(m_matBackgroundMask.size(), CV_8UC1);
for (auto& rect : m_vecRectObjRegion)
{
matMaskCur(rect).setTo(255);
}
cv::bitwise_and(m_matBackgroundMask, matMaskCur, m_matBackgroundMask);
m_vecRectObjRegionPrev = m_vecRectObjRegion;
matMaskCur.release();
}
}
|