Memory: reuse compressed image/depth blobs when pixels are unchanged (#1766)

* Memory: reuse compressed image/depth blobs when pixels are unchanged

* fixed flaky test. Added tests to make sure reuseCompressedImage is disabled if images have been modified

---------

Co-authored-by: matlabbe <[email protected]>
This commit is contained in:
Torjus Iveland
2026-09-12 19:21:15 -07:00
committed by GitHub
co-authored by matlabbe
parent 2fbbe19d70
commit 6075e52857
3 changed files with 264 additions and 7 deletions
+16 -6
View File
@@ -6633,6 +6633,16 @@ Signature * Memory::createSignature(const SensorData & inputData, const Transfor
}
}
bool reuseCompressedImage =
image.data == data.imageRaw().data &&
!data.imageCompressed().empty();
bool reuseCompressedDepth =
depthOrRightImage.data == data.depthOrRightRaw().data &&
!data.depthOrRightCompressed().empty();
bool reuseCompressedDepthConfidence =
depthConfidence.data == data.depthConfidenceRaw().data &&
!data.depthConfidenceCompressed().empty();
cv::Mat compressedImage;
cv::Mat compressedDepth;
cv::Mat compressedDepthConfidence;
@@ -6645,15 +6655,15 @@ Signature * Memory::createSignature(const SensorData & inputData, const Transfor
rtabmap::CompressionThread ctDepthConfidence(depthConfidence);
rtabmap::CompressionThread ctLaserScan(laserScan.data());
rtabmap::CompressionThread ctUserData(data.userDataRaw());
if(!image.empty())
if(!image.empty() && !reuseCompressedImage)
{
ctImage.start();
}
if(!depthOrRightImage.empty())
if(!depthOrRightImage.empty() && !reuseCompressedDepth)
{
ctDepth.start();
}
if(!depthConfidence.empty())
if(!depthConfidence.empty() && !reuseCompressedDepthConfidence)
{
ctDepthConfidence.start();
}
@@ -6679,9 +6689,9 @@ Signature * Memory::createSignature(const SensorData & inputData, const Transfor
}
else
{
compressedImage = compressImage2(image, _rgbCompressionFormat);
compressedDepth = compressImage2(depthOrRightImage, depthOrRightImage.type() == CV_32FC1 || depthOrRightImage.type() == CV_16UC1?_depthCompressionFormat:_rgbCompressionFormat);
compressedDepthConfidence = compressData2(depthConfidence);
compressedImage = reuseCompressedImage?cv::Mat():compressImage2(image, _rgbCompressionFormat);
compressedDepth = reuseCompressedDepth?cv::Mat():compressImage2(depthOrRightImage, depthOrRightImage.type() == CV_32FC1 || depthOrRightImage.type() == CV_16UC1?_depthCompressionFormat:_rgbCompressionFormat);
compressedDepthConfidence = reuseCompressedDepthConfidence?cv::Mat():compressData2(depthConfidence);
compressedScan = compressData2(laserScan.data());
compressedUserData = compressData2(data.userDataRaw());
}