acfr / snark

generic c++ libraries and utilities for robotics
Other
69 stars 41 forks source link

cv-cat filters: text colour doesn't scale with cv::Mat depth #122

Closed spotiris closed 7 years ago

spotiris commented 7 years ago

I have a 16 bit file that displays fine, but the text comes out in black regardless of the colour specified in the "text" filter. cv-cat 'bayer=3;crop=0,0,4240,2824;resize=0.3;brightness=10;text=abcdefgaadsdasd,10,50,yellow;view=0;null' < 20170412T013755.350415.bin

However the following works cv-cat 'bayer=3;crop=0,0,4240,2824;resize=0.3;brightness=10;convert-to=CV_8UC3,0.00390625;text=abcdefgaadsdasd,10,50,yellow;view=0;null' < 20170412T013755.350415.bin

The issue arrises from the lack of scaling to the cv::Mat's mat.depth(). Below is a poor fix for it, for your reference.

filters.cpp:1476

template < typename H >
static typename impl::filters< H >::value_type text_impl_( typename impl::filters< H >::value_type m, const std::string& s, const cv::Point& origin, const cv::Scalar& colour )
{
    auto colour_ = colour;
    switch (m.second.depth()){
        case CV_8S: colour_ = cv::Scalar(colour_ / 2); break;
        case CV_16U: colour_ = cv::Scalar(colour * 255); break;
        case CV_16S: colour_ = cv::Scalar(colour * 255 / 2); break;
        case CV_32S: colour_ = cv::Scalar(colour * 255 * 255 / 2); break;
        case CV_32F: colour_ = cv::Scalar(colour / 255.0); break;
        case CV_64F: colour_ = cv::Scalar(colour / 255.0); break;
    }
    cv::putText( m.second, s, origin, cv::FONT_HERSHEY_SIMPLEX, 1.0, colour_, 1, CV_AA );
    return m;
}
aneelatwork commented 7 years ago

fixed (commit: 19623a91)