oak.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2021 Intel Corporation
  6. #ifndef OPENCV_GAPI_OAK_HPP
  7. #define OPENCV_GAPI_OAK_HPP
  8. #include <opencv2/gapi/garg.hpp> // IStreamSource
  9. #include <opencv2/gapi/gkernel.hpp> // GKernelPackage
  10. #include <opencv2/gapi/gstreaming.hpp> // GOptRunArgsP
  11. namespace cv {
  12. namespace gapi {
  13. namespace oak {
  14. // FIXME: copypasted from dai library
  15. struct EncoderConfig {
  16. /**
  17. * Rate control mode specifies if constant or variable bitrate should be used (H264 / H265)
  18. */
  19. enum class RateControlMode: int { CBR, VBR };
  20. /**
  21. * Encoding profile, H264, H265 or MJPEG
  22. */
  23. enum class Profile: int { H264_BASELINE, H264_HIGH, H264_MAIN, H265_MAIN, MJPEG };
  24. /**
  25. * Specifies preferred bitrate (kb) of compressed output bitstream
  26. */
  27. std::int32_t bitrate = 8000;
  28. /**
  29. * Every x number of frames a keyframe will be inserted
  30. */
  31. std::int32_t keyframeFrequency = 30;
  32. /**
  33. * Specifies maximum bitrate (kb) of compressed output bitstream
  34. */
  35. std::int32_t maxBitrate = 8000;
  36. /**
  37. * Specifies number of B frames to be inserted
  38. */
  39. std::int32_t numBFrames = 0;
  40. /**
  41. * This options specifies how many frames are available in this nodes pool (can help if
  42. * receiver node is slow at consuming
  43. */
  44. std::uint32_t numFramesPool = 4;
  45. /**
  46. * Encoding profile, H264, H265 or MJPEG
  47. */
  48. Profile profile = Profile::H265_MAIN;
  49. /**
  50. * Value between 0-100% (approximates quality)
  51. */
  52. std::int32_t quality = 80;
  53. /**
  54. * Lossless mode ([M]JPEG only)
  55. */
  56. bool lossless = false;
  57. /**
  58. * Rate control mode specifies if constant or variable bitrate should be used (H264 / H265)
  59. */
  60. RateControlMode rateCtrlMode = RateControlMode::CBR;
  61. /**
  62. * Input and compressed output frame width
  63. */
  64. std::int32_t width = 1920;
  65. /**
  66. * Input and compressed output frame height
  67. */
  68. std::int32_t height = 1080;
  69. /**
  70. * Frame rate
  71. */
  72. float frameRate = 30.0f;
  73. };
  74. G_API_OP(GEncFrame, <GArray<uint8_t>(GFrame, EncoderConfig)>, "org.opencv.oak.enc_frame") {
  75. static GArrayDesc outMeta(const GFrameDesc&, const EncoderConfig&) {
  76. return cv::empty_array_desc();
  77. }
  78. };
  79. G_API_OP(GSobelXY, <GFrame(GFrame, const cv::Mat&, const cv::Mat&)>, "org.opencv.oak.sobelxy") {
  80. static GFrameDesc outMeta(const GFrameDesc& in, const cv::Mat&, const cv::Mat&) {
  81. return in;
  82. }
  83. };
  84. G_API_OP(GCopy, <GFrame(GFrame)>, "org.opencv.oak.copy") {
  85. static GFrameDesc outMeta(const GFrameDesc& in) {
  86. return in;
  87. }
  88. };
  89. // FIXME: add documentation on operations below
  90. GAPI_EXPORTS GArray<uint8_t> encode(const GFrame& in, const EncoderConfig&);
  91. GAPI_EXPORTS GFrame sobelXY(const GFrame& in,
  92. const cv::Mat& hk,
  93. const cv::Mat& vk);
  94. GAPI_EXPORTS GFrame copy(const GFrame& in);
  95. // OAK backend & kernels ////////////////////////////////////////////////////////
  96. GAPI_EXPORTS cv::gapi::GBackend backend();
  97. GAPI_EXPORTS cv::gapi::GKernelPackage kernels();
  98. // Camera object ///////////////////////////////////////////////////////////////
  99. struct GAPI_EXPORTS ColorCameraParams {
  100. /**
  101. * Format of the frame one gets from the camera
  102. */
  103. bool interleaved = false;
  104. // FIXME: extend
  105. enum class BoardSocket: int { RGB, BGR };
  106. BoardSocket board_socket = BoardSocket::RGB;
  107. // FIXME: extend
  108. enum class Resolution: int { THE_1080_P };
  109. Resolution resolution = Resolution::THE_1080_P;
  110. };
  111. class GAPI_EXPORTS ColorCamera: public cv::gapi::wip::IStreamSource {
  112. cv::MediaFrame m_dummy;
  113. ColorCameraParams m_params;
  114. virtual bool pull(cv::gapi::wip::Data &data) override;
  115. virtual GMetaArg descr_of() const override;
  116. public:
  117. ColorCamera();
  118. explicit ColorCamera(const ColorCameraParams& params);
  119. };
  120. } // namespace oak
  121. } // namespace gapi
  122. namespace detail {
  123. template<> struct CompileArgTag<gapi::oak::ColorCameraParams> {
  124. static const char* tag() { return "gapi.oak.colorCameraParams"; }
  125. };
  126. template<> struct CompileArgTag<gapi::oak::EncoderConfig> {
  127. static const char* tag() { return "gapi.oak.encoderConfig"; }
  128. };
  129. } // namespace detail
  130. } // namespace cv
  131. #endif // OPENCV_GAPI_OAK_HPP