cdcseacave / openMVS

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

how can i texturing an 3d model by using openMVS? #225

Closed dejunzhang closed 1 year ago

dejunzhang commented 7 years ago

Specifications like the version of the project, operating system, and hardware

master version. ubuntu14.04 and Dell5610

Steps to reproduce the problem

Hi, i have already using rgb-d input images to reconstruct a 3d model in ply or obj format. and i know the pose for each input depth and rgb images. Now i want to use openMVS to texture the 3d model by using some of the rgb images. how can i do it? Can i only use TextureMesh to do the above work? but i don't get the mvs file and config file , how can i get these input files? It would be appreciated if you could give me some suggestions, Thanks a lot.

cdcseacave commented 7 years ago

It can be done relatively easy, but you have to augment the Interface.h with support for meshes (which is the input you desire to use if I understood right). That is simply adding a list of vertices and faces (indices to the vertices), and load them inside Scene structure. You only need to get your hands dirty with C++, but I can guide you if needed.

dejunzhang commented 7 years ago

@cdcseacave , thanks a lot for your kindly suggestions. It would be appreciated if you could guide me how to modify it. :) Now i only have a mesh 3d model , pose and rgb inputs. how to modify and use openMVS.

cdcseacave commented 7 years ago

I added support for mesh input to the interface. Pls use the mesh_interface branch. All you need to do now, is to fill it in with your data, and use the mesh structure during Load() to fill in the mesh inside Scene object.

dejunzhang commented 7 years ago

@cdcseacave thanks for your kindly help on adding mesh structure in mesh_interface branch. one more question. Currently i have a mesh 3d model , pose and rgb input images. how can i convert them into scene.mvs file ? Do i have to implement a interface to convert the above inputs into scene.mvs file, is there any better way to do this?

cdcseacave commented 7 years ago

Yes. You can have a look at InterfaceVisualSFM how the data from VisualSFM format are converted to OpenMVS. All you need is the Interface.h file, with no other dependencies to OpenMVS.

dejunzhang commented 7 years ago

@cdcseacave ,Thanks a lot for your kindly help. I have already implement the interface to convert obj model, rgb images and related pose. But i still meet some problems. My code is as below for the conversion, please have a check: if(OPT_App::strInputFileName == NULL)return false; std::ifstream in(OPT_App::strInputFileName); printf("Loading cameras,mesh,points: %s\n",OPT_App::strInputFileName.c_str()); LOG_OUT() << "Loading cameras,mesh,points: " << OPT_App::strInputFileName <<"\n" ; if(!in.is_open()) return false;

//load mesh.
in>>OPT_App::strMeshFileName;

//load input texture images.
LoadTextureImage(in,cameras, names);
printf("Finish loading LoadTextureImage. ncameras: %d\n",cameras.size());

Scene scene(OPT_App::nMaxThreads);
// load and texture the mesh
scene.platforms.Reserve((uint32_t)cameras.size());
scene.images.Reserve((uint32_t)cameras.size());
scene.nCalibratedImages = 0;
for (size_t idx=0; idx<cameras.size(); ++idx) {
    MVS::Image& image = scene.images.AddEmpty();
    image.name = names[idx];
    Util::ensureUnifySlash(image.name);
    image.name = MAKE_PATH_FULL(WORKING_FOLDER_FULL, image.name);
    printf("opening image[%d]: %s.\n",idx,image.name.c_str());
    if (!image.ReloadImage(0, false)) {
        LOG("error: can not read image %s", image.name.c_str());
        printf("error: can not read image %s", image.name.c_str());
        return EXIT_FAILURE;
    }
    // set camera
    image.platformID = scene.platforms.GetSize();
    MVS::Platform& platform = scene.platforms.AddEmpty();
    MVS::Platform::Camera& camera = platform.cameras.AddEmpty();
    image.cameraID = 0;
    const PBA::CameraT& cameraNVM = cameras[idx];
    //camera.K = cameraNVM.GetFocalLength();
    //const float *K = (float *)cameraNVM.GetFocalLength();
    camera.K(0, 0) = cameraNVM.GetFocalLengthFx();camera.K(0, 1) = 0.0;camera.K(0, 2) = cameraNVM.GetFocalLengthCx();
    camera.K(1, 0) = 0.0;camera.K(1, 1) = cameraNVM.GetFocalLengthFy();camera.K(1, 2) = cameraNVM.GetFocalLengthCy();
    camera.K(2, 0) = 0.0;camera.K(2, 1) = 0.0;camera.K(2, 2) = 1.0;

    camera.R = RMatrix::IDENTITY;
    camera.C = CMatrix::ZERO;
    // normalize camera intrinsics
    const REAL fScale(REAL(1)/MVS::Camera::GetNormalizationScale(image.width, image.height));
    camera.K(0, 0) *= fScale;
    camera.K(1, 1) *= fScale;
    camera.K(0, 2) *= fScale;
    camera.K(1, 2) *= fScale;
    // set pose
    image.poseID = platform.poses.GetSize();
    MVS::Platform::Pose& pose = platform.poses.AddEmpty();
    cameraNVM.GetMatrixRotation(pose.R.val);
    cameraNVM.GetCameraCenter(pose.C.ptr());
    image.UpdateCamera(scene.platforms);
    ++scene.nCalibratedImages;
}
printf("Finish convert mvs scene.\n");

