int main(int argc, char** argv)
{
    if(argc != 2  && argc != 3)
    {
        cout << "Format: " << argv[0] << " train_dirname [model_filename]" << endl;
        cout << "   train_dirname - a path to the directory with TOD-like training base." << endl;
        cout << "   model_filename - an optional parameter, it's a filename that will be used to save trained model." << endl;
        return -1;
    }

    Mat cameraMatrix = defaultCameraMatrix();

    // Load the data
    const string dirname = argv[1];
#if 1
    vector<string> frameIndices;
    readFrameIndices(dirname, frameIndices);
    if(frameIndices.empty())
    {
        cout << "Can not load the data from given directory of the base: " << dirname << endl;
        return -1;
    }

    cout << "Frame indices count " << frameIndices.size() << endl;

    Ptr<ArbitraryCaptureServer> captureServer = new ArbitraryCaptureServer();
    captureServer->set("cameraMatrix", cameraMatrix);
    captureServer->initialize(Size(640,480));
    for(size_t i = 0; i < frameIndices.size(); i++)
    {
        Mat bgrImage, depth;
        loadFrameData(dirname, frameIndices[i], bgrImage, depth);

        captureServer->push(bgrImage, depth, i);

        if(captureServer->get<bool>("isFinalized"))
        {
            cout << "The trajecotry construction is finalized ahead of time.";
            return -1;
        }
    }

    Ptr<TrajectoryFrames> trajectoryFrames = captureServer->finalize();
    captureServer.release();

    if(trajectoryFrames.empty())
        return -1;
#if 0
    trajectoryFrames->save("trajectoryFrames/");
    return 0;
#endif

#else
    Ptr<TrajectoryFrames> trajectoryFrames = new TrajectoryFrames();
    trajectoryFrames->load(dirname);
#endif

    ModelReconstructor reconstructor;
    reconstructor.set("isShowStepResults", true);
    reconstructor.set("maxBAPosesCount", 50);

    Ptr<ObjectModel> model;
    reconstructor.reconstruct(trajectoryFrames, cameraMatrix, model);

    if(argc == 3)
    {
        model->write_ply(argv[2]);
    }

    model->show();

    return 0;
}
Example #2
0
int main(int argc, char** argv)
{
    if(argc != 3  && argc != 4)
    {
        cout << "Format: " << argv[0] << " train_dirname construct_if_loop_closure_only [model_filename]" << endl;
        cout << "   train_dirname - a path to the directory with TOD-like training base." << endl;
        cout << "   construct_if_loop_closure_only - 0 or 1. If 1 the model reconstruction will be run if the loop closure was detected. If 0,"
                " it will be run in any case (and result can be not very accurate in this case)." << endl;
        cout << "   model_filename - an optional parameter, it's a filename that will be used to save trained model." << endl;
        return -1;
    }

    // Load the data
    const string dirname = argv[1];
    bool constructIfLoopClosureOnly = true;

    if(string(argv[2]) == "0")
        constructIfLoopClosureOnly = false;
    else if(string(argv[2]) != "1")
    {
        cout << "Incorrect second parameter passed to the application." << endl;
        return -1;
    }

    vector<Mat> bgrImages, depthes;
    loadTODLikeBase(dirname, bgrImages, depthes);
    if(bgrImages.empty())
    {
        cout << "Can not load the data from given directory of the base: " << dirname << endl;
        return -1;
    }

    Mat cameraMatrix = defaultCameraMatrix();

    OnlineCaptureServer onlineCaptureServer;
    onlineCaptureServer.set("cameraMatrix", cameraMatrix);
    CV_Assert(!bgrImages[0].empty());
    onlineCaptureServer.initialize(bgrImages[0].size());//, TrajectoryFrames::VALIDFRAME);
    for(size_t i = 0; i < bgrImages.size(); i++)
        onlineCaptureServer.push(bgrImages[i], depthes[i], i);

    Ptr<TrajectoryFrames> trajectoryFrames = onlineCaptureServer.finalize();
    if(constructIfLoopClosureOnly && !onlineCaptureServer.get<bool>("isLoopClosed"))
        return -1;

#if 1
    releaseUnusedFrames(trajectoryFrames, bgrImages, depthes);
#endif

    ModelReconstructor reconstructor;
    reconstructor.set("isShowStepResults", false);

    Ptr<ObjectModel> model;
    reconstructor.reconstruct(trajectoryFrames, cameraMatrix, model);

    if(argc == 4)
        model->write_ply(argv[3]);

    model->show();

    return 0;
}