/mylib/myimage.cpp

https://github.com/rayban/UchiyaMarkers · C++ · 123 lines · 93 code · 23 blank · 7 comment · 2 complexity · 87c96dc4460d33bd8a44e1ac1dff4ad8 MD5 · raw file

  1. /*
  2. This file is part of UCHIYAMARKERS, a software for random dot markers.
  3. Copyright (c) 2011 Hideaki Uchiyama
  4. You can use, copy, modify and re-distribute this software
  5. for non-profit purposes.
  6. */
  7. #include "myimage.h"
  8. MyImage::MyImage():m_img(NULL)
  9. {
  10. }
  11. MyImage::MyImage(const MyImage &src):m_img(NULL)
  12. {
  13. Clone(src);
  14. }
  15. MyImage::~MyImage()
  16. {
  17. Release();
  18. }
  19. void MyImage::Flip(const MyImage &src)
  20. {
  21. cvFlip(src.m_img, m_img);
  22. }
  23. void MyImage::Release()
  24. {
  25. if(m_img != NULL){
  26. cvReleaseImage(&m_img);
  27. m_img = NULL;
  28. }
  29. }
  30. void MyImage::Clone(const MyImage &src)
  31. {
  32. Release();
  33. m_img = cvCloneImage(src.m_img);
  34. w = m_img->width;
  35. h = m_img->height;
  36. }
  37. void MyImage::Binarization(const MyImage &src, int threshold)
  38. {
  39. cvThreshold(src.m_img, m_img, threshold, 255, CV_THRESH_BINARY_INV);
  40. }
  41. void MyImage::GraytoColor(const MyImage &src)
  42. {
  43. cvCvtColor(src.m_img, m_img, CV_GRAY2BGR);
  44. }
  45. void MyImage::ColortoGray(const MyImage &src)
  46. {
  47. cvCvtColor(src.m_img, m_img, CV_BGR2GRAY);
  48. }
  49. void MyImage::Swap(MyImage &src)
  50. {
  51. IplImage *tmp = m_img;
  52. m_img = src.m_img;
  53. src.m_img = tmp;
  54. }
  55. void MyImage::Resize(const MyImage &src)
  56. {
  57. cvResize(src.m_img, m_img);
  58. }
  59. void MyImage::Init(const int iw, const int ih, const int c, const int d)
  60. {
  61. w = iw, h = ih;
  62. m_img = cvCreateImage(cvSize(iw, ih), d, c);
  63. Clean();
  64. }
  65. void MyImage::Clean()
  66. {
  67. cvSetZero(m_img);
  68. }
  69. void MyImage::Save(const char *name) const
  70. {
  71. cvSaveImage(name, m_img);
  72. }
  73. void MyImage::Load(const char *name)
  74. {
  75. Release();
  76. m_img = cvLoadImage(name);
  77. w = m_img->width;
  78. h = m_img->height;
  79. }
  80. void MyImage::Circle(const int x, const int y, const int radius, const int thickness, const unsigned char r, const unsigned char g, const unsigned char b)
  81. {
  82. cvCircle(m_img,cvPoint(x,y),radius,CV_RGB(r,g,b),thickness);
  83. }
  84. MyImage::operator const char* () const
  85. {
  86. return m_img->imageData;
  87. }
  88. MyImage::operator char* ()
  89. {
  90. return m_img->imageData;
  91. }
  92. MyImage::operator const IplImage* () const
  93. {
  94. return m_img;
  95. }
  96. MyImage::operator IplImage* ()
  97. {
  98. return m_img;
  99. }