MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / generate_patch_image

Function generate_patch_image

util/preprocessing.py:310–340  ·  view source on GitHub ↗
(cvimg, bbox, scale, rot, do_flip, out_shape)

Source from the content-addressed store, hash-verified

308
309
310def generate_patch_image(cvimg, bbox, scale, rot, do_flip, out_shape):
311 img = cvimg.copy()
312
313 img_height, img_width, img_channels = img.shape
314
315 bb_c_x = float(bbox[0] + 0.5 * bbox[2])
316 bb_c_y = float(bbox[1] + 0.5 * bbox[3])
317 bb_width = float(bbox[2])
318 bb_height = float(bbox[3])
319
320 if do_flip:
321 img = img[:, ::-1, :]
322 bb_c_x = img_width - bb_c_x - 1
323
324 trans = gen_trans_from_patch_cv(bb_c_x, bb_c_y, bb_width, bb_height,
325 out_shape[1], out_shape[0], scale, rot)
326 img_patch = cv2.warpAffine(img,
327 trans, (int(out_shape[1]), int(out_shape[0])),
328 flags=cv2.INTER_LINEAR)
329 img_patch = img_patch.astype(np.float32)
330 inv_trans = gen_trans_from_patch_cv(bb_c_x,
331 bb_c_y,
332 bb_width,
333 bb_height,
334 out_shape[1],
335 out_shape[0],
336 scale,
337 rot,
338 inv=True)
339
340 return img_patch, trans, inv_trans
341
342
343def rotate_2d(pt_2d, rot_rad):

Callers 2

augmentation_keep_sizeFunction · 0.85

Calls 2

gen_trans_from_patch_cvFunction · 0.85
copyMethod · 0.80

Tested by

no test coverage detected