inferNode.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "nodes/base/base.hpp"
  2. #include "nodes/infer/inferNode.hpp"
  3. #include <unordered_map>
  4. #include <random>
  5. namespace Node
  6. {
  7. void InferNode::work()
  8. {
  9. printf("InferNode %s\n", name_.c_str());
  10. while (running_)
  11. {
  12. for (auto& input_buffer : input_buffers_)
  13. {
  14. std::shared_ptr<meta::MetaData> metaData;
  15. if (!input_buffer.second->try_pop(metaData))
  16. {
  17. continue;
  18. }
  19. printf("Node %s get data from %s\n", name_.c_str(), input_buffer.first.c_str());
  20. // do something
  21. cv::Mat image = metaData->image;
  22. int width = image.cols;
  23. int height = image.rows;
  24. // cv::imwrite("test.jpg", image);
  25. int x = rand() % width;
  26. int y = rand() % height;
  27. int w = rand() % (width - x);
  28. int h = rand() % (height - y);
  29. metaData->boxes.push_back(data::Box(x, y, x + w, y + h, 0.9, "test"));
  30. for (auto& output_buffer : output_buffers_)
  31. {
  32. printf("Node %s push data to %s\n", name_.c_str(), output_buffer.first.c_str());
  33. output_buffer.second->push(metaData);
  34. }
  35. }
  36. }
  37. };
  38. } // namespace Node