openMVG / openMVG

open Multiple View Geometry library. Basis for 3D computer vision and Structure from Motion.
Mozilla Public License 2.0
5.66k stars 1.67k forks source link

The format of the MVG's SfM result #594

Closed xialang2012 closed 8 years ago

xialang2012 commented 8 years ago

Hi, @pmoulon I intend to convert the OpenSfM https://github.com/mapillary/OpenSfM result to the MVE format, and then I can get the dense cloud point by using the openMVG dmrecon tool. Now, the problem is that I do not know the output result format of the openMVG's SfM tool. I need some help to do it.

autosquid commented 8 years ago

I have a similar question: is it a good idea to add an option of output format (ascii or binary) be to the software?

pmoulon commented 8 years ago

@xialang2012 I don't know why you are speaking about OpenSfM on the OpenMVG issue... BTW, dmrecon is not a OpenMVG tool, it is a MVE tool and the usage of OpenMVG for MVE is explained here http://openmvg.readthedocs.io/en/latest/software/MVS/MVE/#mve-multi-view-environment

@xialang2012, @autosquid Default output format of OpenMVG sfm results is not in binary format, but in can be converted easily in various format (json, xml, ascii, PLY). See the usage of openMVG_main_ConvertSfM_DataFormat

./openMVG_main_ConvertSfM_DataFormat 
Usage: ./openMVG_main_ConvertSfM_DataFormat
[-i|--input_file] path to the input SfM_Data scene
[-o|--output_file] path to the output SfM_Data scene
     .json, .bin, .xml, .ply, .baf

[Options to export partial data (by default all data are exported)]

Usable for json/bin/xml format
[-V|--VIEWS] export views
[-I|--INTRINSICS] export intrinsics
[-E|--EXTRINSICS] export extrinsics (view poses)
[-S|--STRUCTURE] export structure
[-C|--CONTROL_POINTS] export control points

So you can do the following (default option export all the data)

./openMVG_main_ConvertSfM_DataFormat -i ./sfm_data.bin -o ./sfm_data.json
xialang2012 commented 8 years ago

Sorry, I did not make myself clear. But from you response, I have got the answer. Thank you pmoulon.

pmoulon commented 8 years ago

Can you close the issue or do you have another questions?

xialang2012 commented 8 years ago

Ok

xialang2012 commented 8 years ago

Hi @pmoulon, Do you know how is the OpenMVS in put scene.mvs binary file format. I used the command

openMVG_main_openMVG2openMVS -i global/sfm_data.bin -d tomvs -o tomvs/scene.mvs

to get the scene.mvs, but I do not know the structure was arranged.

pmoulon commented 8 years ago

You can read the saving code there https://github.com/openMVG/openMVG/blob/master/src/software/SfM/InterfaceMVS.h

xialang2012 commented 8 years ago

Thank you. I tried to export the OpenSfM result to OpenMVS, and I read the codes in OpenMVG https://github.com/openMVG/openMVG/blob/master/src/software/SfM/main_openMVG2openMVS.cpp. Below is my question.

Does the sfm_data.GetIntrinsics().size() return the number of view? I found the sfm_data.json exported by openMVG_main_ConvertSfM_DataFormat shows that one json file owns "intrinsics" and "extrinsics" array, and "intrinsics" seems has one key and value, as below:

    "intrinsics": [
        {
            "key": 0,
            "value": {
                "polymorphic_id": 2147483649,
                "polymorphic_name": "pinhole_radial_k3",
                "ptr_wrapper": {
                    "id": 2147483657,
                    "data": {
                        "width": 1000,
                        "height": 1000,
                        "focal_length": 3969.6880368381389,
                        "principal_point": [
                            537.918929758339,
                            483.93989077748427
                        ],
                        "disto_k3": [
                            -0.2675739922324965,
                            6.371365606789265,
                            -79.15161480442211
                        ]
                    }
                }
            }
        }
    ],

but "extrinsics" have many keys and values, and the number of the keys and values is as same as the camera number. So, I mean the sfm_data.GetIntrinsics().size() return the number of "extrinsics"'s keys and values, not the "intrinsics"'?

pmoulon commented 8 years ago

The OpenMVG SFM data format store:

sfm_data.GetIntrinsics().size() returns the number of intrinsic group, so if there is no shared intrinsics, it will return the number of view initialized with intrinsic data. In your case you have no grouped camera and so sfm_data.GetIntrinsics().size() == sfm_data.GetPoses().size() == sfm_data.GetViews().size()

PS: would be nice to put a link towards the OpenMVG exporter as a not inside your OpenSfM exporter.

xialang2012 commented 8 years ago

Of cause, I should do what like you suggestion. But I am a new one about the SfM, so, it will take a long time to do that. By the way, I think it would be great if you are interesting about making a exporter to convert the OpenSfM results to your OpenMVG format? :smile:

xialang2012 commented 8 years ago

https://github.com/mapillary/OpenSfM/commit/d3362ce7efd2575c798afc153ae2bbd333d7777c