def draw_object(backg): obj = sample_object() mask = calculate_mask(obj) obj = photometric_seq(image=obj) det_aug = geometric_seq.to_deterministic() obj = det_aug(image=obj) mask = det_aug(image=mask) bin_mask = (mask > 0.1) * 1.0 row_mask = bin_mask.any(axis=1) col_mask = bin_mask.any(axis=0) Xs, = np.where(col_mask > 0.1) Ys, = np.where(row_mask > 0.1) try: x1, y1 = Xs.min(), Ys.min() x2, y2 = Xs.max(), Ys.max() except: x1, y1, x2, y2 = 0, 0, backg.shape[1], backg.shape[0] x1 *= backg.shape[1] / obj.shape[1] x2 *= backg.shape[1] / obj.shape[1] y1 *= backg.shape[0] / obj.shape[0] y2 *= backg.shape[0] / obj.shape[0] obj = cv2.resize(obj, (backg.shape[1], backg.shape[0])) mask = cv2.resize(mask, (backg.shape[1], backg.shape[0])) if mask.ndim < 3: mask = np.expand_dims(mask, -1) return (backg * (1 - mask) + obj * mask).astype('uint8'), x1, y1, x2, y2
def draw_object(backg): obj = sample_object() obj = photometric_seq(image=obj) obj = geometric_seq(image=obj) x1, y1, x2, y2 = 0, 0, obj.shape[1], obj.shape[0] x1 *= backg.shape[1] / obj.shape[1] x2 *= backg.shape[1] / obj.shape[1] y1 *= backg.shape[0] / obj.shape[0] y2 *= backg.shape[0] / obj.shape[0] obj = cv2.resize(obj, (backg.shape[1], backg.shape[0])) return obj.astype('uint8'), x1, y1, x2, y2