#ifdef VP_WITH_TRT #include "vp_trt_vehicle_plate_detector.h" namespace vp_nodes { vp_trt_vehicle_plate_detector::vp_trt_vehicle_plate_detector(std::string node_name, std::string plate_det_model_path, std::string char_rec_model_path): vp_secondary_infer_node(node_name, "") { plate_detector = std::make_shared(plate_det_model_path, char_rec_model_path); this->initialized(); } vp_trt_vehicle_plate_detector::~vp_trt_vehicle_plate_detector() { deinitialized(); } void vp_trt_vehicle_plate_detector::postprocess(const std::vector& raw_outputs, const std::vector>& frame_meta_with_batch) { } // please refer to vp_infer_node::run_infer_combinations void vp_trt_vehicle_plate_detector::run_infer_combinations(const std::vector>& frame_meta_with_batch) { assert(frame_meta_with_batch.size() == 1); std::vector mats_to_infer; // start auto start_time = std::chrono::system_clock::now(); // prepare data, as same as base class vp_secondary_infer_node::prepare(frame_meta_with_batch, mats_to_infer); auto prepare_time = std::chrono::duration_cast(std::chrono::system_clock::now() - start_time); start_time = std::chrono::system_clock::now(); // here we detect vehicle plate for all target(like car/bus) in frame std::vector> plates; plate_detector->detect(mats_to_infer, plates, true); // detect at most 1 plate for each image auto& frame_meta = frame_meta_with_batch[0]; for (int i = 0; i < plates.size(); i++) { for (int j = 0; j < plates[i].size(); j++) { auto& plate = plates[i][j]; // only plate detection but no recognition result if (plate.text.empty()) { continue; } // check value range auto x = std::max(0, plate.x + frame_meta->targets[i]->x - 10); // offset auto y = std::max(0, plate.y + frame_meta->targets[i]->y - 8); // offset auto w = std::min(plate.width, frame_meta->frame.cols - x); auto h = std::min(plate.height, frame_meta->frame.rows - y); if (w <= 0 || h <=0) { continue; } // create sub target and update back into frame meta // we treat vehicle plate as sub target of those in vp_frame_meta.targets auto sub_target = std::make_shared(x, y, w, h, -1, 0, plate.color + "_" + plate.text, frame_meta->frame_index, frame_meta->channel_index); frame_meta->targets[i]->sub_targets.push_back(sub_target); } } auto infer_time = std::chrono::duration_cast(std::chrono::system_clock::now() - start_time); // can not calculate preprocess time and postprocess time, set 0 by default. vp_infer_node::infer_combinations_time_cost(mats_to_infer.size(), prepare_time.count(), 0, infer_time.count(), 0); } } #endif