(self, imgfile)
| 35 | |
| 36 | |
| 37 | def predict(self, imgfile): |
| 38 | img_cv2 = cv2.imread(imgfile) |
| 39 | img_height, img_width, _ = img_cv2.shape |
| 40 | aspect_ratio = img_width / img_height |
| 41 | |
| 42 | inWidth = int(((aspect_ratio * self.inHeight) * 8) // 8) |
| 43 | inpBlob = cv2.dnn.blobFromImage(img_cv2, 1.0 / 255, (inWidth, self.inHeight), (0, 0, 0), swapRB=False, crop=False) |
| 44 | |
| 45 | self.hand_net.setInput(inpBlob) |
| 46 | |
| 47 | output = self.hand_net.forward() |
| 48 | |
| 49 | # vis heatmaps |
| 50 | self.vis_heatmaps(imgfile, output) |
| 51 | |
| 52 | # |
| 53 | points = [] |
| 54 | for idx in range(self.num_points): |
| 55 | probMap = output[0, idx, :, :] # confidence map. |
| 56 | probMap = cv2.resize(probMap, (img_width, img_height)) |
| 57 | |
| 58 | # Find global maxima of the probMap. |
| 59 | minVal, prob, minLoc, point = cv2.minMaxLoc(probMap) |
| 60 | |
| 61 | if prob > self.threshold: |
| 62 | points.append((int(point[0]), int(point[1]))) |
| 63 | else: |
| 64 | points.append(None) |
| 65 | |
| 66 | return points |
| 67 | |
| 68 | |
| 69 | def vis_heatmaps(self, imgfile, net_outputs): |
no test coverage detected