INNER CODE UNIT · Python

cy

Anything-of-anything/Anything-3D · AnyObject3D/src/main.py:44

    cx, cy = (x1 + x2) / 2., (y1 + y2) / 2.
    w, h = x2 - x1, y2 - y1
    crop_sz = 1.8 * math.sqrt(w * h) # context_ratio
    x1, x2 = cx - crop_sz / 2., cx + crop_sz / 2.
    y1, y2 = cy - crop_sz / 2., cy + crop_sz / 2.
    x1, y1, x2, y2 = list(map(lambda x: int(x), [x1, y1, x2, y2]))

    # affine transform to get the object-centric image
    bbox = [x1, y1, x2, y2]
    output_sz = 512
    a = (output_sz-1) / (bbox[2]-bbox[0])
    b = (output_sz-1) / (bbox[3]-bbox[1])
    c = -a * bbox[0]
    d = -b * bbox[1]
    mapping = np.array([[a, 0, c],
                        [0, b, d]]).astype(np.float32)
    img_patch = cv2.warpAffine(image, mapping, (output_sz, output_sz), borderMode=cv2.BORDER_CONSTANT, borderValue=(0, 0, 0))
    mask_patch = cv2.warpAffine(mask, mapping, (output_sz, output_sz), borderMode=cv2.BORDER_CONSTANT, borderValue=0)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…