MCPcopy
hub / github.com/sml2h3/ddddocr / get_bbox

Method get_bbox

ddddocr/core/detection_engine.py:173–212  ·  view source on GitHub ↗

原始的目标检测方法

(self, image_bytes)

Source from the content-addressed store, hash-verified

171 return self.multiclass_nms_class_agnostic(boxes, scores, nms_thr, score_thr)
172
173 def get_bbox(self, image_bytes):
174 """原始的目标检测方法"""
175 img = cv2.imdecode(np.frombuffer(image_bytes, np.uint8), cv2.IMREAD_COLOR)
176 im, ratio = self.preproc(img, (416, 416))
177 ort_inputs = {self.session.get_inputs()[0].name: im[None, :, :, :]}
178 output = self.session.run(None, ort_inputs)
179 predictions = self.demo_postprocess(output[0], (416, 416))[0]
180 boxes = predictions[:, :4]
181 scores = predictions[:, 4:5] * predictions[:, 5:]
182 boxes_xyxy = np.ones_like(boxes)
183 boxes_xyxy[:, 0] = boxes[:, 0] - boxes[:, 2] / 2.
184 boxes_xyxy[:, 1] = boxes[:, 1] - boxes[:, 3] / 2.
185 boxes_xyxy[:, 2] = boxes[:, 0] + boxes[:, 2] / 2.
186 boxes_xyxy[:, 3] = boxes[:, 1] + boxes[:, 3] / 2.
187 boxes_xyxy /= ratio
188 pred = self.multiclass_nms(boxes_xyxy, scores, nms_thr=0.45, score_thr=0.1)
189 try:
190 final_boxes = pred[:, :4].tolist()
191 result = []
192 for b in final_boxes:
193 if b[0] < 0:
194 x_min = 0
195 else:
196 x_min = int(b[0])
197 if b[1] < 0:
198 y_min = 0
199 else:
200 y_min = int(b[1])
201 if b[2] > img.shape[1]:
202 x_max = int(img.shape[1])
203 else:
204 x_max = int(b[2])
205 if b[3] > img.shape[0]:
206 y_max = int(img.shape[0])
207 else:
208 y_max = int(b[3])
209 result.append([x_min, y_min, x_max, y_max])
210 except Exception as e:
211 return []
212 return result

Callers 1

predictMethod · 0.95

Calls 3

preprocMethod · 0.95
demo_postprocessMethod · 0.95
multiclass_nmsMethod · 0.95

Tested by

no test coverage detected