1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #include <algorithm>
- #include <cstring>
- #include <iostream>
- #include <memory>
- #include <string>
- #include <utility>
- #include <vector>
- #include "cnstream_frame_va.hpp"
- #include "postproc.hpp"
- using std::cerr;
- using std::endl;
- using std::pair;
- using std::to_string;
- using std::vector;
- class PostprocSsd : public cnstream::Postproc {
- public:
-
- int Execute(const std::vector<float*>& net_outputs, const std::shared_ptr<edk::ModelLoader>& model,
- const cnstream::CNFrameInfoPtr& package) override;
- DECLARE_REFLEX_OBJECT_EX(PostprocSsd, cnstream::Postproc)
- };
- #define CLIP(x) ((x) < 0 ? 0 : ((x) > 1 ? 1 : (x)))
- IMPLEMENT_REFLEX_OBJECT_EX(PostprocSsd, cnstream::Postproc)
- int PostprocSsd::Execute(const std::vector<float*>& net_outputs, const std::shared_ptr<edk::ModelLoader>& model,
- const cnstream::CNFrameInfoPtr& package) {
- auto data = net_outputs[0];
-
- auto box_num = data[0];
- data += 64;
- cnstream::CNInferObjsPtr objs_holder = package->collection.Get<cnstream::CNInferObjsPtr>(cnstream::kCNInferObjsTag);
- cnstream::CNObjsVec& objs = objs_holder->objs_;
- for (decltype(box_num) bi = 0; bi < box_num; ++bi) {
- if (data[1] == 0) continue;
- if (threshold_ > 0 && data[2] < threshold_) continue;
- std::shared_ptr<cnstream::CNInferObject> object = std::make_shared<cnstream::CNInferObject>();
- object->id = std::to_string(data[1] - 1);
- object->score = data[2];
- object->bbox.x = data[3];
- object->bbox.y = data[4];
- object->bbox.w = data[5] - object->bbox.x;
- object->bbox.h = data[6] - object->bbox.y;
- std::lock_guard<std::mutex> objs_mutex(objs_holder->mutex_);
- objs.push_back(object);
- data += 7;
- }
- return 0;
- }
|