TekkotsuLink.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef __LIMUN_TEKKOTSULINK_H__
  2. #define __LIMUN_TEKKOTSULINK_H__
  3. /**
  4. * @file TekkotsuLink.h
  5. * Interface between Linum images and Tekkotsu images.
  6. * Only available in AIBO mode.
  7. */
  8. #ifdef LIMUN_AIBO_MODE
  9. #include <core/image/ImageT.h>
  10. #include <core/image/ColorImageT.h>
  11. #include <Shared/WorldState.h>
  12. #include <Shared/ProjectInterface.h>
  13. #include <Shared/Config.h>
  14. #include <Behaviors/BehaviorBase.h>
  15. #include <Events/EventRouter.h>
  16. #include <Events/FilterBankEvent.h>
  17. #include <Vision/RawCameraGenerator.h>
  18. #include <Vision/InterleavedYUVGenerator.h>
  19. namespace NICE {
  20. /**
  21. * Create a new interleaved YUV ColorImage from a Tekkotsu
  22. * FilterBankEvent \c fbkevt. The new ColorImage directly uses the pixel memory
  23. * of the FilterBankEvent, the image data itself is not copied.
  24. * @param fbkevt source FilterBankEvent created from an InterleavedYUVGenerator.
  25. * The GeneratorID has to be EventBase::visInterleaveEGID.
  26. * @param layer specifies the size of the created ColorImage, possible values are
  27. * - 5 - double resolution - 416x320 - requires some significant processing, so use it sparingly.
  28. * - 4 - full resolution - 208x160 - direct from system
  29. * - 3 - half resolution - 104x80 - direct from system
  30. * - 2 - quarter resolution - 52x40 - direct from system
  31. * - 1 - eigth resolution - 26x20 - references every other pixel of quarter resolution image
  32. * - 0 - sixteenth resolution - 13x10 - references the every fourth pixel of quarter resolution image
  33. * @return Pointer to a new ColorImage
  34. * @throws ImageException will be thrown if the fbkevt or layer is invalid.
  35. */
  36. inline ColorImage* createYUVImageFromTekkotsu(const FilterBankEvent& fbkevt,
  37. const uint& layer) {
  38. if (fbkevt.getGeneratorID() != EventBase::visInterleaveEGID) {
  39. fthrow(ImageException,
  40. "Invalid event GeneratorID (expected visInterleaveEGID).");
  41. }
  42. if (layer > 5) {
  43. fthrow(ImageException, "Invalid Layer.");
  44. }
  45. FilterBankGenerator* gen = fbkevt.getSource();
  46. return new ColorImage(gen->getImage(layer, 0),
  47. gen->getWidth(layer),
  48. gen->getHeight(layer),
  49. gen->getStride(layer),
  50. GrayColorImageCommonImplementation::shallowCopy);
  51. }
  52. /**
  53. * Return an interleaved YUV ColorImage from a Tekkotsu
  54. * FilterBankEvent \c fbkevt. The new ColorImage directly uses the pixel memory
  55. * of the FilterBankEvent, the image data itself is not copied.
  56. * @param fbkevt source FilterBankEvent created from an InterleavedYUVGenerator.
  57. * The GeneratorID has to be EventBase::visInterleaveEGID.
  58. * @param layer specifies the size of the created ColorImage, possible values are
  59. * - 5 - double resolution - 416x320 - requires some significant processing, so use it sparingly.
  60. * - 4 - full resolution - 208x160 - direct from system
  61. * - 3 - half resolution - 104x80 - direct from system
  62. * - 2 - quarter resolution - 52x40 - direct from system
  63. * - 1 - eigth resolution - 26x20 - references every other pixel of quarter resolution image
  64. * - 0 - sixteenth resolution - 13x10 - references the every fourth pixel of quarter resolution image
  65. * @return The new ColorImage
  66. * @throws ImageException will be thrown if the fbkevt or layer is invalid.
  67. */
  68. inline ColorImage yuvImageFromTekkotsu(const FilterBankEvent& fbkevt,
  69. const uint& layer) {
  70. if (fbkevt.getGeneratorID() != EventBase::visInterleaveEGID) {
  71. fthrow(ImageException,
  72. "Invalid event GeneratorID (expected visInterleaveEGID).");
  73. }
  74. if (layer > 5) {
  75. fthrow(ImageException, "Invalid Layer.");
  76. }
  77. FilterBankGenerator* gen = fbkevt.getSource();
  78. return ColorImage(gen->getImage(layer, 0),
  79. gen->getWidth(layer),
  80. gen->getHeight(layer),
  81. gen->getStride(layer),
  82. GrayColorImageCommonImplementation::shallowCopy);
  83. }
  84. /**
  85. * Create a new Image from a Tekkotsu FilterBankEvent \c fbkevt.
  86. * The new Image directly uses the pixel memory
  87. * of the FilterBankEvent, the image data itself is not copied.
  88. * @param fbkevt source FilterBankEvent created from a RawCameraGenerator.
  89. * The GeneratorID has to be EventBase::visRawCameraEGID.
  90. * @param layer specifies the size of the created ColorImage, possible values are
  91. * - 5 - double resolution - 416x320 - requires some significant processing, so use it sparingly.
  92. * - 4 - full resolution - 208x160 - direct from system
  93. * - 3 - half resolution - 104x80 - direct from system
  94. * - 2 - quarter resolution - 52x40 - direct from system
  95. * - 1 - eigth resolution - 26x20 - references every other pixel of quarter resolution image
  96. * - 0 - sixteenth resolution - 13x10 - references the every fourth pixel of quarter resolution image
  97. * @param channel Channel to retrieve from the RawCameraGenerator, possible values are:
  98. * - RawCameraGenerator::CHAN_Y - Y (intensity) channel.
  99. * - RawCameraGenerator::CHAN_U - Cb (approx. blue,green,yellow) channel.
  100. * - RawCameraGenerator::CHAN_V - Cr (approx. pink,red,yellow) channel.
  101. * - RawCameraGenerator::CHAN_Y_DY - vertical derivative of Y channel.
  102. * - RawCameraGenerator::CHAN_Y_DX - horizontal derivative of Y channel.
  103. * - RawCameraGenerator::CHAN_Y_DXDY - vert. & horiz. derivatives of Y channel.
  104. * @return Pointer to Image
  105. * @throws ImageException will be thrown if the fbkevt, layer or channel is invalid.
  106. */
  107. inline Image* createGrayImageFromTekkotsu(
  108. const FilterBankEvent& fbkevt,
  109. const uint& layer,
  110. const RawCameraGenerator::channel_id_t channel) {
  111. if (fbkevt.getGeneratorID() != EventBase::visRawCameraEGID) {
  112. fthrow(ImageException,
  113. "Invalid event GeneratorID (expected visRawCameraEGID).");
  114. }
  115. if (layer > 5) {
  116. fthrow(ImageException, "Invalid Layer.");
  117. }
  118. if (channel < RawCameraGenerator::CHAN_Y
  119. || channel > RawCameraGenerator::CHAN_Y_DXDY) {
  120. fthrow(ImageException, "Invalid Channel.");
  121. }
  122. FilterBankGenerator* gen = fbkevt.getSource();
  123. return new Image(gen->getImage(layer, channel),
  124. gen->getWidth(layer),
  125. gen->getHeight(layer),
  126. GrayColorImageCommonImplementation::shallowCopy);
  127. }
  128. /**
  129. * Return a Image from a Tekkotsu FilterBankEvent \c fbkevt.
  130. * The new Image directly uses the pixel memory
  131. * of the FilterBankEvent, the image data itself is not copied.
  132. * @param fbkevt source FilterBankEvent created from a RawCameraGenerator.
  133. * The GeneratorID has to be EventBase::visRawCameraEGID.
  134. * @param layer specifies the size of the created ColorImage, possible values are
  135. * - 5 - double resolution - 416x320 - requires some significant processing, so use it sparingly.
  136. * - 4 - full resolution - 208x160 - direct from system
  137. * - 3 - half resolution - 104x80 - direct from system
  138. * - 2 - quarter resolution - 52x40 - direct from system
  139. * - 1 - eigth resolution - 26x20 - references every other pixel of quarter resolution image
  140. * - 0 - sixteenth resolution - 13x10 - references the every fourth pixel of quarter resolution image
  141. * @param channel Channel to retrieve from the RawCameraGenerator, possible values are:
  142. * - RawCameraGenerator::CHAN_Y - Y (intensity) channel.
  143. * - RawCameraGenerator::CHAN_U - Cb (approx. blue,green,yellow) channel.
  144. * - RawCameraGenerator::CHAN_V - Cr (approx. pink,red,yellow) channel.
  145. * - RawCameraGenerator::CHAN_Y_DY - vertical derivative of Y channel.
  146. * - RawCameraGenerator::CHAN_Y_DX - horizontal derivative of Y channel.
  147. * - RawCameraGenerator::CHAN_Y_DXDY - vert. & horiz. derivatives of Y channel.
  148. * @return Image
  149. * @throws ImageException will be thrown if the fbkevt, layer or channel is invalid.
  150. */
  151. inline Image grayImageFromTekkotsu(
  152. const FilterBankEvent& fbkevt,
  153. const uint& layer,
  154. const RawCameraGenerator::channel_id_t channel) {
  155. if (fbkevt.getGeneratorID() != EventBase::visRawCameraEGID) {
  156. fthrow(ImageException,
  157. "Invalid event GeneratorID (expected visRawCameraEGID).");
  158. }
  159. if (layer > 5) {
  160. fthrow(ImageException, "Invalid Layer.");
  161. }
  162. if (channel < RawCameraGenerator::CHAN_Y
  163. || channel > RawCameraGenerator::CHAN_Y_DXDY) {
  164. fthrow(ImageException, "Invalid Channel.");
  165. }
  166. FilterBankGenerator* gen = fbkevt.getSource();
  167. return Image(gen->getImage(layer, channel),
  168. gen->getWidth(layer),
  169. gen->getHeight(layer),
  170. GrayColorImageCommonImplementation::shallowCopy);
  171. }
  172. } // namespace NICE
  173. #endif // LIMUN_AIBO_MODE
  174. #endif // __LIMUN_TEKKOTSULINK_H__