Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color conversion module bug fix #299

Merged
merged 1 commit into from
Aug 29, 2023
Merged
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/include/ColorConversionXForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
};

149 changes: 73 additions & 76 deletions base/src/ColorConversionXForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<RawImageMetadata>(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<RawImagePlanarMetadata>(metadata);
auto imageType = rawMetadata->getImageType();
if (imageType != ImageMetadata::YUV420)
{
LOG_ERROR << "<" << getId() << ">Output Image type is not supported . Actual<" << imageType << ">";
return false;
}
}
return true;
}

Expand All @@ -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<RawImageMetadata>(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<RawImagePlanarMetadata>(metadata);
auto imageType = rawMetadata->getImageType();
if (imageType != ImageMetadata::YUV420)
{
LOG_ERROR << "<" << getId() << ">Output Image type is not supported . Actual<" << imageType << ">";
return false;
}
}
return true;
}

Expand All @@ -97,76 +57,113 @@ 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<FrameMetadata>(new RawImagePlanarMetadata(FrameMetadata::HOST));
}
else
{
mOutputMetadata = boost::shared_ptr<FrameMetadata>(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<RawImageMetadata>(metadata);
mWidth = rawMetadata->getWidth();
mHeight = rawMetadata->getHeight();
auto tempRawMetadata = FrameMetadataFactory::downcast<RawImageMetadata>(metadata);
mWidth = tempRawMetadata->getWidth();
mHeight = tempRawMetadata->getHeight();
}
else if (inputFrameType == FrameMetadata::RAW_IMAGE_PLANAR)
{
auto rawPlanarMetadata = FrameMetadataFactory::downcast<RawImagePlanarMetadata>(metadata);
mWidth = rawPlanarMetadata->getWidth(0);
mHeight = rawPlanarMetadata->getHeight(0);
auto tempRawPlanarMetadata = FrameMetadataFactory::downcast<RawImagePlanarMetadata>(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<FrameMetadata>(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:
case ColorConversionProps::ConversionType::YUV420PLANAR_TO_RGB:
case ColorConversionProps::ConversionType::BAYERGB8_TO_RGB:
case ColorConversionProps::ConversionType::BAYERGR8_TO_RGB:
case ColorConversionProps::ConversionType::BAYERRG8_TO_RGB:
mOutputMetadata = boost::shared_ptr<FrameMetadata>(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<FrameMetadata>(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<FrameMetadata>(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<RawImagePlanarMetadata>(mOutputMetadata);
rawPlanarOutMetadata->setData(rawPlanarMetadata);
}
else
{
auto rawOutMetadata = FrameMetadataFactory::downcast<RawImageMetadata>(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;
}
Loading