From 16a657e5e25e6e67e9545270a2d27c3313641c9b Mon Sep 17 00:00:00 2001 From: zhiboniu <31800336+zhiboniu@users.noreply.github.com> Date: Tue, 9 Aug 2022 20:54:35 +0800 Subject: [PATCH] car licenseplate skipframe&time counter vote (#6609) * car licenseplate skipframe&time counter vote * incase of no track --- deploy/pipeline/datacollector.py | 12 +++++++++++- deploy/pipeline/pipeline.py | 31 +++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/deploy/pipeline/datacollector.py b/deploy/pipeline/datacollector.py index fa12fc318..794711f04 100644 --- a/deploy/pipeline/datacollector.py +++ b/deploy/pipeline/datacollector.py @@ -14,6 +14,7 @@ import os import copy +from collections import Counter class Result(object): @@ -113,9 +114,18 @@ class DataCollector(object): idx]) self.collector[ids]["qualities"].append(reid_res['qualities'][ idx]) - if vehicleplate_res: + if vehicleplate_res and vehicleplate_res['plate'][idx] != "": self.collector[ids]["vehicleplate"].append(vehicleplate_res[ 'plate'][idx]) def get_res(self): return self.collector + + def get_carlp(self, trackid): + lps = self.collector[trackid]["vehicleplate"] + counter = Counter(lps) + carlp = counter.most_common() + if len(carlp) > 0: + return carlp[0][0] + else: + return None diff --git a/deploy/pipeline/pipeline.py b/deploy/pipeline/pipeline.py index 3ea65c113..6705083e5 100644 --- a/deploy/pipeline/pipeline.py +++ b/deploy/pipeline/pipeline.py @@ -781,7 +781,7 @@ class PipePredictor(object): crop_input, new_bboxes, ori_bboxes = crop_image_with_mot( frame_rgb, mot_res) - if self.with_vehicleplate: + if self.with_vehicleplate and frame_id % 10 == 0: if frame_id > self.warmup_frame: self.pipe_timer.module_time['vehicleplate'].start() plate_input, _, _ = crop_image_with_mot( @@ -791,6 +791,8 @@ class PipePredictor(object): if frame_id > self.warmup_frame: self.pipe_timer.module_time['vehicleplate'].end() self.pipeline_res.update(platelicense, 'vehicleplate') + else: + self.pipeline_res.clear('vehicleplate') if self.with_human_attr: if frame_id > self.warmup_frame: @@ -935,9 +937,9 @@ class PipePredictor(object): if self.cfg['visual']: _, _, fps = self.pipe_timer.get_total_time() - im = self.visualize_video(frame, self.pipeline_res, frame_id, - fps, entrance, records, - center_traj) # visualize + im = self.visualize_video( + frame, self.pipeline_res, self.collector, frame_id, fps, + entrance, records, center_traj) # visualize writer.write(im) if self.file_name is None: # use camera_id cv2.imshow('Paddle-Pipeline', im) @@ -950,6 +952,7 @@ class PipePredictor(object): def visualize_video(self, image, result, + collector, frame_id, fps, entrance=None, @@ -1006,12 +1009,20 @@ class PipePredictor(object): image = visualize_attr(image, vehicle_attr_res, boxes) image = np.array(image) - vehicleplate_res = result.get('vehicleplate') - if vehicleplate_res: - boxes = mot_res['boxes'][:, 1:] - image = visualize_vehicleplate(image, vehicleplate_res['plate'], - boxes) - image = np.array(image) + if mot_res is not None: + vehicleplate = False + plates = [] + for trackid in mot_res['boxes'][:, 0]: + plate = collector.get_carlp(trackid) + if plate != None: + vehicleplate = True + plates.append(plate) + else: + plates.append("") + if vehicleplate: + boxes = mot_res['boxes'][:, 1:] + image = visualize_vehicleplate(image, plates, boxes) + image = np.array(image) kpt_res = result.get('kpt') if kpt_res is not None: -- GitLab