VAST-AI-Research / TripoSR

MIT License
4.47k stars 512 forks source link

camera distance question #87

Open gtangg12 opened 6 months ago

gtangg12 commented 6 months ago

What camera distance should I set render to get the original image, assuming I set height and width to be the same as the original image and leave all other params default? For example, for chair, horse, and robot (512x512), i resize to 256x256 (avoid memory) and set the render distance to 1.8 to get a extremely close rendering in scale.

def preprocess(self, image: Image.Image, remove_bg=True, downsample=1):
        """
        Remove the background and handle the alpha channel if needed
        """
        if downsample > 1:
            image = image.resize((image.width // downsample, image.height // downsample))
        if remove_bg:
            image = remove_background(image, self.rembg_session)
        image = np.array(image).astype(np.float32) / 255.0
        if image.shape[-1] == 4:
            alpha = image[:, :, 3:4]
            image = image[:, :,  :3] * alpha + 0.5 * (1 - alpha)
        return image

image = self.preprocess(image, remove_bg=remove_bg, downsample=downsample)

with torch.no_grad():
    scene_codes = self.model([image], device='cuda' if torch.cuda.is_available() else 'cpu')
render_images = self.model.render(scene_codes, camera_distance=1.8, n_views=30, return_type="pil")
for ri, render_image in enumerate(render_images[0]):
    print(render_image.size)
    render_image.save('test_render.png')
    break
Image.fromarray((image * 255).astype(np.uint8)).save('test_input.png')
MontaEllis commented 2 months ago

Same question!

MontaEllis commented 2 months ago

maybe should be 1.87