Skip to content

Commit

Permalink
With Mem/RotateImagesUpsideUp=true, do not clear features if none of …
Browse files Browse the repository at this point in the history
…the cameras are rotated. DBViewer: show local transform of all cameras in tooltip
  • Loading branch information
matlabbe committed Aug 12, 2024
1 parent cc5da37 commit 4911dbe
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion corelib/include/rtabmap/core/util2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ std::vector<int> RTABMAP_CORE_EXPORT SSC(
* @param model a valid camera model
* @param rgb a rgb/grayscale image (set cv::Mat() if not used)
* @param depth a depth image (set cv::Mat() if not used)
* @return true if the model/images have been rotated, false otherwise
*/
void RTABMAP_CORE_EXPORT rotateImagesUpsideUpIfNecessary(
bool RTABMAP_CORE_EXPORT rotateImagesUpsideUpIfNecessary(
CameraModel & model,
cv::Mat & rgb,
cv::Mat & depth);
Expand Down
5 changes: 3 additions & 2 deletions corelib/src/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4717,13 +4717,14 @@ Signature * Memory::createSignature(const SensorData & inputData, const Transfor
cv::Mat rotatedDepthImages;
std::vector<CameraModel> rotatedCameraModels;
bool allOutputSizesAreOkay = true;
bool atLeastOneCameraRotated = false;
for(size_t i=0; i<data.cameraModels().size(); ++i)
{
UDEBUG("Rotating camera %ld", i);
cv::Mat rgb = cv::Mat(data.imageRaw(), cv::Rect(subInputImageWidth*i, 0, subInputImageWidth, data.imageRaw().rows));
cv::Mat depth = !data.depthRaw().empty()?cv::Mat(data.depthRaw(), cv::Rect(subInputDepthWidth*i, 0, subInputDepthWidth, data.depthRaw().rows)):cv::Mat();
CameraModel model = data.cameraModels()[i];
util2d::rotateImagesUpsideUpIfNecessary(model, rgb, depth);
atLeastOneCameraRotated |= util2d::rotateImagesUpsideUpIfNecessary(model, rgb, depth);
if(rotatedColorImages.empty())
{
rotatedColorImages = cv::Mat(cv::Size(rgb.cols * data.cameraModels().size(), rgb.rows), rgb.type());
Expand Down Expand Up @@ -4757,7 +4758,7 @@ Signature * Memory::createSignature(const SensorData & inputData, const Transfor
}
rotatedCameraModels.push_back(model);
}
if(allOutputSizesAreOkay)
if(allOutputSizesAreOkay && atLeastOneCameraRotated)
{
data.setRGBDImage(rotatedColorImages, rotatedDepthImages, rotatedCameraModels);

Expand Down
6 changes: 4 additions & 2 deletions corelib/src/util2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ std::vector<int> SSC(
return ResultVec;
}

void rotateImagesUpsideUpIfNecessary(
bool rotateImagesUpsideUpIfNecessary(
CameraModel & model,
cv::Mat & rgb,
cv::Mat & depth)
Expand All @@ -2293,7 +2293,7 @@ void rotateImagesUpsideUpIfNecessary(
{
// Return original because of ambiguity for what would be considered up...
UDEBUG("Ignoring image rotation as pitch(%f)>Pi/4", pitch);
return;
return false;
}
if(roll<0)
{
Expand Down Expand Up @@ -2368,7 +2368,9 @@ void rotateImagesUpsideUpIfNecessary(
else
{
UDEBUG("ROTATION_0 (roll=%f)", roll);
return false;
}
return true;
}

}
Expand Down
2 changes: 2 additions & 0 deletions guilib/src/DatabaseViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4952,6 +4952,7 @@ void DatabaseViewer::update(int value,
if( data.cameraModels()[i].D_raw().total()) calibrationDetails << "D=" << data.cameraModels()[i].D_raw() << std::endl;
if( data.cameraModels()[i].R().total()) calibrationDetails << "R=" << data.cameraModels()[i].R() << std::endl;
if( data.cameraModels()[i].P().total()) calibrationDetails << "P=" << data.cameraModels()[i].P() << std::endl;
calibrationDetails << "BaseToCam(without opt rot)=" << (data.cameraModels()[i].localTransform()*CameraModel::opticalRotation().inverse()).prettyPrint() << std::endl;
}

}
Expand Down Expand Up @@ -4988,6 +4989,7 @@ void DatabaseViewer::update(int value,
if( data.stereoCameraModels()[i].T().total()) calibrationDetails << " T=" << data.stereoCameraModels()[i].T() << std::endl;
if( data.stereoCameraModels()[i].F().total()) calibrationDetails << " F=" << data.stereoCameraModels()[i].F() << std::endl;
if( data.stereoCameraModels()[i].E().total()) calibrationDetails << " E=" << data.stereoCameraModels()[i].E() << std::endl;
calibrationDetails << "BaseToLeftCam(without opt rot)=" << (data.stereoCameraModels()[i].left().localTransform()*CameraModel::opticalRotation().inverse()).prettyPrint() << std::endl;
}
}
labelCalib->setToolTip(calibrationDetails.str().c_str());
Expand Down

0 comments on commit 4911dbe

Please sign in to comment.