From 3b27411a6a9cf8c51456227725f7921f4f199054 Mon Sep 17 00:00:00 2001 From: zaki Date: Thu, 24 Aug 2023 17:35:02 +0530 Subject: [PATCH] color conversion bug fix --- base/include/ColorConversionXForm.h | 3 + base/src/ColorConversionXForm.cpp | 149 ++++++++++++++-------------- 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/base/include/ColorConversionXForm.h b/base/include/ColorConversionXForm.h index 13209dfb0..aac8f8eb1 100644 --- a/base/include/ColorConversionXForm.h +++ b/base/include/ColorConversionXForm.h @@ -41,6 +41,7 @@ class ColorConversion : public Module protected: bool process(frame_container& frames); bool processSOS(frame_sp& frame); + bool shouldTriggerSOS(); bool validateInputPins(); bool validateOutputPins(); void setConversionStrategy(framemetadata_sp inputMetadata, framemetadata_sp outputMetadata); @@ -53,5 +54,7 @@ class ColorConversion : public Module std::string mOutputPinId; framemetadata_sp mOutputMetadata; framemetadata_sp mInputMetadata; + bool mShouldTriggerSos = true; + bool setMetadata(framemetadata_sp& metadata); }; diff --git a/base/src/ColorConversionXForm.cpp b/base/src/ColorConversionXForm.cpp index 0bc6896dd..36e288101 100644 --- a/base/src/ColorConversionXForm.cpp +++ b/base/src/ColorConversionXForm.cpp @@ -27,26 +27,6 @@ bool ColorConversion::validateInputPins() LOG_ERROR << "<" << getId() << ">::validateInputPins input frameType is expected to be Raw_Image or Raw_Image_Planar. Actual<" << frameType << ">"; return false; } - if (frameType == FrameMetadata::RAW_IMAGE) - { - auto rawMetadata = FrameMetadataFactory::downcast(metadata); - auto imageType = rawMetadata->getImageType(); - if (imageType != ImageMetadata::RGB && imageType != ImageMetadata::BGR && imageType != ImageMetadata::BAYERBG10 && imageType != ImageMetadata::BAYERBG8 && imageType != ImageMetadata::BAYERGB8 && imageType != ImageMetadata::BAYERGR8 && imageType != ImageMetadata::BAYERRG8) - { - LOG_ERROR << "<" << getId() << ">Input Image type is not supported. Actual<" << imageType << ">"; - return false; - } - } - else if (frameType == FrameMetadata::RAW_IMAGE_PLANAR) - { - auto rawMetadata = FrameMetadataFactory::downcast(metadata); - auto imageType = rawMetadata->getImageType(); - if (imageType != ImageMetadata::YUV420) - { - LOG_ERROR << "<" << getId() << ">Output Image type is not supported . Actual<" << imageType << ">"; - return false; - } - } return true; } @@ -65,26 +45,6 @@ bool ColorConversion::validateOutputPins() LOG_ERROR << "<" << getId() << ">::validateOutputPins input frameType is expected to be RAW_IMAGE or Raw_Image_Planar. Actual<" << frameType << ">"; return false; } - if (frameType == FrameMetadata::RAW_IMAGE) - { - auto rawMetadata = FrameMetadataFactory::downcast(metadata); - auto imageType = rawMetadata->getImageType(); - if (imageType != ImageMetadata::MONO && imageType != ImageMetadata::RGB && imageType != ImageMetadata::BGR && imageType != ImageMetadata::BAYERBG8) - { - LOG_ERROR << "<" << getId() << ">Output Image type is not supported . Actual<" << imageType << ">"; - return false; - } - } - else if (frameType == FrameMetadata::RAW_IMAGE_PLANAR) - { - auto rawMetadata = FrameMetadataFactory::downcast(metadata); - auto imageType = rawMetadata->getImageType(); - if (imageType != ImageMetadata::YUV420) - { - LOG_ERROR << "<" << getId() << ">Output Image type is not supported . Actual<" << imageType << ">"; - return false; - } - } return true; } @@ -97,29 +57,69 @@ void ColorConversion::addInputPin(framemetadata_sp& metadata, string& pinId) { mInputMetadata = metadata; Module::addInputPin(metadata, pinId); - auto inputFrameType = metadata->getFrameType(); - uint16_t mWidth; - uint16_t mHeight; + auto frameType = metadata->getFrameType(); + if (mProps.type == ColorConversionProps::RGB_TO_YUV420PLANAR) + { + mOutputMetadata = boost::shared_ptr(new RawImagePlanarMetadata(FrameMetadata::HOST)); + } + else + { + mOutputMetadata = boost::shared_ptr(new RawImageMetadata(FrameMetadata::HOST)); + } + mOutputPinId = addOutputPin(mOutputMetadata); +} + +std::string ColorConversion::addOutputPin(framemetadata_sp& metadata) +{ + return Module::addOutputPin(metadata); +} + +bool ColorConversion::init() +{ + + return Module::init(); +} + +bool ColorConversion::term() +{ + return Module::term(); +} + +bool ColorConversion::process(frame_container& frames) +{ + auto outFrame = makeFrame(); + mDetail->convert(frames, outFrame, mOutputMetadata); + frames.insert(make_pair(mOutputPinId, outFrame)); + send(frames); + return true; +} + +bool ColorConversion::setMetadata(framemetadata_sp& metadata) +{ + int mWidth; + int mHeight; + auto inputFrameType = metadata->getFrameType(); + RawImageMetadata rawMetadata; + RawImagePlanarMetadata rawPlanarMetadata(FrameMetadata::HOST); if (inputFrameType == FrameMetadata::RAW_IMAGE) { - auto rawMetadata = FrameMetadataFactory::downcast(metadata); - mWidth = rawMetadata->getWidth(); - mHeight = rawMetadata->getHeight(); + auto tempRawMetadata = FrameMetadataFactory::downcast(metadata); + mWidth = tempRawMetadata->getWidth(); + mHeight = tempRawMetadata->getHeight(); } else if (inputFrameType == FrameMetadata::RAW_IMAGE_PLANAR) { - auto rawPlanarMetadata = FrameMetadataFactory::downcast(metadata); - mWidth = rawPlanarMetadata->getWidth(0); - mHeight = rawPlanarMetadata->getHeight(0); + auto tempRawPlanarMetadata = FrameMetadataFactory::downcast(metadata); + mWidth = tempRawPlanarMetadata->getWidth(0); + mHeight = tempRawPlanarMetadata->getHeight(0); } - switch (mProps.type) { case ColorConversionProps::ConversionType::RGB_TO_MONO: case ColorConversionProps::ConversionType::BGR_TO_MONO: case ColorConversionProps::ConversionType::BAYERBG8_TO_MONO: - mOutputMetadata = boost::shared_ptr(new RawImageMetadata(mWidth, mHeight, ImageMetadata::MONO, CV_8UC1, 0, CV_8U, FrameMetadata::HOST, true)); + rawMetadata = RawImageMetadata(mWidth, mHeight, ImageMetadata::MONO, CV_8UC1, 0, CV_8U, FrameMetadata::HOST, true); break; case ColorConversionProps::ConversionType::BGR_TO_RGB: case ColorConversionProps::ConversionType::BAYERBG8_TO_RGB: @@ -127,46 +127,43 @@ void ColorConversion::addInputPin(framemetadata_sp& metadata, string& pinId) case ColorConversionProps::ConversionType::BAYERGB8_TO_RGB: case ColorConversionProps::ConversionType::BAYERGR8_TO_RGB: case ColorConversionProps::ConversionType::BAYERRG8_TO_RGB: - mOutputMetadata = boost::shared_ptr(new RawImageMetadata(mWidth, mHeight, ImageMetadata::RGB, CV_8UC3, 0, CV_8U, FrameMetadata::HOST, true)); + rawMetadata = RawImageMetadata(mWidth, mHeight, ImageMetadata::RGB, CV_8UC3, 0, CV_8U, FrameMetadata::HOST, true); break; case ColorConversionProps::ConversionType::RGB_TO_BGR: - mOutputMetadata = boost::shared_ptr(new RawImageMetadata(mWidth, mHeight, ImageMetadata::BGR, CV_8UC3, 0, CV_8U, FrameMetadata::HOST, true)); + rawMetadata = RawImageMetadata(mWidth, mHeight, ImageMetadata::BGR, CV_8UC3, 0, CV_8U, FrameMetadata::HOST, true); break; case ColorConversionProps::ConversionType::RGB_TO_YUV420PLANAR: - mOutputMetadata = boost::shared_ptr(new RawImagePlanarMetadata(mWidth, mHeight, ImageMetadata::YUV420, size_t(0), CV_8U, FrameMetadata::HOST)); + rawPlanarMetadata = RawImagePlanarMetadata(mWidth, mHeight, ImageMetadata::YUV420, size_t(0), CV_8U, FrameMetadata::HOST); break; default: throw AIPException(AIP_FATAL, "conversion not supported"); } - mOutputPinId = addOutputPin(mOutputMetadata); -} -std::string ColorConversion::addOutputPin(framemetadata_sp& metadata) -{ - return Module::addOutputPin(metadata); -} - -bool ColorConversion::init() -{ - setConversionStrategy(mInputMetadata, mOutputMetadata); - return Module::init(); -} + if(mProps.type == ColorConversionProps::RGB_TO_YUV420PLANAR) + { + auto rawPlanarOutMetadata = FrameMetadataFactory::downcast(mOutputMetadata); + rawPlanarOutMetadata->setData(rawPlanarMetadata); + } + else + { + auto rawOutMetadata = FrameMetadataFactory::downcast(mOutputMetadata); + rawOutMetadata->setData(rawMetadata); + } -bool ColorConversion::term() -{ - return Module::term(); + return true; } -bool ColorConversion::process(frame_container& frames) +bool ColorConversion::processSOS(frame_sp& frame) { - auto outFrame = makeFrame(); - mDetail->convert(frames, outFrame, mOutputMetadata); - frames.insert(make_pair(mOutputPinId, outFrame)); - send(frames); + auto mInputMetadata = frame->getMetadata(); + setMetadata(mInputMetadata); + Module::setMetadata(mOutputPinId, mOutputMetadata); + setConversionStrategy(mInputMetadata, mOutputMetadata); + mShouldTriggerSos = false; return true; } -bool ColorConversion::processSOS(frame_sp& frame) +bool ColorConversion::shouldTriggerSOS() { - return true; + return mShouldTriggerSos; } \ No newline at end of file