homog2d library
Public Member Functions | Friends | List of all members
h2d::img::Image< T > Class Template Reference

Opaque data structure, will hold the image type, depending on back-end library. This type is the one used in all the drawing functions. More...

#include <homog2d.hpp>

Public Member Functions

void clear (Color c=Color(255, 255, 255))
 
void clear (uint8_t, uint8_t, uint8_t)
 
void clear (uint8_t)
 
template<>
void clear (uint8_t, uint8_t, uint8_t)
 
template<>
void clear (uint8_t r, uint8_t g, uint8_t b)
 
template<>
void clear (uint8_t col)
 
int cols () const
 
template<typename U >
void draw (const U &object, img::DrawParams dp=img::DrawParams())
 
template<typename U , typename V >
void draw (const std::pair< U, V > &p_objects, img::DrawParams dp=img::DrawParams())
 
void drawText (std::string, Point2d_< float >, img::DrawParams dp=img::DrawParams())
 
template<>
void drawText (std::string str, Point2d_< float > pt, img::DrawParams dp)
 Draw text on Svg image. More...
 
template<>
void drawText (std::string str, Point2d_< float > pt, img::DrawParams dp)
 Draw text on Opencv image. More...
 
T & getReal ()
 Returns a reference on the underlying image. More...
 
const T & getReal () const
 Returns a const reference on the underlying image. More...
 
 Image ()=default
 
 Image (T &m)
 
 Image (size_t, size_t)
 That constructor is the default, shouln't be instanciated, see specializations. More...
 
template<>
 Image (size_t width, size_t height)
 
template<>
 Image (size_t width, size_t height)
 
int rows () const
 
void setSize (size_t width, size_t height)
 
template<typename F >
void setSize (const std::pair< F, F > &)
 
template<>
void setSize (size_t width, size_t height)
 
template<typename T >
void setSize (const std::pair< T, T > &pa)
 
void show (std::string wname)
 Show image on window wname (not available for SVG !) More...
 
std::pair< size_t, size_t > size () const
 
void write (std::string) const
 
template<>
void write (std::string fname) const
 
template<>
void write (std::string fname) const
 

Friends

std::ostream & operator<< (std::ostream &, const Image< SvgImage > &)
 Streaming operator (only defined for SVG) More...
 

Detailed Description

template<typename T>
class h2d::img::Image< T >

Opaque data structure, will hold the image type, depending on back-end library. This type is the one used in all the drawing functions.

At present the two allowed types are cv::Mat (external Opencv library, requires the symbol HOMOG2D_USE_OPENCV to be defined) or SvgImage (no dependency)

Constructor & Destructor Documentation

◆ Image() [1/5]

template<typename T>
h2d::img::Image< T >::Image ( )
default

◆ Image() [2/5]

template<typename T>
h2d::img::Image< T >::Image ( T &  m)
inline
723  : _realImg(m)
724  {}

◆ Image() [3/5]

template<typename T>
h2d::img::Image< T >::Image ( size_t  ,
size_t   
)
inline

That constructor is the default, shouln't be instanciated, see specializations.

742  {
743  assert(0);
744 // static_assert( detail::AlwaysFalse<std::false_type>::value, "no concrete implementation available" );
745 // static_assert( std::false_type, "no concrete implementation available" );
746  }

◆ Image() [4/5]

