MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / read_frame

Function read_frame

eval_video_segmentation.py:197–221  ·  view source on GitHub ↗

read a single frame & preprocess

(frame_dir, scale_size=[480])

Source from the content-addressed store, hash-verified

195
196
197def read_frame(frame_dir, scale_size=[480]):
198 """
199 read a single frame & preprocess
200 """
201 img = cv2.imread(frame_dir)
202 ori_h, ori_w, _ = img.shape
203 if len(scale_size) == 1:
204 if(ori_h > ori_w):
205 tw = scale_size[0]
206 th = (tw * ori_h) / ori_w
207 th = int((th // 64) * 64)
208 else:
209 th = scale_size[0]
210 tw = (th * ori_w) / ori_h
211 tw = int((tw // 64) * 64)
212 else:
213 th, tw = scale_size
214 img = cv2.resize(img, (tw, th))
215 img = img.astype(np.float32)
216 img = img / 255.0
217 img = img[:, :, ::-1]
218 img = np.transpose(img.copy(), (2, 0, 1))
219 img = torch.from_numpy(img).float()
220 img = color_normalize(img)
221 return img, ori_h, ori_w
222
223
224def read_seg(seg_dir, factor, scale_size=[480]):

Callers 1

Calls 1

color_normalizeFunction · 0.85

Tested by

no test coverage detected