Gazebo | Ignition | Community
Ask Your Question
0

How do you get kinect data?

asked 2014-04-26 17:37:38 -0600

Kevin gravatar image

How do you get the kinect depth and image data from the sensor? If I insert the kinect into a world, there are no topics to get data from? Note I am not using ROS, just Gazebo.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-06-22 08:24:31 -0600

longwoo gravatar image

updated 2018-06-22 08:29:17 -0600

{ this->camera = std::dynamic_pointer_cast<sensors::depthcamerasensor>(sensors::SensorManager::Instance()->GetSensor(this->world->GetName() + "::" + this->model->GetScopedName()+ "::kinect")); if(!this->camera) std::cout<<"kinect not found!"<<std::endl; this-="">camera->SetUpdateRate(30); }

void MyPlugin::PublishStates()
{
    /*
     * after run 100 times, collect the camera image 
     * then publish the observation
     */
    if(runCNT % 100 == 0)
    {
        this->runCNT = 1;
        this->world->SetPaused(true);

        if(!this->camera->IsActive())
            ROS_ERROR("kinect camera is not active!!! ");
        // publish observation
        const unsigned char* img = this->camera->ImageData();
        my_msgs::ObsData obs;
        // static unsigned char * mem = new unsigned char [640*480*3];
        // memcpy(mem, img, 640*480*3);
        // obs.data.resize(640*480*3);
        // for(unsigned int i=0;i<640*480*3;i++)
        //  obs.data[i] = double(img[i]);
        obs.data.insert(obs.data.end(), img, img+320*240*3);
        obs.shape.resize(2);
        obs.shape[0] = 320;
        obs.shape[1] = 240;
        this->pubObsData.publish(obs);
        // camera test
        // this->camera->SaveFrame("/home/1.jpg");
    }
    else
        this->runCNT ++;
}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-04-26 17:37:38 -0600

Seen: 653 times

Last updated: Jun 22 '18