template<>
h2d::img::Image< cv::Mat >::Image ( size_t  width,
size_t  height 
)
inline
798 {
799  p_setSize( width, height );
800 }
HOMOG2D_INUMTYPE height(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10874
HOMOG2D_INUMTYPE width(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10882

◆ Image() [5/5]

template<>
h2d::img::Image< SvgImage >::Image ( size_t  width,
size_t  height 
)
inline
830 {
831  setSize( width, height );
832 }
HOMOG2D_INUMTYPE height(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10874
HOMOG2D_INUMTYPE width(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10882
void setSize(size_t width, size_t height)
Definition: homog2d.hpp:813

Member Function Documentation

◆ clear() [1/6]

template<typename T>
void h2d::img::Image< T >::clear ( Color  c = Color(255,255,255))
inline
759 { clear(c.r,c.g,c.b); }
void clear(Color c=Color(255, 255, 255))
Definition: homog2d.hpp:759
Here is the caller graph for this function:

◆ clear() [2/6]

template<typename T>
void h2d::img::Image< T >::clear ( uint8_t  ,
uint8_t  ,
uint8_t   
)
inline
762  {
763  assert(0);
764  }

◆ clear() [3/6]

template<typename T>
void h2d::img::Image< T >::clear ( uint8_t  )
inline
766  {
767  assert(0);
768  }

◆ clear() [4/6]

template<>
void h2d::img::Image< SvgImage >::clear ( uint8_t  ,
uint8_t  ,
uint8_t   
)
inline
859 {
860  _realImg._svgString.str("");
861  _realImg._svgString.clear();
862 }

◆ clear() [5/6]

template<>
void h2d::img::Image< cv::Mat >::clear ( uint8_t  r,
uint8_t  g,
uint8_t  b 
)
inline
869 {
870  _realImg = cv::Scalar(b,g,r);
871 }

◆ clear() [6/6]

template<>
void h2d::img::Image< cv::Mat >::clear ( uint8_t  col)
inline
876 {
877  _realImg = cv::Scalar(col,col,col);
878 }

◆ cols()

template<typename T>
int h2d::img::Image< T >::cols ( ) const
inline
757 { return _width; }
Here is the caller graph for this function:

◆ draw() [1/2]

template<typename IMG >
template<typename U >
void h2d::img::Image< IMG >::draw ( const U &  object,
img::DrawParams  dp = img::DrawParams() 
)
892 {
893  object.draw( *this, dp );
894 }
Here is the caller graph for this function:

◆ draw() [2/2]

template<typename IMG >
template<typename U , typename V >
void h2d::img::Image< IMG >::draw ( const std::pair< U, V > &  p_objects,
img::DrawParams  dp = img::DrawParams() 
)
899 {
900  pairp.first.draw( *this, dp );
901  pairp.second.draw( *this, dp );
902 }

◆ drawText() [1/3]

template<typename T>
void h2d::img::Image< T >::drawText ( std::string  ,
Point2d_< float >  ,
img::DrawParams  dp = img::DrawParams() 
)
Here is the caller graph for this function:

◆ drawText() [2/3]

template<>
void h2d::img::Image< img::SvgImage >::drawText ( std::string  str,
Point2d_< float >  pt,
img::DrawParams  dp 
)
inline

Draw text on Svg image.

Todo:
20230118: find a way to add a default parameter for dp (not allowed on explicit instanciation)
12039 {
12040  getReal()._svgString << "<text x=\"" << pt.getX()
12041  << "\" y=\"" << pt.getY()
12042  << "\" font-size=\"" << dp._dpValues._fontSize << "px"
12043  << "\" fill=\"#" << std::hex << std::setfill('0')
12044  << std::setw(2) << (int)dp.color().r
12045  << std::setw(2) << (int)dp.color().g
12046  << std::setw(2) << (int)dp.color().b
12047  << std::dec << "\">" << str << "</text>\n";
12048 }
Point2d pt
Definition: homog2d_test.cpp:4034
T & getReal()
Returns a reference on the underlying image.
Definition: homog2d.hpp:726

◆ drawText() [3/3]

template<>
void h2d::img::Image< cv::Mat >::drawText ( std::string  str,
Point2d_< float >  pt,
img::DrawParams  dp 
)
inline

Draw text on Opencv image.

12056 {
12057  auto col = dp.color();
12058  cv::putText(
12059  getReal(), str, pt.getCvPtd(),
12060  cv::FONT_HERSHEY_SIMPLEX, // font id, see https://docs.opencv.org/4.7.0/
12061  0.03 * dp._dpValues._fontSize, // scale factor (approximate...)
12062  cv::Scalar( col.b, col.g, col.r )
12063  );
12064 }
Point2d pt
Definition: homog2d_test.cpp:4034
T & getReal()
Returns a reference on the underlying image.
Definition: homog2d.hpp:726

◆ getReal() [1/2]

template<typename T>
T& h2d::img::Image< T >::getReal ( )
inline

Returns a reference on the underlying image.

727  {
728  return _realImg;
729  }
Here is the caller graph for this function:

◆ getReal() [2/2]

template<typename T>
const T& h2d::img::Image< T >::getReal ( ) const
inline

Returns a const reference on the underlying image.

732  {
733  return _realImg;
734  }

◆ rows()

template<typename T>
int h2d::img::Image< T >::rows ( ) const
inline
758 { return _height; }
Here is the caller graph for this function:

◆ setSize() [1/4]

template<typename IMG >
void h2d::img::Image< IMG >::setSize ( size_t  width,
size_t  height 
)
814 {
815  _width = width;
816  _height = height;
817 }
HOMOG2D_INUMTYPE height(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10874
HOMOG2D_INUMTYPE width(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10882
Here is the caller graph for this function:

◆ setSize() [2/4]

template<typename T>
template<typename F >
void h2d::img::Image< T >::setSize ( const std::pair< F, F > &  )

◆ setSize() [3/4]

template<>
void h2d::img::Image< cv::Mat >::setSize ( size_t  width,
size_t  height 
)
inline
806 {
807  p_setSize( width, height );
808 }
HOMOG2D_INUMTYPE height(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10874
HOMOG2D_INUMTYPE width(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10882

◆ setSize() [4/4]

template<typename T>
template<typename T >
void h2d::img::Image< T >::setSize ( const std::pair< T, T > &  pa)
823 {
824  setSize( pa.first, pa.second );
825 }
void setSize(size_t width, size_t height)
Definition: homog2d.hpp:813

◆ show()

template<typename T>
void h2d::img::Image< T >::show ( std::string  wname)
inline

Show image on window wname (not available for SVG !)

780  {
781  cv::imshow( wname, _realImg );
782  }
Here is the caller graph for this function:

◆ size()

template<typename T>
std::pair<size_t,size_t> h2d::img::Image< T >::size ( ) const
inline
737  {
738  return std::make_pair( _width, _height );
739  }

◆ write() [1/3]

template<typename T>
void h2d::img::Image< T >::write ( std::string  ) const
inline
753  {
754  assert(0);
755  }
Here is the caller graph for this function:

◆ write() [2/3]

template<>
void h2d::img::Image< SvgImage >::write ( std::string  fname) const
inline
838 {
839  std::ofstream file( fname );
840  if( !file.is_open() )
841  {
842  HOMOG2D_THROW_ERROR_1( "unable to open output file '" + fname + "'" );
843  }
844  file << "<svg version=\"1.1\" width=\"" << _width
845  << "\" height=\"" << _height
846  << "\" style=\"background-color:white;\" xmlns=\"http://www.w3.org/2000/svg\">\n"
847  << "<style>\n"
848  << ".txt1 { font: bold 12px sans-serif; };\n" // text style, you can change or add classes as required
849  << "</style>\n";
850 
851  file << _realImg._svgString.str();
852  file << "</svg>\n";
853 }
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181

◆ write() [3/3]

template<>
void h2d::img::Image< cv::Mat >::write ( std::string  fname) const
inline
884 {
885  cv::imwrite( fname, _realImg );
886 }

Friends And Related Function Documentation

◆ operator<<

template<typename T>
std::ostream& operator<< ( std::ostream &  f,
const Image< SvgImage< T > > &  im 
)
friend

Streaming operator (only defined for SVG)

12018 {
12019  f << "<svg version=\"1.1\" width=\"" << im._width
12020  << "\" height=\"" << im._height
12021  << "\" style=\"background-color:white;\" xmlns=\"http://www.w3.org/2000/svg\">\n"
12022  << "<style>\n"
12023  << ".txt1 { font: bold 12px sans-serif; };\n" // text style, you can change or add classes as required
12024  << "</style>\n";
12025 
12026  f << im._realImg._svgString.str();
12027  f << "</svg>\n";
12028 
12029  return f;
12030 }
img::Image< img::SvgImage > im(300, 400)

The documentation for this class was generated from the following file: