(self, imgfile)
| 104 | |
| 105 | |
| 106 | def predict(self, imgfile): |
| 107 | img_cv2 = cv2.imread(imgfile) |
| 108 | img_height, img_width, _ = img_cv2.shape |
| 109 | inpBlob = cv2.dnn.blobFromImage(img_cv2, |
| 110 | 1.0 / 255, |
| 111 | (self.inWidth, self.inHeight), |
| 112 | (0, 0, 0), |
| 113 | swapRB=False, |
| 114 | crop=False) |
| 115 | self.pose_net.setInput(inpBlob) |
| 116 | self.pose_net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV) |
| 117 | self.pose_net.setPreferableTarget(cv2.dnn.DNN_TARGET_OPENCL) |
| 118 | |
| 119 | output = self.pose_net.forward() |
| 120 | |
| 121 | H = output.shape[2] |
| 122 | W = output.shape[3] |
| 123 | print(output.shape) |
| 124 | |
| 125 | # vis heatmaps |
| 126 | self.vis_heatmaps(img_file, output) |
| 127 | |
| 128 | # |
| 129 | points = [] |
| 130 | for idx in range(self.num_points): |
| 131 | probMap = output[0, idx, :, :] # confidence map. |
| 132 | |
| 133 | # Find global maxima of the probMap. |
| 134 | minVal, prob, minLoc, point = cv2.minMaxLoc(probMap) |
| 135 | |
| 136 | # Scale the point to fit on the original image |
| 137 | x = (img_width * point[0]) / W |
| 138 | y = (img_height * point[1]) / H |
| 139 | |
| 140 | if prob > self.threshold: |
| 141 | points.append((int(x), int(y))) |
| 142 | else: |
| 143 | points.append(None) |
| 144 | |
| 145 | return points |
| 146 | |
| 147 | |
| 148 | def vis_heatmaps(self, imgfile, net_outputs): |
no test coverage detected