Get bounding box for specific landmarks
(self, landmarks, indices, frame_shape)
| 15 | self.bar_y = None |
| 16 | |
| 17 | def get_bounding_box(self, landmarks, indices, frame_shape): |
| 18 | """Get bounding box for specific landmarks""" |
| 19 | h, w = frame_shape[:2] |
| 20 | points = [] |
| 21 | |
| 22 | for idx in indices: |
| 23 | lm = landmarks[idx] |
| 24 | x, y = int(lm.x * w), int(lm.y * h) |
| 25 | points.append([x, y]) |
| 26 | |
| 27 | points = np.array(points) |
| 28 | x, y, w_box, h_box = cv2.boundingRect(points) |
| 29 | |
| 30 | padding = 20 |
| 31 | x = max(0, x - padding) |
| 32 | y = max(0, y - padding) |
| 33 | w_box = w_box + 2 * padding |
| 34 | h_box = h_box + 2 * padding |
| 35 | |
| 36 | return x, y, w_box, h_box |
| 37 | |
| 38 | def process_frame(self, frame): |
| 39 | h, w = frame.shape[:2] |