34 image = cv.resize(image, dsize=self.
input_size)
35 image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
36 image = image.astype(np.float32) / 255.0
37 image = (image - 0.5) * 2
38 return image[np.newaxis, :, :, :]
47 self.
model.setInput(input_blob)
48 output_blob = self.
model.forward()
51 score, palm_box, palm_landmarks = self.
_postprocess(output_blob, np.array([w, h]))
53 return (score, palm_box, palm_landmarks)
56 score = output_blob[0, :, 0]
57 box_delta = output_blob[0, :, 1:5]
58 landmark_delta = output_blob[0, :, 5:]
61 score = score.astype(np.float64)
62 score = 1 / (1 + np.exp(-score))
67 xy1 = (cxy_delta - wh_delta / 2 + self.
anchors[:, :2]) * original_shape
68 xy2 = (cxy_delta + wh_delta / 2 + self.
anchors[:, :2]) * original_shape
69 boxes = np.concatenate([xy1, xy2], axis=1)
72 if len(keep_idx) == 0:
73 return None,
None,
None
74 selected_score = score[keep_idx][0]
75 selected_box = boxes[keep_idx][0]
78 selected_landmarks = landmark_delta[keep_idx].reshape(7, 2)
79 selected_landmarks = (selected_landmarks / self.
input_size + self.
anchors[keep_idx]) * original_shape
81 return (selected_score, selected_box, selected_landmarks)