printf("Beginning to load mesh:%s\n",OPT_App::strMeshFileName.c_str());

if (!OPT_App::strMeshFileName.IsEmpty()) {
    // load given mesh
    scene.mesh.Load(MAKE_PATH_SAFE(OPT_App::strMeshFileName));
}
if (scene.mesh.IsEmpty()) {
    VERBOSE("error: empty initial mesh");
    return EXIT_FAILURE;
}
printf("Finish loading input mesh.\n");

const String baseFileName(MAKE_PATH_SAFE(Util::getFullFileName(OPT_App::strOutputFileName)));
if (OPT_App::nOrthoMapResolution && !scene.mesh.textureDiffuse.empty()) {
    // the input mesh is already textured and an orthographic projection was requested
    goto ProjectOrtho;
}

Does above code enough for read obj model file and n rgb images and its relates pose. I check the parameters, they are right. Firstly ,the program crashed here(SceneTexture.cpp line 853): ASSERT(ISINSIDE((int)afaces.GetSize(), 1, 4)); After modifing to : ASSERT(ISINSIDE((int)afaces.GetSize(), 0, 4));

i meet another errors: /media/dejun/work/slam/texture/openMVS-master/libs/MVS/../Common/List.h:353: TYPE& SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::operator[](SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::IDX) [with TYPE = MeshTexture::TexturePatch; ARG_TYPE = const MeshTexture::TexturePatch&; int useConstruct = 1; int grow = 1024; IDX_TYPE = unsigned int; SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::IDX = unsigned int]: Assertion `index < _size' failed.

I checked ,and found that it crashed in function MeshTexture::GenerateTexture(), the size of the input texturePatches is 1 when crash happens.

BTW, there might be a bug in ./libs/IO/OBJ.cpp line 236, like below line: groups.back().faces.push_back(f); At the beginning, the groups should be empty. so we should not use back() to get last element here.

cdcseacave commented 7 years ago

At the first sight, the code looks ok, I could tell more if I had the sample you use for testing. The first ASSERT is usually due to meshes that are non-manifold. The OBJ is fine as long as it does not crash (calling back() for an empty vector results in crash).

dejunzhang commented 7 years ago

@cdcseacave , Thanks a lot. it would be appreciated if you could help to have a check. i use the below datasets: http://redwood-data.org/3dscan/models.html?i=6969 after downloading the 3d model (06969.ply) and rgb, depth sequences. Use 06969.ply as input 3d model. And just extract 43 rgb images as texture images. and its pose are as below: My algorithm needs to start with 0000000.jpg. as the original rgb/depth sequence don't have 0000000.jpg 000000.png, So i just copy 0000001.jpg to 0000000.jpg and 0000001.png to 0000000.png.

0000000.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0000100.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.999978 -0.004160 0.005158 0.004483 0.997916 -0.064369 -0.004879 0.064391 0.997913 -0.050124 0.847654 0.318013 0000200.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.995968 0.085037 0.028587 -0.082821 0.994004 -0.071389 -0.034486 0.068734 0.997039 0.029757 -0.048607 -0.004136 0000300.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.982922 0.013489 0.183527 -0.018574 0.999489 0.026014 -0.183082 -0.028978 0.982670 0.537884 0.770339 0.284183 0000400.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.971139 0.037763 0.235506 -0.025760 0.998217 -0.053839 -0.237119 0.046219 0.970380 0.638015 -0.056752 0.060844 0000500.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.823943 -0.039201 0.565316 0.021574 0.999051 0.037833 -0.566262 -0.018976 0.824007 1.067848 0.847604 0.533184 0000600.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.535870 -0.224439 0.813923 0.229450 0.966451 0.115433 -0.812524 0.124898 0.569390 1.609978 -0.130920 0.877382 0000700.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.562922 -0.131693 0.815951 0.197707 0.980019 0.021775 -0.802515 0.149061 0.577711 1.559273 0.414812 1.149363 0000800.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.045168 -0.169225 0.984542 0.155374 0.974744 0.160413 -0.986823 0.145727 0.070320 1.866431 -0.139793 1.574063 0000900.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.054975 -0.191106 0.980029 0.186903 0.966134 0.177912 -0.980839 0.173390 0.088832 1.643780 0.433889 1.685089 0001000.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.033389 -0.160527 0.986466 0.170538 0.971627 0.163885 -0.984785 0.173703 -0.005066 1.437272 -0.271269 1.629665 0001100.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.170774 -0.103622 0.979846 0.154650 0.979310 0.130519 -0.973098 0.173822 -0.151215 1.427608 -0.279033 1.820772 0001200.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.449830 -0.163153 0.878085 0.066454 0.974333 0.215079 -0.890639 0.155101 -0.427442 1.234545 0.501183 2.326214 0001300.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.410964 -0.174244 0.894845 0.162369 0.951882 0.259919 -0.897076 0.252113 -0.362897 1.216115 0.631897 2.337063 0001400.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.716354 -0.142029 0.683129 0.091450 0.951505 0.293726 -0.691718 0.272884 -0.668626 1.067543 -0.459448 2.668353 0001500.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.876743 -0.073748 0.475272 0.067710 0.959407 0.273778 -0.476169 0.272213 -0.836159 0.792520 0.464507 2.813143 0001600.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.869137 -0.053134 0.491709 0.126204 0.937470 0.324379 -0.478198 0.343986 -0.808084 0.841889 -0.476546 2.916925 0001700.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.918006 -0.099534 0.383873 0.065016 0.917117 0.393280 -0.391201 0.385991 -0.835448 0.572594 -0.561332 2.558580 0001800.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.986567 -0.122432 0.108151 -0.033995 0.801419 0.597136 -0.159783 0.585438 -0.794816 0.369471 -0.563017 2.080898 0001900.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.807233 -0.162504 0.567422 0.143045 0.878830 0.455188 -0.572637 0.448610 -0.686175 0.272560 -0.577472 2.182566 0002000.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.998062 -0.052747 0.033013 -0.040075 0.950716 0.307464 -0.047604 0.305545 -0.950987 0.262567 -0.588997 2.568532 0002100.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.991862 0.003254 0.127276 0.037666 0.962424 0.268927 -0.121619 0.271532 -0.954714 0.205396 0.413298 2.909809 0002200.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.988193 -0.019971 0.151909 0.034333 0.937394 0.346575 -0.149320 0.347698 -0.925640 0.214348 -0.494014 2.858355 0002300.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.996613 -0.016040 -0.080658 -0.040582 0.948978 0.312721 0.071527 0.314935 -0.946414 -0.341076 0.383588 2.941213 0002400.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.998147 0.058553 -0.016567 0.049389 0.938562 0.341558 0.035548 0.340107 -0.939715 -0.516124 -0.527491 2.901395 0002500.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.674060 0.128587 -0.727398 -0.118900 0.953004 0.278650 0.729044 0.274315 -0.627093 -1.230941 -0.165528 2.598917 0002600.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.615473 0.113558 -0.779935 -0.116795 0.965500 0.232742 0.779456 0.234339 -0.580976 -1.314503 -0.502661 2.580700 0002700.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.178396 0.156161 -0.971488 -0.201706 0.960554 0.191444 0.963063 0.230108 -0.139860 -1.610894 -0.047207 1.947824 0002800.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.220065 0.108655 -0.969415 -0.295045 0.939817 0.172315 0.929796 0.323942 -0.174762 -1.608341 -0.281376 1.939077 0002900.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 -0.020121 0.160346 -0.986856 -0.324584 0.932543 0.158139 0.945643 0.323500 0.033283 -0.896364 -0.497444 1.598477 0003000.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.465502 0.162133 -0.870070 -0.159257 0.982376 0.097855 0.870600 0.093013 0.483119 -1.582487 -0.262891 1.027917 0003100.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.437474 0.142921 -0.887801 -0.253285 0.966900 0.030846 0.862823 0.211372 0.459193 -1.462294 0.502397 1.139178 0003200.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.900091 0.151408 -0.408548 -0.111664 0.986524 0.119592 0.421149 -0.062023 0.904868 -0.917620 -0.195205 0.249724 0003300.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.980613 0.016594 -0.195249 -0.004490 0.998049 0.062274 0.195901 -0.060190 0.978775 -0.701395 0.859435 0.297703 0003400.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.977647 0.020989 -0.209204 -0.000637 0.995296 0.096879 0.210253 -0.094580 0.973061 -0.698860 0.680132 0.297019 0003500.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.977334 0.100002 -0.186597 -0.105278 0.994270 -0.018556 0.183672 0.037780 0.982261 -0.545337 -0.075577 -0.069450 0003600.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.999150 0.020708 -0.035632 -0.017710 0.996434 0.082491 0.037213 -0.081790 0.995955 -0.055270 0.804815 0.234233 0003700.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.994552 0.024958 -0.101206 -0.024824 0.999689 0.002581 0.101239 -0.000055 0.994862 -0.054641 -0.019887 -0.059936 0003800.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.998917 0.016768 -0.043410 -0.025391 0.978125 -0.206465 0.038998 0.207343 0.977491 0.031668 -0.235809 0.530147 0003900.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.999396 -0.009056 0.033556 0.014099 0.988086 -0.153253 -0.031768 0.153634 0.987617 0.084592 -0.212717 0.259431 0004000.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.923653 -0.041684 0.380956 0.058679 0.997728 -0.033100 -0.378711 0.052927 0.924001 0.629793 -0.052605 -0.084690 0004100.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.952563 -0.065734 0.297156 0.049346 0.996835 0.062326 -0.300313 -0.044706 0.952793 0.552687 0.937519 0.324731 0004200.jpg 525 0.0 319.5 0.0 525 239.5 0 0 1 0.966523 -0.059801 0.249512 0.067871 0.997409 -0.023855 -0.247439 0.039991 0.968078 0.686837 -0.133554 0.022479

Notes: If directly use 06969.ply as input, another error appears: Mesh.cpp:145: void MVS::Mesh::ListIncidenteFaces(): Assertion vertexFaces[face[v]].Find(i) == FaceIdxArr::NO_INDEX' failed. So i edited the 06969.ply with meshlab. and remove the outliers and only retain the trash. with the new 3d model, i get the below error messages: openMVS-master/libs/MVS/../Common/List.h:353: TYPE& SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::operator[](SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::IDX) [with TYPE = MeshTexture::TexturePatch; ARG_TYPE = const MeshTexture::TexturePatch&; int useConstruct = 1; int grow = 1024; IDX_TYPE = unsigned int; SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::IDX = unsigned int]: Assertionindex < _size' failed.

cdcseacave commented 7 years ago

the mesh is non-manifold, as expected, and this is most certainly the error cause; you can easily check if a mesh if manifold with Meshlab ("select non-manifold edges and vertices")

dejunzhang commented 7 years ago

@cdcseacave yes.there are so many non-manifold vertices in the 3d model. After trying to remove the non-manifold vertices using meshlab several times. it is not easy to remove all the non-manifold vertices. as there might some holes on the model. So is it possible or any way to skip the constraint to support non-manifold mesh? Thanks a lot for your kindly help.

cdcseacave commented 7 years ago

OpenMVS can clean the mesh for you. Just run ReconstructMesh scene.mvs --mesh-file rawmesh.ply --smooth 0

dejunzhang commented 7 years ago

@cdcseacave follow your instruction, the input mesh is cleaned. but the below error still happened:

openMVS-master/libs/MVS/../Common/List.h:353: TYPE& SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::operator[](SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::IDX) [with TYPE = MeshTexture::TexturePatch; ARG_TYPE = const MeshTexture::TexturePatch&; int useConstruct = 1; int grow = 1024; IDX_TYPE = unsigned int; SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::IDX = unsigned int]: Assertionindex < _size' failed.

As i could see the texturPatches.size = 1. in this case.

himanshusagar commented 7 years ago

Hi @dejunzhang Did you get the solution for your problem/error? Why was it happening even after cleaning the mesh?

vkkhare commented 6 years ago

HI @cdcseacave ,

I followed the above procedure and am able to run the code but I wanted a partial texture transfer i.e. texture only the portion visible in the image and leave the rest unchanged. However, it seems to put a color to the entire model file. Can you tell me where I would be going wrong?

UPDATE:: I have texturePatches.GetSize as 1 but dont know why. The following is the code snippet in SceneTexture.cpp

                    LabelArr sizes(nComponents);
                    sizes.Memset(0);
                    FOREACH(c, components)
                            ++sizes[components[c]];
                    texturePatches.Resize(nComponents+1);
                    // nComponents is 278 here
                    texturePatches.Last().label = NO_ID;
                    FOREACH(f, faces) {
                            const Label label(labels[f]);
                            const FIndex c(components[f]);
                            TexturePatch& texturePatch = texturePatches[c];
                            ASSERT(texturePatch.label == label || texturePatch.faces.IsEmpty());
                            if (label == NO_ID) {
                                    texturePatch.label = NO_ID;
                                    //Everyone gets assigned NO_ID ^^^
                                    texturePatches.Last().faces.Insert(f);
                            } else {
                                    if (texturePatch.faces.IsEmpty()) {
                                            texturePatch.label = label;
                                            texturePatch.faces.Reserve(sizes[c]);
                                    }
                                    texturePatch.faces.Insert(f);
                            }
                    }
                    // remove all patches with invalid label (except the last one)
                    // and create the map from the old index to the new one
                    mapIdxPatch.Resize(nComponents);
                    std::iota(mapIdxPatch.Begin(), mapIdxPatch.End(), 0);
                    for (FIndex t = nComponents; t-- > 0; ) {
                            if (texturePatches[t].label == NO_ID) {
                                   //All the patches are removed since everyone has No_ID
                                    texturePatches.RemoveAtMove(t);
                                    mapIdxPatch.RemoveAtMove(t);
                            }
                    }
                   const unsigned numPatches(texturePatches.GetSize()-1);
vkkhare commented 6 years ago

According to #321 it is the default color fill. I am getting orange fill everywhere. So is it not possible to texture only via single image given camera poses?

isshenye commented 3 years ago

@cdcseacave ,Thanks a lot for your kindly help. I have already implement the interface to convert obj model, rgb images and related pose. But i still meet some problems. My code is as below for the conversion, please have a check: if(OPT_App::strInputFileName == NULL)return false; std::ifstream in(OPT_App::strInputFileName); printf("Loading cameras,mesh,points: %s\n",OPT_App::strInputFileName.c_str()); LOG_OUT() << "Loading cameras,mesh,points: " << OPT_App::strInputFileName <<"\n" ; if(!in.is_open()) return false;

//load mesh.
in>>OPT_App::strMeshFileName;

//load input texture images.
LoadTextureImage(in,cameras, names);
printf("Finish loading LoadTextureImage. ncameras: %d\n",cameras.size());

Scene scene(OPT_App::nMaxThreads);
// load and texture the mesh
scene.platforms.Reserve((uint32_t)cameras.size());
scene.images.Reserve((uint32_t)cameras.size());
scene.nCalibratedImages = 0;
for (size_t idx=0; idx<cameras.size(); ++idx) {
  MVS::Image& image = scene.images.AddEmpty();
  image.name = names[idx];
  Util::ensureUnifySlash(image.name);
  image.name = MAKE_PATH_FULL(WORKING_FOLDER_FULL, image.name);
    printf("opening image[%d]: %s.\n",idx,image.name.c_str());
  if (!image.ReloadImage(0, false)) {
      LOG("error: can not read image %s", image.name.c_str());
      printf("error: can not read image %s", image.name.c_str());
      return EXIT_FAILURE;
  }
  // set camera
  image.platformID = scene.platforms.GetSize();
  MVS::Platform& platform = scene.platforms.AddEmpty();
  MVS::Platform::Camera& camera = platform.cameras.AddEmpty();
  image.cameraID = 0;
  const PBA::CameraT& cameraNVM = cameras[idx];
  //camera.K = cameraNVM.GetFocalLength();
    //const float *K = (float *)cameraNVM.GetFocalLength();
    camera.K(0, 0) = cameraNVM.GetFocalLengthFx();camera.K(0, 1) = 0.0;camera.K(0, 2) = cameraNVM.GetFocalLengthCx();
    camera.K(1, 0) = 0.0;camera.K(1, 1) = cameraNVM.GetFocalLengthFy();camera.K(1, 2) = cameraNVM.GetFocalLengthCy();
    camera.K(2, 0) = 0.0;camera.K(2, 1) = 0.0;camera.K(2, 2) = 1.0;

  camera.R = RMatrix::IDENTITY;
  camera.C = CMatrix::ZERO;
  // normalize camera intrinsics
  const REAL fScale(REAL(1)/MVS::Camera::GetNormalizationScale(image.width, image.height));
  camera.K(0, 0) *= fScale;
  camera.K(1, 1) *= fScale;
  camera.K(0, 2) *= fScale;
  camera.K(1, 2) *= fScale;
  // set pose
  image.poseID = platform.poses.GetSize();
  MVS::Platform::Pose& pose = platform.poses.AddEmpty();
  cameraNVM.GetMatrixRotation(pose.R.val);
  cameraNVM.GetCameraCenter(pose.C.ptr());
  image.UpdateCamera(scene.platforms);
  ++scene.nCalibratedImages;
}
printf("Finish convert mvs scene.\n");

printf("Beginning to load mesh:%s\n",OPT_App::strMeshFileName.c_str());

if (!OPT_App::strMeshFileName.IsEmpty()) {
  // load given mesh
  scene.mesh.Load(MAKE_PATH_SAFE(OPT_App::strMeshFileName));
}
if (scene.mesh.IsEmpty()) {
  VERBOSE("error: empty initial mesh");
  return EXIT_FAILURE;
}
printf("Finish loading input mesh.\n");

const String baseFileName(MAKE_PATH_SAFE(Util::getFullFileName(OPT_App::strOutputFileName)));
if (OPT_App::nOrthoMapResolution && !scene.mesh.textureDiffuse.empty()) {
  // the input mesh is already textured and an orthographic projection was requested
  goto ProjectOrtho;
}

Does above code enough for read obj model file and n rgb images and its relates pose. I check the parameters, they are right. Firstly ,the program crashed here(SceneTexture.cpp line 853): ASSERT(ISINSIDE((int)afaces.GetSize(), 1, 4)); After modifing to : ASSERT(ISINSIDE((int)afaces.GetSize(), 0, 4));

i meet another errors: /media/dejun/work/slam/texture/openMVS-master/libs/MVS/../Common/List.h:353: TYPE& SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::operator[](SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::IDX) [with TYPE = MeshTexture::TexturePatch; ARG_TYPE = const MeshTexture::TexturePatch&; int useConstruct = 1; int grow = 1024; IDX_TYPE = unsigned int; SEACAVE::cList<TYPE, ARG_TYPE, useConstruct, grow, IDX_TYPE>::IDX = unsigned int]: Assertion `index < _size' failed.

