当前位置: 首页>>代码示例>>C++>>正文


C++ Simulator::close方法代码示例

本文整理汇总了C++中Simulator::close方法的典型用法代码示例。如果您正苦于以下问题:C++ Simulator::close方法的具体用法?C++ Simulator::close怎么用?C++ Simulator::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Simulator的用法示例。


在下文中一共展示了Simulator::close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[]) {
//    std::mt19937 random_source(0);
    std::minstd_rand random_source(0);
    std::uniform_real_distribution<float> angledist(-M_PI / 4, M_PI / 4);
    Simulator *sim = new Simulator();

    // Sets resolution. Default is 320X240
    sim->setCameraResolution(640,480);

    // Initialize the simulator. Further camera configuration won't take any effect from now on.
    sim->init();

    // Run this many episodes
    int episodes = 10;

    for (int i = 0; i < episodes; ++i) {

        // Starts a new episode. It is not needed right after init() but it doesn't cost much and the loop is nicer.
        sim->newEpisode("2t7WUuJeko7"); // Take optional viewpoint_id argument, otherwise launches at a random location

        for (int step = 0;step < 10;++step) {
            // Get the state
            SimStatePtr state = sim->getState(); // SimStatePtr is std::shared_ptr<SimState>

            // Which consists of:
            unsigned int n = state->step;
            cv::Mat rgb  = state->rgb; // Use OpenCV CV_8UC3 type (i.e. 8bit color rgb)
            cv::Mat depth  = state->depth; // ignore for now
            ViewpointPtr location = state->location; // Need a class to hold viewpoint id, and cv::Point3 for x,y,z location of a viewpoint
            float heading = state->heading;
            float elevation = state->elevation; // camera parameters
            std::vector<ViewpointPtr> reachable = state->navigableLocations; // Where we can move to,
            std::uniform_int_distribution<> distribution(0, reachable.size() - 1);
            int locationIdx = distribution(random_source);
            float headingChange = angledist(random_source);
            float elevationChange = angledist(random_source);

/*            std::stringstream ss;
            ss << "rgb_" << i << "_" << step << ".png";
            cv::imwrite(ss.str(), rgb);*/

            // Make action (index into reachable, heading change in rad, elevation change in rad)      
// E.g. an RL agent will sample an action here. A reward can be determined based on location, heading, elevation but that is dataset dependent
            sim->makeAction(locationIdx, headingChange, elevationChange);
            std::this_thread::sleep_for(std::chrono::milliseconds{100});
        }
    }

    // It will be done automatically in destructor but after close You can init it again with different settings.
    sim->close();
    delete sim;

    return 0;
}
开发者ID:volkancirik,项目名称:Matterport3DSimulator,代码行数:54,代码来源:random_agent.cpp


注:本文中的Simulator::close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。