cdcseacave / openMVS

open Multi-View Stereo reconstruction library
http://cdcseacave.github.io
GNU Affero General Public License v3.0
3.18k stars 891 forks source link

camera pose I drew did not match the camera pose directly viewed from the MVS file #1148

Open JV-X opened 4 weeks ago

JV-X commented 4 weeks ago

Hi, I generated a JSON file from the MVS file and read the camera pose from the JSON file. I used Open3D to visualize the read camera pose and the point cloud read from the PLY file. However, when I rendered the 3D view, I found that the camera pose I drew did not match the camera pose directly viewed from the MVS file. They are as follows: Camera pose as I drew it: Idraw idraw2

Camera pose as seen in the MVS file: frommvs frommvs1

Here is my drawing code:

import json
import numpy as np
import open3d as o3d

def camera3():

    file_path = "test\scene_2.json"
    data = None
    with open(file_path,'r') as f:
        data = json.loads(f.read())['platforms'][0]

    K = np.array(data['cameras'][0]['K'])
    camera = data['cameras'][0]
    poses = camera['poses']

    vizualizer = o3d.visualization.Visualizer()
    vizualizer.create_window(width=camera['width'], height=camera['height'])

    for pose in poses:
        R = np.array(pose['R'])
        C = np.array(pose['C'])

        intrinsic = o3d.camera.PinholeCameraIntrinsic()
        intrinsic.set_intrinsics(
            width=data['cameras'][0]['width'],
            height=data['cameras'][0]['height'],
            fx=K[0, 0],
            fy=K[1, 1],
            cx=K[0, 2],
            cy=K[1, 2]
        )

        extrinsic = np.eye(4)
        extrinsic[:3, :3] = R
        extrinsic[:3, 3] = C

        camera_lineset = o3d.geometry.LineSet.create_camera_visualization(
            intrinsic=intrinsic,
            extrinsic=extrinsic,
            scale=0.1 
        )
        vizualizer.add_geometry(camera_lineset)

    pcd = o3d.io.read_point_cloud("test/texture.ply")
    # o3d.visualization.draw_geometries([camera_lineset, pcd])
    vizualizer.add_geometry(pcd)
    vizualizer.run()

if __name__ == '__main__':
    camera3()

Here are the files that I used: test.zip

I don't know why there is such a discrepancy. Is there something wrong with my code? any suggestions? thanks for your reply.

cdcseacave commented 3 weeks ago

the full description of how to interpret the camera matrices is in the Interface.h file

JV-X commented 3 weeks ago

the full description of how to interpret the camera matrices is in the Interface.h file

thanks for your reply