introlab / rtabmap

RTAB-Map library and standalone application
https://introlab.github.io/rtabmap
Other
2.74k stars 779 forks source link

Odometry Process Error #1200

Closed pranav-mp closed 8 months ago

pranav-mp commented 8 months ago

Hey Folks, I have been trying to integrate rtabmap with my ROS node. While I successfully constructed the cv mat from the callback msg, I have been facing an error while sending the SensorData to the process function of odometry. Any advices or fixes would be appreciated. Error

error: (-4:Insufficient memory) Failed to allocate 21431809826240 bytes in function 'OutOfMemoryError'

Code Snippet code fails at odom->process(sensor_data, &info)

rtabmap::SensorData sensor_data(rgb_image, depth_image, camModels[0], idx, this->now().seconds());
  if(sensor_data.imageRaw().empty()){
    std::cerr<<"RGB Image is empty"<<std::endl;
  }
  if(sensor_data.depthRaw().empty()){
    std::cerr<<"Depth Image is empty"<<std::endl;
  }
  if(sensor_data.cameraModels().at(0).isValidForProjection()){
    std::cerr<<"Projection Valid"<<std::endl;
  }

  if (sensor_data.isValid())
  {
    std::cout << "Valid" << std::endl;
  }
  try
  {
    rtabmap::OdometryInfo info;

    rtabmap::Transform pose = odom->process(sensor_data, &info);
  }

  catch (std::exception& e)
  {
    std::cerr <<  << std::endl;

  }
matlabbe commented 8 months ago

It tries to allocate 21 TB of RAM! From where rgb_image and depth_image come from? There could be a memory issue if upstream rgb_image is being modified while odometry tries to process it. You can do:

rtabmap::SensorData sensor_data(rgb_image.clone(), depth_image.clone(), camModels[0], idx, this->now().seconds());

to make sure nobody is modifying the images. Otherwise, you can enable the logger to see more info, add this at the beginning of your app:

#include <rtabmap/utilite/ULogger.h>
...
ULogger::setType(ULogger::kTypeConsole);
ULogger::setLevel(ULogger::kDebug);
pranav-mp commented 8 months ago

I found the error. I was passing an RGB image instead of a Grayscale/BGR image. The error was occurring at a cv::cvtColor() function