From e6c473dfa6e13790e5509a796c661b95b19367ef Mon Sep 17 00:00:00 2001 From: Yashraj Singh Date: Thu, 9 Sep 2021 13:02:58 +0530 Subject: [PATCH 1/6] Added 1. Brightness Contrast Module 2. VirtualPTZ module --- base/CMakeLists.txt | 6 + base/include/BrightnessContrastControl.h | 54 +++++++ base/include/VirtualPTZ.h | 62 ++++++++ base/src/BrightnessContrastControl.cpp | 165 +++++++++++++++++++ base/src/VirtualPTZ.cpp | 193 +++++++++++++++++++++++ base/test/brightness_contrast_tests.cpp | 128 +++++++++++++++ base/test/virtualptz_tests.cpp | 141 +++++++++++++++++ 7 files changed, 749 insertions(+) create mode 100644 base/include/BrightnessContrastControl.h create mode 100644 base/include/VirtualPTZ.h create mode 100644 base/src/BrightnessContrastControl.cpp create mode 100644 base/src/VirtualPTZ.cpp create mode 100644 base/test/brightness_contrast_tests.cpp create mode 100644 base/test/virtualptz_tests.cpp diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index 1f724f605..361666d72 100755 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -209,6 +209,8 @@ SET(IP_FILES src/ImageResizeCV.cpp src/ImageEncoderCV.cpp src/RotateCV.cpp + src/BrightnessContrastControl.cpp + src/VirtualPTZ.cpp ) SET(IP_FILES_H @@ -222,6 +224,8 @@ SET(IP_FILES_H include/ImageResizeCV.h include/ImageEncoderCV.h include/RotateCV.h + include/BrightnessContrastControl.h + include/VirtualPTZ.h ) SET(CUDA_CORE_FILES @@ -418,6 +422,8 @@ SET(UT_FILES test/ImageEncodeCV_tests.cpp test/QRReader_tests.cpp test/rotatecv_tests.cpp + test/brightness_contrast_tests.cpp + test/virtualptz_tests.cpp ${ARM64_UT_FILES} ${CUDA_UT_FILES} ) diff --git a/base/include/BrightnessContrastControl.h b/base/include/BrightnessContrastControl.h new file mode 100644 index 000000000..843cfb3f1 --- /dev/null +++ b/base/include/BrightnessContrastControl.h @@ -0,0 +1,54 @@ +#pragma once + +#include "Module.h" + +class BrightnessContrastControlProps : public ModuleProps +{ +public: + BrightnessContrastControlProps(double _alpha, int _beta) : alpha(_alpha), beta(_beta) + { + } + double alpha; + int beta; + + size_t getSerializeSize() + { + return ModuleProps::getSerializeSize() + sizeof(int) + sizeof(double); + } + +private: + friend class boost::serialization::access; + + template + void serialize(Archive &ar, const unsigned int version) + { + ar &boost::serialization::base_object(*this); + ar &alpha β + } +}; + +class BrightnessContrastControl : public Module +{ + +public: + BrightnessContrastControl(BrightnessContrastControlProps _props); + virtual ~BrightnessContrastControl(); + bool init(); + bool term(); + void setProps(BrightnessContrastControlProps &props); + BrightnessContrastControlProps getProps(); + +protected: + bool process(frame_container &frames); + bool processSOS(frame_sp &frame); + bool validateInputPins(); + bool validateOutputPins(); + void addInputPin(framemetadata_sp &metadata, string &pinId); + void setProps(BrightnessContrastControl); + bool handlePropsChange(frame_sp &frame); + +private: + void setMetadata(framemetadata_sp &metadata); + class Detail; + boost::shared_ptr mDetail; +}; \ No newline at end of file diff --git a/base/include/VirtualPTZ.h b/base/include/VirtualPTZ.h new file mode 100644 index 000000000..973b69836 --- /dev/null +++ b/base/include/VirtualPTZ.h @@ -0,0 +1,62 @@ +#pragma once + +#include "Module.h" + +class VirtualPTZProps : public ModuleProps +{ +public: + VirtualPTZProps() + { + roiHeight = roiWidth = 1; + roiX = roiY = 0; + } + VirtualPTZProps(float _roiWidth, float _roiHeight, float _roiX, float _roiY) : roiWidth(_roiWidth), roiHeight(_roiHeight), roiX(_roiX), roiY(_roiY) + { + } + + float roiX; + float roiY; + float roiWidth; + float roiHeight; + + size_t getSerializeSize() + { + return ModuleProps::getSerializeSize() + sizeof(float) * 4; + } + +private: + friend class boost::serialization::access; + + template + void serialize(Archive &ar, const unsigned int version) + { + ar &boost::serialization::base_object(*this); + ar &roiX &roiY &roiWidth &roiHeight; + } +}; + +class VirtualPTZ : public Module +{ + +public: + VirtualPTZ(VirtualPTZProps _props); + virtual ~VirtualPTZ(); + bool init(); + bool term(); + void setProps(VirtualPTZProps &props); + VirtualPTZProps getProps(); + +protected: + bool process(frame_container &frames); + bool processSOS(frame_sp &frame); + bool validateInputPins(); + bool validateOutputPins(); + void addInputPin(framemetadata_sp &metadata, string &pinId); + void setProps(VirtualPTZ); + bool handlePropsChange(frame_sp &frame); + +private: + void setMetadata(framemetadata_sp &metadata); + class Detail; + boost::shared_ptr mDetail; +}; \ No newline at end of file diff --git a/base/src/BrightnessContrastControl.cpp b/base/src/BrightnessContrastControl.cpp new file mode 100644 index 000000000..c0a7eaaba --- /dev/null +++ b/base/src/BrightnessContrastControl.cpp @@ -0,0 +1,165 @@ +#include "BrightnessContrastControl.h" +#include "FrameMetadata.h" +#include "FrameMetadataFactory.h" +#include "Frame.h" +#include "Logger.h" +#include +#include "opencv2/highgui.hpp" +#include "Utils.h" + +class BrightnessContrastControl::Detail +{ +public: + Detail(BrightnessContrastControlProps &_props) : mProps(_props) + { + } + ~Detail() {} + + void initMatImages(framemetadata_sp &input) + { + mInputImg = Utils::getMatHeader(FrameMetadataFactory::downcast(input)); + mOutputImg = Utils::getMatHeader(FrameMetadataFactory::downcast(mOutputMetadata)); + } + + void setProps(BrightnessContrastControlProps &props) + { + mProps = props; + } + +public: + framemetadata_sp mOutputMetadata; + std::string mOutputPinId; + cv::Mat mInputImg; + cv::Mat mOutputImg; + BrightnessContrastControlProps mProps; + int mFrameType; +}; + +BrightnessContrastControl::BrightnessContrastControl(BrightnessContrastControlProps _props) : Module(TRANSFORM, "BrightnessContrastControl", _props) //, mFrameType(FrameMetadata::GENERAL) //mProps(_props), +{ + mDetail.reset(new Detail(_props)); +} + +BrightnessContrastControl::~BrightnessContrastControl() {} + +bool BrightnessContrastControl::validateInputPins() +{ + if (getNumberOfInputPins() != 1) + { + LOG_ERROR << "<" << getId() << ">::validateInputPins size is expected to be 1. Actual<" << getNumberOfInputPins() << ">"; + return false; + } + + framemetadata_sp metadata = getFirstInputMetadata(); + FrameMetadata::FrameType frameType = metadata->getFrameType(); + if (frameType != FrameMetadata::RAW_IMAGE) + { + LOG_ERROR << "<" << getId() << ">::validateInputPins input frameType is expected to be Raw_Image. Actual<" << frameType << ">"; + return false; + } + + return true; +} + +bool BrightnessContrastControl::validateOutputPins() +{ + if (getNumberOfOutputPins() != 1) + { + LOG_ERROR << "<" << getId() << ">::validateOutputPins size is expected to be 1. Actual<" << getNumberOfOutputPins() << ">"; + return false; + } + + framemetadata_sp metadata = getFirstOutputMetadata(); + FrameMetadata::FrameType frameType = metadata->getFrameType(); + if (frameType != FrameMetadata::RAW_IMAGE) + { + LOG_ERROR << "<" << getId() << ">::validateOutputPins input frameType is expected to be RAW_IMAGE. Actual<" << frameType << ">"; + return false; + } + + return true; +} + +void BrightnessContrastControl::addInputPin(framemetadata_sp &metadata, string &pinId) +{ + Module::addInputPin(metadata, pinId); + mDetail->mOutputMetadata = framemetadata_sp(new RawImageMetadata()); + mDetail->mOutputMetadata->copyHint(*metadata.get()); + mDetail->mOutputPinId = addOutputPin(mDetail->mOutputMetadata); +} + +bool BrightnessContrastControl::init() +{ + return Module::init(); +} + +bool BrightnessContrastControl::term() +{ + return Module::term(); +} + +bool BrightnessContrastControl::process(frame_container &frames) +{ + auto frame = frames.begin()->second; + auto outFrame = makeFrame(); + + mDetail->mInputImg.data = static_cast(frame->data()); + mDetail->mOutputImg.data = static_cast(outFrame->data()); + mDetail->mInputImg.convertTo(mDetail->mOutputImg, -1, mDetail->mProps.alpha, mDetail->mProps.beta); + frames.insert(make_pair(mDetail->mOutputPinId, outFrame)); + send(frames); + return true; +} + +void BrightnessContrastControl::setMetadata(framemetadata_sp &metadata) +{ + if (!metadata->isSet()) + { + return; + } + auto rawMetadata = FrameMetadataFactory::downcast(metadata); + RawImageMetadata outputMetadata(rawMetadata->getWidth(), rawMetadata->getHeight(), rawMetadata->getImageType(), rawMetadata->getType(), 0, rawMetadata->getDepth(), FrameMetadata::HOST, true); + auto rawOutMetadata = FrameMetadataFactory::downcast(mDetail->mOutputMetadata); + rawOutMetadata->setData(outputMetadata); + auto imageType = rawMetadata->getImageType(); + + mDetail->initMatImages(metadata); + + switch (imageType) + { + case ImageMetadata::MONO: + case ImageMetadata::BGR: + case ImageMetadata::BGRA: + case ImageMetadata::RGB: + case ImageMetadata::RGBA: + break; + default: + throw AIPException(AIP_NOTIMPLEMENTED, "ImageType not Supported<" + std::to_string(imageType) + ">"); // # aug30review - change comment + } +} + +bool BrightnessContrastControl::processSOS(frame_sp &frame) +{ + auto metadata = frame->getMetadata(); + setMetadata(metadata); + return true; +} + +BrightnessContrastControlProps BrightnessContrastControl::getProps() +{ + fillProps(mDetail->mProps); + return mDetail->mProps; +} + +bool BrightnessContrastControl::handlePropsChange(frame_sp &frame) +{ + BrightnessContrastControlProps props(0, 0); + auto ret = Module::handlePropsChange(frame, props); + mDetail->setProps(props); + return ret; +} + +void BrightnessContrastControl::setProps(BrightnessContrastControlProps &props) +{ + Module::addPropsToQueue(props); +} diff --git a/base/src/VirtualPTZ.cpp b/base/src/VirtualPTZ.cpp new file mode 100644 index 000000000..4a0c38352 --- /dev/null +++ b/base/src/VirtualPTZ.cpp @@ -0,0 +1,193 @@ +#include "VirtualPTZ.h" +#include "FrameMetadata.h" +#include "FrameMetadataFactory.h" +#include "Frame.h" +#include "Logger.h" +#include +#include "Utils.h" +#include "AIPExceptions.h" + +class VirtualPTZ::Detail +{ +public: + Detail(VirtualPTZProps &_props) : mProps(_props) + { + } + ~Detail() + { + } + + void initMatImages(framemetadata_sp &input) + { + mInputImg = Utils::getMatHeader(FrameMetadataFactory::downcast(input)); + mOutputImg = Utils::getMatHeader(FrameMetadataFactory::downcast(mOutputMetadata)); + } + + void setProps(VirtualPTZProps &props) + { + if (!mOutputMetadata.get()) + { + return; + } + auto rawMetadata = FrameMetadataFactory::downcast(mOutputMetadata); + mRoi = cv::Rect(mInputWidth * props.roiX, mInputHeight * props.roiY, mInputWidth * props.roiWidth, mInputHeight * props.roiHeight); + if (!Utils::check_roi_bounds(mRoi, rawMetadata->getWidth(), rawMetadata->getHeight())) + { + LOG_ERROR << "Using the full image as roi is out of bounds. <" << props.roiX << "> <" << props.roiY << "> <" << props.roiWidth << "> <" << props.roiHeight << ">"; + VirtualPTZProps defProps(1, 1, 0, 0); + mProps = defProps; + } + else + { + mProps = props; + } + mRoi = cv::Rect(mInputWidth * mProps.roiX, mInputHeight * mProps.roiY, mInputWidth * mProps.roiWidth, mInputHeight * mProps.roiHeight); + } + +public: + framemetadata_sp mOutputMetadata; + std::string mOutputPinId; + cv::Mat mOutputImg; + cv::Mat mInputImg; + cv::Size mOutSize; + int mInputWidth; + int mInputHeight; + cv::Rect mRoi; + VirtualPTZProps mProps; + +private: +}; + +VirtualPTZ::VirtualPTZ(VirtualPTZProps _props) : Module(TRANSFORM, "VirtualPTZ", _props) +{ + mDetail.reset(new Detail(_props)); +} + +VirtualPTZ::~VirtualPTZ() {} + +bool VirtualPTZ::validateInputPins() +{ + if (getNumberOfInputPins() != 1) + { + LOG_ERROR << "<" << getId() << ">::validateInputPins size is expected to be 1. Actual<" << getNumberOfInputPins() << ">"; + return false; + } + + framemetadata_sp metadata = getFirstInputMetadata(); + FrameMetadata::FrameType frameType = metadata->getFrameType(); + if (frameType != FrameMetadata::RAW_IMAGE) + { + LOG_ERROR << "<" << getId() << ">::validateInputPins input frameType is expected to be RAW_IMAGE. Actual<" << frameType << ">"; + return false; + } + + return true; +} + +bool VirtualPTZ::validateOutputPins() +{ + if (getNumberOfOutputPins() != 1) + { + LOG_ERROR << "<" << getId() << ">::validateOutputPins size is expected to be 1. Actual<" << getNumberOfOutputPins() << ">"; + return false; + } + + framemetadata_sp metadata = getFirstOutputMetadata(); + FrameMetadata::FrameType frameType = metadata->getFrameType(); + if (frameType != FrameMetadata::RAW_IMAGE) + { + LOG_ERROR << "<" << getId() << ">::validateOutputPins input frameType is expected to be RAW_IMAGE. Actual<" << frameType << ">"; + return false; + } + + return true; +} + +void VirtualPTZ::addInputPin(framemetadata_sp &metadata, string &pinId) +{ + Module::addInputPin(metadata, pinId); + mDetail->mOutputMetadata = framemetadata_sp(new RawImageMetadata()); + mDetail->mOutputMetadata->copyHint(*metadata.get()); + mDetail->mOutputPinId = addOutputPin(mDetail->mOutputMetadata); +} + +bool VirtualPTZ::init() +{ + return Module::init(); +} + +bool VirtualPTZ::term() +{ + return Module::term(); +} + +bool VirtualPTZ::process(frame_container &frames) +{ + auto frame = frames.begin()->second; + auto outFrame = makeFrame(); + + mDetail->mInputImg.data = static_cast(frame->data()); + mDetail->mOutputImg.data = static_cast(outFrame->data()); + + cv::resize(mDetail->mInputImg(mDetail->mRoi), mDetail->mOutputImg, mDetail->mOutSize); + frames.insert(make_pair(mDetail->mOutputPinId, outFrame)); + + send(frames); + return true; +} + +void VirtualPTZ::setMetadata(framemetadata_sp &metadata) +{ + if (!metadata->isSet()) + { + return; + } + auto rawMetadata = FrameMetadataFactory::downcast(metadata); + mDetail->mInputWidth = rawMetadata->getWidth(); + mDetail->mInputHeight = rawMetadata->getHeight(); + RawImageMetadata outputMetadata(mDetail->mInputWidth, mDetail->mInputHeight, rawMetadata->getImageType(), rawMetadata->getType(), 0, rawMetadata->getDepth(), FrameMetadata::HOST, true); + auto rawOutMetadata = FrameMetadataFactory::downcast(mDetail->mOutputMetadata); + rawOutMetadata->setData(outputMetadata); + mDetail->setProps(mDetail->mProps); + auto imageType = rawMetadata->getImageType(); + mDetail->initMatImages(metadata); + mDetail->mOutSize = cv::Size(mDetail->mInputWidth, mDetail->mInputHeight); + + switch (imageType) + { + case ImageMetadata::MONO: + case ImageMetadata::BGR: + case ImageMetadata::BGRA: + case ImageMetadata::RGB: + case ImageMetadata::RGBA: + break; + default: + throw AIPException(AIP_NOTIMPLEMENTED, "ImageType Not Supported <" + std::to_string(imageType) + ">"); + } +} + +void VirtualPTZ::setProps(VirtualPTZProps &props) +{ + Module::addPropsToQueue(props); +} + +VirtualPTZProps VirtualPTZ::getProps() +{ + fillProps(mDetail->mProps); + return mDetail->mProps; +} + +bool VirtualPTZ::handlePropsChange(frame_sp &frame) +{ + VirtualPTZProps props(0, 0, 0, 0); + bool ret = Module::handlePropsChange(frame, props); + mDetail->setProps(props); + return ret; +} + +bool VirtualPTZ::processSOS(frame_sp &frame) +{ + auto metadata = frame->getMetadata(); + setMetadata(metadata); + return true; +} diff --git a/base/test/brightness_contrast_tests.cpp b/base/test/brightness_contrast_tests.cpp new file mode 100644 index 000000000..3e0b7a222 --- /dev/null +++ b/base/test/brightness_contrast_tests.cpp @@ -0,0 +1,128 @@ +#include "stdafx.h" +#include +#include "FileReaderModule.h" +#include "ExternalSinkModule.h" +#include "FrameMetadata.h" +#include "FrameMetadataFactory.h" +#include "Frame.h" +#include "Logger.h" +#include "AIPExceptions.h" +#include "MetadataHints.h" +#include "test_utils.h" +#include "FramesMuxer.h" +#include "PipeLine.h" +#include "StatSink.h" +#include "PipeLine.h" +#include "FileWriterModule.h" +#include "CudaMemCopy.h" +#include "BrightnessContrastControl.h" + +#ifdef ARM64 +BOOST_AUTO_TEST_SUITE(brightnes_contrast_tests, *boost::unit_test::disabled()) +#else +BOOST_AUTO_TEST_SUITE(brightnes_contrast_tests) +#endif + +BOOST_AUTO_TEST_CASE(mono) +{ + + auto fileReader = boost::shared_ptr(new FileReaderModule(FileReaderModuleProps("./data/mono_1920x1080.raw"))); + auto metadata = framemetadata_sp(new RawImageMetadata(1920, 960, ImageMetadata::ImageType::MONO, CV_8UC1, 0, CV_8U, FrameMetadata::HOST, true)); + fileReader->addOutputPin(metadata); + + auto brightnessControl = boost::shared_ptr(new BrightnessContrastControl(BrightnessContrastControlProps(0.5, 40))); + fileReader->setNext(brightnessControl); + + auto m2 = boost::shared_ptr(new FileWriterModule(FileWriterModuleProps("./data/testOutput/brightnessControlmono.raw"))); + brightnessControl->setNext(m2); + + PipeLine p("test"); + p.appendModule(fileReader); + BOOST_TEST(p.init()); + p.run_all_threaded(); + + boost::this_thread::sleep_for(boost::chrono::seconds(2)); + Logger::setLogLevel(boost::log::trivial::severity_level::error); + + p.stop(); + p.term(); + + p.wait_for_all(); +} + +BOOST_AUTO_TEST_CASE(bgra) +{ + LoggerProps logprops; + logprops.logLevel = boost::log::trivial::severity_level::info; + Logger::initLogger(logprops); + + auto width = 1920; + auto height = 960; + + auto fileReader = boost::shared_ptr(new FileReaderModule(FileReaderModuleProps("./data/overlay_1920x960_BGRA.raw"))); + auto metadata = framemetadata_sp(new RawImageMetadata(width, height, ImageMetadata::BGRA, CV_8UC4, 0, CV_8U, FrameMetadata::HOST)); + auto rawImagePin = fileReader->addOutputPin(metadata); + + auto brightnessControl = boost::shared_ptr(new BrightnessContrastControl(BrightnessContrastControlProps(0.5, 40))); + fileReader->setNext(brightnessControl); + + auto m2 = boost::shared_ptr(new FileWriterModule(FileWriterModuleProps("./data/testOutput/brightnessControl12345.raw"))); + brightnessControl->setNext(m2); + + PipeLine p("test"); + p.appendModule(fileReader); + BOOST_TEST(p.init()); + p.run_all_threaded(); + + boost::this_thread::sleep_for(boost::chrono::seconds(2)); + Logger::setLogLevel(boost::log::trivial::severity_level::error); + + p.stop(); + p.term(); + + p.wait_for_all(); +} + +BOOST_AUTO_TEST_CASE(getSetProps) +{ + auto fileReader = boost::shared_ptr(new FileReaderModule(FileReaderModuleProps("./data/frame_1280x720_rgb.raw"))); + auto metadata = framemetadata_sp(new RawImageMetadata(1280, 720, ImageMetadata::ImageType::RGB, CV_8UC3, 0, CV_8U, FrameMetadata::HOST, true)); + fileReader->addOutputPin(metadata); + + auto brightnessControl = boost::shared_ptr(new BrightnessContrastControl(BrightnessContrastControlProps(0.5, 40))); + fileReader->setNext(brightnessControl); + + auto m2 = boost::shared_ptr(new ExternalSinkModule()); + brightnessControl->setNext(m2); + + BOOST_TEST(fileReader->init()); + BOOST_TEST(brightnessControl->init()); + BOOST_TEST(m2->init()); + + { + fileReader->step(); + brightnessControl->step(); + auto frames = m2->pop(); + BOOST_TEST(frames.size() == 1); + auto outputFrame = frames.cbegin()->second; + BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); + Test_Utils::saveOrCompare("./data/testOutput/brightnessgetset1.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); + } + + BrightnessContrastControlProps props12(2, 40); + + brightnessControl->setProps(props12); + brightnessControl->step(); + + { + fileReader->step(); + brightnessControl->step(); + auto frames = m2->pop(); + BOOST_TEST(frames.size() == 1); + auto outputFrame = frames.cbegin()->second; + BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); + Test_Utils::saveOrCompare("./data/testOutput/brightnessgetset2.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); + } +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/base/test/virtualptz_tests.cpp b/base/test/virtualptz_tests.cpp new file mode 100644 index 000000000..ce10b2e59 --- /dev/null +++ b/base/test/virtualptz_tests.cpp @@ -0,0 +1,141 @@ +#include "stdafx.h" +#include +// #include +#include "VirtualPTZ.h" +#include "FileReaderModule.h" +#include "ExternalSinkModule.h" +#include "FrameMetadata.h" +#include "FrameMetadataFactory.h" +#include "Frame.h" +#include "Logger.h" +#include "AIPExceptions.h" +#include "MetadataHints.h" +#include "test_utils.h" +#include "ImageResizeCV.h" +#include "RotateCV.h" +#include "FramesMuxer.h" +#include "PipeLine.h" +#include "StatSink.h" +#include "ImageOverlayCPU.h" +#include "TextOverlayCPU.h" +#include "OpencvWebcam.h" +#include "StatSink.h" +#include "PipeLine.h" +#include "FileWriterModule.h" +#include "CudaMemCopy.h" +#include "JPEGEncoderNVJPEG.h" +#include "ImageEncoderCV.h" +#include "BrightnessContrastControl.h" +#include "ImageOverlay.h" +#include "WebCamSrc.h" +#ifdef ARM64 +BOOST_AUTO_TEST_SUITE(virtual_ptz_tests, *boost::unit_test::disabled()) +#else +BOOST_AUTO_TEST_SUITE(virtual_ptz_tests) +#endif + +BOOST_AUTO_TEST_CASE(mono) +{ + + auto fileReader = boost::shared_ptr(new FileReaderModule(FileReaderModuleProps("./data/mono_1920x960.raw"))); + auto metadata = framemetadata_sp(new RawImageMetadata(1920, 960, ImageMetadata::ImageType::MONO, CV_8UC1, 0, CV_8U, FrameMetadata::HOST, true)); + fileReader->addOutputPin(metadata); + + auto vPtz = boost::shared_ptr(new VirtualPTZ(VirtualPTZProps(0.09, 0.500, 0.00, 0.00))); + fileReader->setNext(vPtz); + + auto Vptzprops = vPtz->getProps(); + + auto sink = boost::shared_ptr(new ExternalSinkModule()); + vPtz->setNext(sink); + + BOOST_TEST(fileReader->init()); + BOOST_TEST(vPtz->init()); + BOOST_TEST(sink->init()); + + fileReader->step(); + vPtz->step(); + auto frames = sink->pop(); + BOOST_TEST(frames.size() == 1); + auto outputFrame = frames.cbegin()->second; + BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); + + Test_Utils::saveOrCompare("./data/testOutput/vPtztest4.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); +} + +BOOST_AUTO_TEST_CASE(rgb) +{ + + auto fileReader = boost::shared_ptr(new FileReaderModule(FileReaderModuleProps("./data/frame_1280x720_rgb.raw"))); + auto metadata = framemetadata_sp(new RawImageMetadata(1280, 720, ImageMetadata::ImageType::RGB, CV_8UC3, 0, CV_8U, FrameMetadata::HOST, true)); + fileReader->addOutputPin(metadata); + + auto vPtz = boost::shared_ptr(new VirtualPTZ(VirtualPTZProps(0.9, 0.900, 0.90, 0.90))); + fileReader->setNext(vPtz); + + auto Vptzprops = vPtz->getProps(); + + auto sink = boost::shared_ptr(new ExternalSinkModule()); + vPtz->setNext(sink); + + BOOST_TEST(fileReader->init()); + BOOST_TEST(vPtz->init()); + BOOST_TEST(sink->init()); + + fileReader->step(); + vPtz->step(); + auto frames = sink->pop(); + BOOST_TEST(frames.size() == 1); + auto outputFrame = frames.cbegin()->second; + BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); + + Test_Utils::saveOrCompare("./data/testOutput/vPtztest8.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); +} + +BOOST_AUTO_TEST_CASE(testGetSetProps) +{ + + auto fileReader = boost::shared_ptr(new FileReaderModule(FileReaderModuleProps("./data/mono_1920x960.raw"))); + auto metadata = framemetadata_sp(new RawImageMetadata(1920, 960, ImageMetadata::ImageType::MONO, CV_8UC1, 0, CV_8U, FrameMetadata::HOST, true)); + fileReader->addOutputPin(metadata); + + auto vPtz = boost::shared_ptr(new VirtualPTZ(VirtualPTZProps(0.300, 0.300, 0.100, 0.100))); + fileReader->setNext(vPtz); + + auto Vptzprops = vPtz->getProps(); + + auto sink = boost::shared_ptr(new ExternalSinkModule()); + vPtz->setNext(sink); + + BOOST_TEST(fileReader->init()); + BOOST_TEST(vPtz->init()); + BOOST_TEST(sink->init()); + + { + fileReader->step(); + vPtz->step(); + auto frames = sink->pop(); + BOOST_TEST(frames.size() == 1); + auto outputFrame = frames.cbegin()->second; + BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); + Test_Utils::saveOrCompare("./data/testOutput/vPtztest2.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); + } + + VirtualPTZProps props12(0.950, 0.950, 0.90, 0.90); + + vPtz->setProps(props12); + vPtz->step(); + + { + auto Vptzprops1 = vPtz->getProps(); + fileReader->step(); + vPtz->step(); + auto frames = sink->pop(); + BOOST_TEST(frames.size() == 1); + auto outputFrame = frames.cbegin()->second; + BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); + Test_Utils::saveOrCompare("./data/testOutput/vPtztest7.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); + } +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file From a4fbdadeb27762c312123c485254b0b81b1bce96 Mon Sep 17 00:00:00 2001 From: Yashraj Singh Date: Mon, 13 Sep 2021 22:37:38 +0530 Subject: [PATCH 2/6] Modified tests --- base/src/VirtualPTZ.cpp | 2 - base/test/brightness_contrast_tests.cpp | 54 +++++++++++-------------- base/test/virtualptz_tests.cpp | 13 +++--- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/base/src/VirtualPTZ.cpp b/base/src/VirtualPTZ.cpp index 4a0c38352..97779f0fa 100644 --- a/base/src/VirtualPTZ.cpp +++ b/base/src/VirtualPTZ.cpp @@ -33,9 +33,7 @@ class VirtualPTZ::Detail mRoi = cv::Rect(mInputWidth * props.roiX, mInputHeight * props.roiY, mInputWidth * props.roiWidth, mInputHeight * props.roiHeight); if (!Utils::check_roi_bounds(mRoi, rawMetadata->getWidth(), rawMetadata->getHeight())) { - LOG_ERROR << "Using the full image as roi is out of bounds. <" << props.roiX << "> <" << props.roiY << "> <" << props.roiWidth << "> <" << props.roiHeight << ">"; VirtualPTZProps defProps(1, 1, 0, 0); - mProps = defProps; } else { diff --git a/base/test/brightness_contrast_tests.cpp b/base/test/brightness_contrast_tests.cpp index 3e0b7a222..f0b2bac92 100644 --- a/base/test/brightness_contrast_tests.cpp +++ b/base/test/brightness_contrast_tests.cpp @@ -17,11 +17,7 @@ #include "CudaMemCopy.h" #include "BrightnessContrastControl.h" -#ifdef ARM64 -BOOST_AUTO_TEST_SUITE(brightnes_contrast_tests, *boost::unit_test::disabled()) -#else BOOST_AUTO_TEST_SUITE(brightnes_contrast_tests) -#endif BOOST_AUTO_TEST_CASE(mono) { @@ -30,24 +26,23 @@ BOOST_AUTO_TEST_CASE(mono) auto metadata = framemetadata_sp(new RawImageMetadata(1920, 960, ImageMetadata::ImageType::MONO, CV_8UC1, 0, CV_8U, FrameMetadata::HOST, true)); fileReader->addOutputPin(metadata); - auto brightnessControl = boost::shared_ptr(new BrightnessContrastControl(BrightnessContrastControlProps(0.5, 40))); + auto brightnessControl = boost::shared_ptr(new BrightnessContrastControl(BrightnessContrastControlProps(0.5, 40))); fileReader->setNext(brightnessControl); - auto m2 = boost::shared_ptr(new FileWriterModule(FileWriterModuleProps("./data/testOutput/brightnessControlmono.raw"))); + auto m2 = boost::shared_ptr(new ExternalSinkModule()); brightnessControl->setNext(m2); - PipeLine p("test"); - p.appendModule(fileReader); - BOOST_TEST(p.init()); - p.run_all_threaded(); - - boost::this_thread::sleep_for(boost::chrono::seconds(2)); - Logger::setLogLevel(boost::log::trivial::severity_level::error); - - p.stop(); - p.term(); + BOOST_TEST(fileReader->init()); + BOOST_TEST(brightnessControl->init()); + BOOST_TEST(m2->init()); - p.wait_for_all(); + fileReader->step(); + brightnessControl->step(); + auto frames = m2->pop(); + BOOST_TEST(frames.size() == 1); + auto outputFrame = frames.cbegin()->second; + BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); + Test_Utils::saveOrCompare("./data/testOutput/brightnessmono.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); } BOOST_AUTO_TEST_CASE(bgra) @@ -63,24 +58,23 @@ BOOST_AUTO_TEST_CASE(bgra) auto metadata = framemetadata_sp(new RawImageMetadata(width, height, ImageMetadata::BGRA, CV_8UC4, 0, CV_8U, FrameMetadata::HOST)); auto rawImagePin = fileReader->addOutputPin(metadata); - auto brightnessControl = boost::shared_ptr(new BrightnessContrastControl(BrightnessContrastControlProps(0.5, 40))); + auto brightnessControl = boost::shared_ptr(new BrightnessContrastControl(BrightnessContrastControlProps(0.5, 40))); fileReader->setNext(brightnessControl); - auto m2 = boost::shared_ptr(new FileWriterModule(FileWriterModuleProps("./data/testOutput/brightnessControl12345.raw"))); + auto m2 = boost::shared_ptr(new ExternalSinkModule()); brightnessControl->setNext(m2); - PipeLine p("test"); - p.appendModule(fileReader); - BOOST_TEST(p.init()); - p.run_all_threaded(); - - boost::this_thread::sleep_for(boost::chrono::seconds(2)); - Logger::setLogLevel(boost::log::trivial::severity_level::error); - - p.stop(); - p.term(); + BOOST_TEST(fileReader->init()); + BOOST_TEST(brightnessControl->init()); + BOOST_TEST(m2->init()); - p.wait_for_all(); + fileReader->step(); + brightnessControl->step(); + auto frames = m2->pop(); + BOOST_TEST(frames.size() == 1); + auto outputFrame = frames.cbegin()->second; + BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); + Test_Utils::saveOrCompare("./data/testOutput/brightnessbgra.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); } BOOST_AUTO_TEST_CASE(getSetProps) diff --git a/base/test/virtualptz_tests.cpp b/base/test/virtualptz_tests.cpp index ce10b2e59..f5947873b 100644 --- a/base/test/virtualptz_tests.cpp +++ b/base/test/virtualptz_tests.cpp @@ -28,11 +28,8 @@ #include "BrightnessContrastControl.h" #include "ImageOverlay.h" #include "WebCamSrc.h" -#ifdef ARM64 -BOOST_AUTO_TEST_SUITE(virtual_ptz_tests, *boost::unit_test::disabled()) -#else + BOOST_AUTO_TEST_SUITE(virtual_ptz_tests) -#endif BOOST_AUTO_TEST_CASE(mono) { @@ -60,7 +57,7 @@ BOOST_AUTO_TEST_CASE(mono) auto outputFrame = frames.cbegin()->second; BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); - Test_Utils::saveOrCompare("./data/testOutput/vPtztest4.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); + Test_Utils::saveOrCompare("./data/testOutput/vPtztestmono.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); } BOOST_AUTO_TEST_CASE(rgb) @@ -89,7 +86,7 @@ BOOST_AUTO_TEST_CASE(rgb) auto outputFrame = frames.cbegin()->second; BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); - Test_Utils::saveOrCompare("./data/testOutput/vPtztest8.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); + Test_Utils::saveOrCompare("./data/testOutput/vPtztestrgb.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); } BOOST_AUTO_TEST_CASE(testGetSetProps) @@ -118,7 +115,7 @@ BOOST_AUTO_TEST_CASE(testGetSetProps) BOOST_TEST(frames.size() == 1); auto outputFrame = frames.cbegin()->second; BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); - Test_Utils::saveOrCompare("./data/testOutput/vPtztest2.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); + Test_Utils::saveOrCompare("./data/testOutput/vPtztestprops1.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); } VirtualPTZProps props12(0.950, 0.950, 0.90, 0.90); @@ -134,7 +131,7 @@ BOOST_AUTO_TEST_CASE(testGetSetProps) BOOST_TEST(frames.size() == 1); auto outputFrame = frames.cbegin()->second; BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE); - Test_Utils::saveOrCompare("./data/testOutput/vPtztest7.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); + Test_Utils::saveOrCompare("./data/testOutput/vPtztestprops2.raw", const_cast(static_cast(outputFrame->data())), outputFrame->size(), 0); } } From 25801f8120575362f11851dbbe2ec4be4eef0ae2 Mon Sep 17 00:00:00 2001 From: Yashraj Singh Date: Mon, 13 Sep 2021 22:44:21 +0530 Subject: [PATCH 3/6] Added Logs if Roi is out of bound --- base/src/VirtualPTZ.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/src/VirtualPTZ.cpp b/base/src/VirtualPTZ.cpp index 97779f0fa..d0308e34c 100644 --- a/base/src/VirtualPTZ.cpp +++ b/base/src/VirtualPTZ.cpp @@ -33,7 +33,7 @@ class VirtualPTZ::Detail mRoi = cv::Rect(mInputWidth * props.roiX, mInputHeight * props.roiY, mInputWidth * props.roiWidth, mInputHeight * props.roiHeight); if (!Utils::check_roi_bounds(mRoi, rawMetadata->getWidth(), rawMetadata->getHeight())) { - VirtualPTZProps defProps(1, 1, 0, 0); + LOG_ERROR << "Using the full image as roi is out of bounds. <" << props.roiX << "> <" << props.roiY << "> <" << props.roiHeight << "> <" << props.roiWidth << ">"; } else { From a22c9d0a35538c31fefb5998eab1420fe66ddc16 Mon Sep 17 00:00:00 2001 From: Yashraj Singh Date: Tue, 14 Sep 2021 11:30:58 +0530 Subject: [PATCH 4/6] MOdified Set Props logic --- base/src/VirtualPTZ.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/src/VirtualPTZ.cpp b/base/src/VirtualPTZ.cpp index d0308e34c..906b65195 100644 --- a/base/src/VirtualPTZ.cpp +++ b/base/src/VirtualPTZ.cpp @@ -34,12 +34,12 @@ class VirtualPTZ::Detail if (!Utils::check_roi_bounds(mRoi, rawMetadata->getWidth(), rawMetadata->getHeight())) { LOG_ERROR << "Using the full image as roi is out of bounds. <" << props.roiX << "> <" << props.roiY << "> <" << props.roiHeight << "> <" << props.roiWidth << ">"; + mRoi = cv::Rect(mInputWidth * mProps.roiX, mInputHeight * mProps.roiY, mInputWidth * mProps.roiWidth, mInputHeight * mProps.roiHeight); } else { mProps = props; } - mRoi = cv::Rect(mInputWidth * mProps.roiX, mInputHeight * mProps.roiY, mInputWidth * mProps.roiWidth, mInputHeight * mProps.roiHeight); } public: From 4bcf8c0074c29608956b702b40ecc8b80059acc6 Mon Sep 17 00:00:00 2001 From: yashrajsapra <88146397+yashrajsapra@users.noreply.github.com> Date: Tue, 14 Sep 2021 15:00:59 +0530 Subject: [PATCH 5/6] Update BrightnessContrastControl.cpp --- base/src/BrightnessContrastControl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/src/BrightnessContrastControl.cpp b/base/src/BrightnessContrastControl.cpp index c0a7eaaba..012e0c163 100644 --- a/base/src/BrightnessContrastControl.cpp +++ b/base/src/BrightnessContrastControl.cpp @@ -35,7 +35,7 @@ class BrightnessContrastControl::Detail int mFrameType; }; -BrightnessContrastControl::BrightnessContrastControl(BrightnessContrastControlProps _props) : Module(TRANSFORM, "BrightnessContrastControl", _props) //, mFrameType(FrameMetadata::GENERAL) //mProps(_props), +BrightnessContrastControl::BrightnessContrastControl(BrightnessContrastControlProps _props) : Module(TRANSFORM, "BrightnessContrastControl", _props) { mDetail.reset(new Detail(_props)); } @@ -134,7 +134,7 @@ void BrightnessContrastControl::setMetadata(framemetadata_sp &metadata) case ImageMetadata::RGBA: break; default: - throw AIPException(AIP_NOTIMPLEMENTED, "ImageType not Supported<" + std::to_string(imageType) + ">"); // # aug30review - change comment + throw AIPException(AIP_NOTIMPLEMENTED, "ImageType not Supported<" + std::to_string(imageType) + ">"); } } From 3b1b70d393e6f613ccaba393f79c52cbbe588b2b Mon Sep 17 00:00:00 2001 From: yashrajsapra <88146397+yashrajsapra@users.noreply.github.com> Date: Tue, 14 Sep 2021 15:01:54 +0530 Subject: [PATCH 6/6] Update virtualptz_tests.cpp --- base/test/virtualptz_tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/test/virtualptz_tests.cpp b/base/test/virtualptz_tests.cpp index f5947873b..ef490c0dc 100644 --- a/base/test/virtualptz_tests.cpp +++ b/base/test/virtualptz_tests.cpp @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(rgb) auto metadata = framemetadata_sp(new RawImageMetadata(1280, 720, ImageMetadata::ImageType::RGB, CV_8UC3, 0, CV_8U, FrameMetadata::HOST, true)); fileReader->addOutputPin(metadata); - auto vPtz = boost::shared_ptr(new VirtualPTZ(VirtualPTZProps(0.9, 0.900, 0.90, 0.90))); + auto vPtz = boost::shared_ptr(new VirtualPTZ(VirtualPTZProps(0.29, 0.2900, 0.0, 0.0))); fileReader->setNext(vPtz); auto Vptzprops = vPtz->getProps(); @@ -135,4 +135,4 @@ BOOST_AUTO_TEST_CASE(testGetSetProps) } } -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +BOOST_AUTO_TEST_SUITE_END()