Skip to content

Commit

Permalink
Merge pull request #2941 from robotology/imageRotation_fix
Browse files Browse the repository at this point in the history
fixed image type in imageRotation portmonitor
  • Loading branch information
randaz81 authored Feb 7, 2023
2 parents 656cf7f + 9ce49e9 commit 84a46c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/libYARP_cv/src/yarp/cv/Cv-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ::cv::Mat yarp::cv::toCvMat(yarp::sig::ImageOf<T>& yarpImage)
return outMat;
}

inline ::cv::Mat yarp::cv::toCvMat(yarp::sig::FlexImage& yarpImage)
inline ::cv::Mat yarp::cv::toCvMat(yarp::sig::Image& yarpImage)
{
int val=-1;
int type=0;
Expand Down
2 changes: 1 addition & 1 deletion src/libYARP_cv/src/yarp/cv/Cv.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace yarp::cv {
* are currently supported.
* @return the resulting cv::Mat.
*/
::cv::Mat toCvMat(yarp::sig::FlexImage& yarpImage);
::cv::Mat toCvMat(yarp::sig::Image& yarpImage);

/**
* Convert a yarp::sig::ImageOf to a cv::Mat object
Expand Down
24 changes: 12 additions & 12 deletions src/portmonitors/image_rotation/imageRotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,33 @@ bool ImageRotation::getparam(yarp::os::Property& params)

bool ImageRotation::accept(yarp::os::Things& thing)
{
auto* img = thing.cast_as<yarp::sig::FlexImage>();
auto* img = thing.cast_as<yarp::sig::Image>();
if(img == nullptr)
{
yCError(IMAGEROTATION, "Expected type FlexImage but got wrong data type!");
yCError(IMAGEROTATION, "Expected type Image, but got wrong data type!");
return false;
}
if (img->getPixelCode() != VOCAB_PIXEL_RGB &&
img->getPixelCode() != VOCAB_PIXEL_MONO_FLOAT)
{
yCError(IMAGEROTATION, "Expected type FlexImage but got wrong data type!");
yCError(IMAGEROTATION, "Received image with invalid/unsupported pixelCode!");
return false;
}
return true;
}

yarp::os::Things& ImageRotation::update(yarp::os::Things& thing)
{
yarp::sig::FlexImage* flximg = thing.cast_as<yarp::sig::FlexImage >();
if (flximg->getPixelCode() == VOCAB_PIXEL_RGB)
yarp::sig::Image* yarpimg = thing.cast_as<yarp::sig::Image >();
if (yarpimg->getPixelCode() == VOCAB_PIXEL_RGB)
{
m_cvInImage = yarp::cv::toCvMat(*flximg);
m_cvInImage = yarp::cv::toCvMat(*yarpimg);

m_outImgRgb.resize(flximg->width(), flximg->height());
m_outImgRgb.resize(yarpimg->width(), yarpimg->height());
m_outImgRgb.zero();

//double angle = 90;
//cv::Point2f center((flximg->width() - 1) / 2.0, (flximg->height() - 1) / 2.0);
//cv::Point2f center((yarpimg->width() - 1) / 2.0, (yarpimg->height() - 1) / 2.0);
//cv::Mat rotation_matix = getRotationMatrix2D(center, angle, 1.0);
//cv::warpAffine(cvInImage, cvOutImage, rotation_matix, cvInImage.size());

Expand All @@ -144,15 +144,15 @@ yarp::os::Things& ImageRotation::update(yarp::os::Things& thing)
m_outImgRgb = yarp::cv::fromCvMat<yarp::sig::PixelRgb>(m_cvOutImage);
m_th.setPortWriter(&m_outImgRgb);
}
else if (flximg->getPixelCode() == VOCAB_PIXEL_MONO_FLOAT)
else if (yarpimg->getPixelCode() == VOCAB_PIXEL_MONO_FLOAT)
{
m_cvInImage = yarp::cv::toCvMat(*flximg);
m_cvInImage = yarp::cv::toCvMat(*yarpimg);

m_outImgFloat.resize(flximg->width(), flximg->height());
m_outImgFloat.resize(yarpimg->width(), yarpimg->height());
m_outImgFloat.zero();

//double angle = 90;
//cv::Point2f center((flximg->width() - 1) / 2.0, (flximg->height() - 1) / 2.0);
//cv::Point2f center((yarpimg->width() - 1) / 2.0, (yarpimg->height() - 1) / 2.0);
//cv::Mat rotation_matix = getRotationMatrix2D(center, angle, 1.0);
//cv::warpAffine(cvInImage, cvOutImage, rotation_matix, cvInImage.size());

Expand Down

0 comments on commit 84a46c9

Please sign in to comment.