ChangeDetection Module
- Input is histogram bins
- Output is ChangeDetectionResult
Define Module Properties
{
public:
{
refWindowLength = 1;
refDelayLength = -1;
insWindowLength = 1;
threshold = 1;
compareMethod = 1;
}
ChangeDetectionProps(
int _refWindowLength,
int _refDelayLength,
int _insWindowLength,
double _threshold,
int _compareMethod):
ModuleProps()
{
refWindowLength = _refWindowLength;
refDelayLength = _refDelayLength;
insWindowLength = _insWindowLength;
threshold = _threshold;
compareMethod = _compareMethod;
}
int refWindowLength;
int refDelayLength;
int insWindowLength;
double threshold;
int compareMethod;
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar,
const unsigned int version)
{
ar & boost::serialization::base_object<ModuleProps>(*this);
ar & refWindowLength;
ar & refDelayLength;
ar & insWindowLength;
ar & threshold;
ar & compareMethod;
}
};
void serialize(Archive &ar, const unsigned int)
Definition Module.h:142
Validating the input and output
bool ChangeDetection::validateInputOutputPins()
{
if (count != 1)
{
LOG_ERROR << "Input pin of type ARRAY is expected.";
return false;
}
if (count != 1)
{
LOG_ERROR << "Input pin of type CHANGE_DETECTION is expected.";
return false;
}
return true;
}
Initialization
bool ChangeDetection::init()
{
{
return false;
}
return true;
}
virtual bool init()
Definition Module.cpp:570
Handling the first frame and using the input metadata
bool ChangeDetection::processSOS(frame_sp& frame)
{
auto metadata = frame->getMetadata();
{
return true;
}
return true;
}
Output
class ChangeDetectionResult
{
public:
ChangeDetectionResult(bool changeDetected, double distance, uint64_t index)
{
mChangeDetected = changeDetected;
mDistance = distance;
fIndex = index;
}
ChangeDetectionResult() {}
static boost::shared_ptr<ChangeDetectionResult> deSerialize(frame_container& frames)
{
auto frame = frame_sp();
for (auto it = frames.cbegin(); it != frames.cend(); it++)
{
auto tempFrame = it->second;
if (tempFrame->getMetadata()->getFrameType() == frameType)
{
frame = tempFrame;
}
}
if (!frame.get())
{
return boost::shared_ptr<ChangeDetectionResult>();
}
auto result = boost::shared_ptr<ChangeDetectionResult>(new ChangeDetectionResult(false, 0, 0));
auto& obj = *result.get();
return result;
}
static void serialize(bool changeDetected, double distance, uint64_t index, void* buffer, size_t size)
{
auto result = ChangeDetectionResult(changeDetected, distance, index);
}
static size_t getSerializeSize()
{
return 1024 + sizeof(mChangeDetected) + sizeof(mDistance) + sizeof(fIndex);
}
bool mChangeDetected;
double mDistance;
uint64_t fIndex;
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int ) {
ar & mChangeDetected & mDistance & fIndex;
}
};
static void serialize(T &obj, void *buffer, size_t size)
Definition Utils.h:31
static void deSerialize(T &obj, void *buffer, size_t size)
Definition Utils.h:41
Consuming the input and send output
bool ChangeDetection::process(frame_container& frames)
{
auto metadata = mDetail->getOutputMetadata();
auto outFrame = makeFrame(ChangeDetectionResult::getSerializeSize(), metadata);
frames.insert(make_pair(pinId, outFrame));
send(frames);
return true;
}
© Copyright 2020-2024, Apra Labs Inc.