MCPcopy Create free account
hub / github.com/deepbrainai-research/float / process_img

Method process_img

generate.py:38–57  ·  view source on GitHub ↗
(self, img:np.ndarray)

Source from the content-addressed store, hash-verified

36
37 @torch.no_grad()
38 def process_img(self, img:np.ndarray) -> np.ndarray:
39 mult = 360. / img.shape[0]
40
41 resized_img = cv2.resize(img, dsize=(0, 0), fx = mult, fy = mult, interpolation=cv2.INTER_AREA if mult < 1. else cv2.INTER_CUBIC)
42 bboxes = self.fa.face_detector.detect_from_image(resized_img)
43 bboxes = [(int(x1 / mult), int(y1 / mult), int(x2 / mult), int(y2 / mult), score) for (x1, y1, x2, y2, score) in bboxes if score > 0.95]
44 bboxes = bboxes[0] # Just use first bbox
45
46 bsy = int((bboxes[3] - bboxes[1]) / 2)
47 bsx = int((bboxes[2] - bboxes[0]) / 2)
48 my = int((bboxes[1] + bboxes[3]) / 2)
49 mx = int((bboxes[0] + bboxes[2]) / 2)
50
51 bs = int(max(bsy, bsx) * 1.6)
52 img = cv2.copyMakeBorder(img, bs, bs, bs, bs, cv2.BORDER_CONSTANT, value=0)
53 my, mx = my + bs, mx + bs # BBox center y, bbox center x
54
55 crop_img = img[my - bs:my + bs,mx - bs:mx + bs]
56 crop_img = cv2.resize(crop_img, dsize = (self.input_size, self.input_size), interpolation = cv2.INTER_AREA if mult < 1. else cv2.INTER_CUBIC)
57 return crop_img
58
59 def default_img_loader(self, path) -> np.ndarray:
60 img = cv2.imread(path)

Callers 1

preprocessMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected