GPU Accelerated Motion Detector/Examples/Library Usage: Difference between revisions

Line 185: Line 185:
std::shared_ptr<rr::Frame> input = std::make_shared<rr::GpuMatFrame>(matrix);
std::shared_ptr<rr::Frame> input = std::make_shared<rr::GpuMatFrame>(matrix);
</syntaxhighlight>
</syntaxhighlight>
== Serialize ==
Finally, as an optional step, you can serialize the obtained motion objects list using the provided serializer. The following code will return a JSON string with the moving objects:
<syntaxhighlight lang=c++>
rr::JsonSerializer<float> serializer;
std::string json_str = serializer.serialize(motion_list);
</syntaxhighlight>
The generated JSON string will look like this:
<syntaxhighlight lang=json>
{
    "ROIs": [{
  "motion": [{
  "x1": 0,
  "x2": 0.048437498509883881,
  "y1": 0.25208333134651184,
  "y2": 0.34375
  }, {
  "x1": 0.92343747615814209,
  "x2": 0.99843752384185791,
  "y1": 0.44374999403953552,
  "y2": 0.58541667461395264
  }],
  "name": "roi",
  "x1": 0,
  "x2": 1,
  "y1": 0,
  "y2": 1
    }]
}
</syntaxhighlight>