I checked ,and found that it crashed in function MeshTexture::GenerateTexture(), the size of the input texturePatches is 1 when crash happens.

BTW, there might be a bug in ./libs/IO/OBJ.cpp line 236, like below line: groups.back().faces.push_back(f); At the beginning, the groups should be empty. so we should not use back() to get last element here.

您好,我现在也在研究如何使用openmvs来给我们生成的ply或者obj模型进行贴图,mesh 3d model , pose and rgb input images也都有,和您三年前遇到的问题一模一样,能参考一下您的代码么,不甚感激!

cdcseacave commented 3 years ago

Did you verify that the MVS scene you create can be correctly visualized in the Viewer? If yes, check the mesh is manifold, or after importing it just call Clean()

calmelo commented 1 year ago

I added support for mesh input to the interface. Pls use the mesh_interface branch. All you need to do now, is to fill it in with your data, and use the mesh structure during Load() to fill in the mesh inside Scene object.

How can I use the mesh, rgb inputs and rgb image poses to obtain the textured mesh? I load them in scene as the mesh_interface branch, and then what should I do? I think I can't use the command "TextureMesh scene_dense_mesh_refine.mvs" to achieve it, but I don't know how to add the code. It would be appreciated if you could guide me how to modify it. :)

cdcseacave commented 1 year ago

once you generate the mvs scene with your data, just call TextureMesh your_scene.mvs --mesh-file your_mesh.ply

calmelo commented 1 year ago

once you generate the mvs scene with your data, just call TextureMesh your_scene.mvs --mesh-file your_mesh.ply

I can texture the mesh correctly using openMVS 1.0. However, I cannot obtain the correct result using openMVS 2.0. Do you know the reason? I will be appreciated if you can help me.