Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ SET(IP_FILES
src/ImageEncoderCV.cpp
src/RotateCV.cpp
src/AffineTransform.cpp
src/PerspectiveTransform.cpp
src/BrightnessContrastControlXform.cpp
src/VirtualPTZ.cpp
src/WebCamSource.cpp
Expand Down Expand Up @@ -355,6 +356,7 @@ SET(IP_FILES_H
include/ImageEncoderCV.h
include/RotateCV.h
include/AffineTransform.h
include/PerspectiveTransform.h
include/BrightnessContrastControlXform.h
include/VirtualPTZ.h
include/WebCamSource.h
Expand Down Expand Up @@ -600,6 +602,7 @@ SET(UT_FILES
test/ImageEncodeCV_tests.cpp
test/rotatecv_tests.cpp
test/affinetransform_tests.cpp
test/perspectivetransform_tests.cpp
test/brightness_contrast_tests.cpp
test/virtualptz_tests.cpp
test/webcam_source_tests.cpp
Expand Down
114 changes: 114 additions & 0 deletions base/include/PerspectiveTransform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#pragma once
#include "FrameMetadata.h"
#include "Module.h"
#include "Logger.h"

class PerspectiveTransformProps : public ModuleProps
{
public:
enum Mode
{
BASIC,
DYNAMIC
};

// Default constructor for serialization
PerspectiveTransformProps() : mode(BASIC) {}

// Constructor for BASIC mode
PerspectiveTransformProps(const std::vector<cv::Point2f> &_srcPoints, const std::vector<cv::Point2f> &_dstPoints)
: mode(BASIC)
{
srcPoints = _srcPoints;
dstPoints = _dstPoints;
}

// Constructor for DYNAMIC mode
PerspectiveTransformProps(Mode _mode) : mode(_mode)
{
if (_mode != DYNAMIC)
{
throw AIPException(AIP_FATAL, "This constructor only supports DYNAMIC mode");
}
}

Mode mode;
std::vector<cv::Point2f> srcPoints;
std::vector<cv::Point2f> dstPoints;

size_t getSerializeSize()
{
return ModuleProps::getSerializeSize() + sizeof(Mode) +
sizeof(size_t) + srcPoints.size() * sizeof(cv::Point2f) +
sizeof(size_t) + dstPoints.size() * sizeof(cv::Point2f);
}

private:
friend class boost::serialization::access;

template <class Archive>
void save(Archive &ar, const unsigned int version) const
{
ar &boost::serialization::base_object<ModuleProps>(*this);
ar &mode;

size_t srcSize = srcPoints.size();
size_t dstSize = dstPoints.size();
ar &srcSize &dstSize;

for (size_t i = 0; i < srcSize; ++i) {
ar &srcPoints[i].x &srcPoints[i].y;
}
for (size_t i = 0; i < dstSize; ++i) {
ar &dstPoints[i].x &dstPoints[i].y;
}
}

template <class Archive>
void load(Archive &ar, const unsigned int version)
{
ar &boost::serialization::base_object<ModuleProps>(*this);
ar &mode;

size_t srcSize, dstSize;
ar &srcSize &dstSize;

srcPoints.resize(srcSize);
dstPoints.resize(dstSize);

for (size_t i = 0; i < srcSize; ++i) {
ar &srcPoints[i].x &srcPoints[i].y;
}
for (size_t i = 0; i < dstSize; ++i) {
ar &dstPoints[i].x &dstPoints[i].y;
}
}

BOOST_SERIALIZATION_SPLIT_MEMBER()
};

class PerspectiveTransform : public Module
{
public:
PerspectiveTransform(PerspectiveTransformProps _props);
virtual ~PerspectiveTransform();
bool init();
bool term();
void setProps(PerspectiveTransformProps &props);
PerspectiveTransformProps getProps();

protected:
bool process(frame_container &frames);
bool processSOS(frame_sp &frame);
bool validateInputPins();
bool validateOutputPins();
void addInputPin(framemetadata_sp &metadata, string &pinId);
std::string addOutputPin(framemetadata_sp &metadata);
bool handlePropsChange(frame_sp &frame);

private:
int mFrameType;
PerspectiveTransformProps mProps;
class Detail;
boost::shared_ptr<Detail> mDetail;
};
Loading
Loading