rga_processor.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <cstdint>
  3. #include <vector>
  4. #include "rtsp_capture.h"
  5. class RgaProcessor {
  6. public:
  7. RgaProcessor() = default;
  8. ~RgaProcessor();
  9. // Initialize with target input size for the model (e.g. 640x640)
  10. bool init(int target_w, int target_h);
  11. // Convert NV12 to RGB and resize to target size
  12. // Returns RGB data in NHWC format, normalized to [0,1] as float
  13. // Also returns the scale factor and padding offsets for coordinate mapping
  14. bool process(const Nv12Frame& nv12,
  15. std::vector<float>& output,
  16. float& scale, int& pad_x, int& pad_y);
  17. // Get the scale factor used in last process() call
  18. float lastScale() const { return last_scale_; }
  19. int lastPadX() const { return last_pad_x_; }
  20. int lastPadY() const { return last_pad_y_; }
  21. // Direct NV12->RGB without normalization (for display/JPEG encoding)
  22. bool processToRgb(const Nv12Frame& nv12, std::vector<uint8_t>& rgb_out,
  23. int& out_w, int& out_h);
  24. private:
  25. int target_w_ = 640;
  26. int target_h_ = 640;
  27. float last_scale_ = 1.0f;
  28. int last_pad_x_ = 0;
  29. int last_pad_y_ = 0;
  30. // Software fallback methods
  31. void softwareNv12ToRgb(const Nv12Frame& nv12, std::vector<uint8_t>& rgb,
  32. int out_w, int out_h);
  33. };