65 """Creates a label colormap used in PASCAL VOC segmentation benchmark.
67 A Colormap for visualizing segmentation results.
69 colormap = np.zeros((256, 3), dtype=int)
70 indices = np.arange(256, dtype=int)
72 for shift
in reversed(range(8)):
73 for channel
in range(3):
74 colormap[:, channel] |= ((indices >> channel) & 1) << shift
77 return colormap.astype(np.uint8)
81 """Creates a label colormap used in PASCAL VOC segmentation benchmark.
83 A Colormap for visualizing segmentation results.
85 colormap = np.zeros((256, 4), dtype=int)
86 indices = np.arange(256, dtype=int)
88 for shift
in reversed(range(8)):
89 for channel
in range(3):
90 colormap[:, channel] |= ((indices >> channel) & 1) << shift
93 colormap[:, 3] = alpha
95 return colormap.astype(np.uint8)
100 frame = inframe.getCvRGB()
if self.
rgb else inframe.getCvBGR()
107 width, height = common.input_size(self.
interpreter)
108 img = Image.fromarray(frame);
110 resized_img, _ = common.set_resized_input(self.
interpreter, img.size,
111 lambda size: img.resize(size, Image.LANCZOS))
113 resized_img = img.resize((width, height), Image.LANCZOS)
117 start = time.perf_counter()
119 inference_time = time.perf_counter() - start
123 if len(result.shape) == 3: result = np.argmax(result, axis=-1)
126 new_width, new_height = resized_img.size
127 result = result[:new_height, :new_width]
128 mask_img = Image.fromarray(self.
cmapRGB[result])
131 output_img = Image.new(
'RGB', (2 * img.width, img.height))
132 output_img.paste(img, (0, 0))
133 output_img.paste(mask_img.resize(img.size), (img.width, 0))
136 outcv = np.array(output_img)
139 cv.putText(outcv,
'JeVois Coral Segmentation - ' + self.
model, (3, 15),
140 cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1, cv.LINE_AA)
142 fps = self.
timer.stop()
143 label = fps +
', %dms' % (inference_time * 1000.0)
144 cv.putText(outcv, label, (3, h-5), cv.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1, cv.LINE_AA)
147 if self.
rgb: outframe.sendCvRGB(outcv)
148 else: outframe.sendCv(outcv)
154 idle, winw, winh = helper.startFrame()
157 x, y, w, h = helper.drawInputFrame(
"c", inframe,
False,
False)
160 frame = inframe.getCvRGBp()
if self.
rgb else inframe.getCvBGRp()
161 iw, ih = frame.shape[1], frame.shape[0]
167 width, height = common.input_size(self.
interpreter)
168 img = Image.fromarray(frame);
170 resized_img, _ = common.set_resized_input(self.
interpreter, img.size,
171 lambda size: img.resize(size, Image.LANCZOS))
173 resized_img = img.resize((width, height), Image.LANCZOS)
177 start = time.perf_counter()
179 inference_time = time.perf_counter() - start
183 if len(result.shape) == 3: result = np.argmax(result, axis=-1)
186 new_width, new_height = resized_img.size
187 result = result[:new_height, :new_width]
191 helper.drawImage(
"m", mask, self.
rgb,
False,
True)
194 helper.itext(
'JeVois-Pro Python Coral Segmentation - %s - %dms/inference' %
195 (self.
model, inference_time * 1000.0))
198 fps = self.
timer.stop()
199 helper.iinfo(inframe, fps, winw, winh);