mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-01 17:10:26 +08:00
Fixed some missing rgb conversions before descriptor extractions. RegVis: re-extracting 3D kpts if Signature.words3() and actual kpts are not the same size. Updated fast visual guess on Memory::computeTransform().
This commit is contained in:
@@ -2073,14 +2073,26 @@ Transform Memory::computeTransform(
|
||||
Signature tmpFrom = *fromS;
|
||||
Signature tmpTo = *toS;
|
||||
|
||||
// make a guess with known correspondences
|
||||
// make a guess fast with known correspondences (if there are)
|
||||
RegistrationVis regVis(parameters_);
|
||||
tmpFrom.sensorData().setFeatures(std::vector<cv::KeyPoint>(), cv::Mat());
|
||||
tmpTo.sensorData().setFeatures(std::vector<cv::KeyPoint>(), cv::Mat());
|
||||
guess = regVis.computeTransformation(tmpFrom, tmpTo, guess, info);
|
||||
if(tmpFrom.getWords().size() &&
|
||||
tmpTo.getWords().size() &&
|
||||
tmpFrom.getWords3().size() &&
|
||||
tmpTo.getWords3().size())
|
||||
{
|
||||
UDEBUG("");
|
||||
// Remove descriptors, this will avoid recomputation of the correspondences in regVis
|
||||
tmpFrom.setWordsDescriptors(std::multimap<int, cv::Mat>());
|
||||
tmpTo.setWordsDescriptors(std::multimap<int, cv::Mat>());
|
||||
guess = regVis.computeTransformation(tmpFrom, tmpTo, guess, info);
|
||||
// set back descriptors
|
||||
tmpFrom.setWordsDescriptors(fromS->getWordsDescriptors());
|
||||
tmpTo.setWordsDescriptors(toS->getWordsDescriptors());
|
||||
}
|
||||
|
||||
if(_reextractLoopClosureFeatures)
|
||||
{
|
||||
UDEBUG("");
|
||||
tmpFrom.setWords(std::multimap<int, cv::KeyPoint>());
|
||||
tmpFrom.setWords3(std::multimap<int, cv::Point3f>());
|
||||
tmpFrom.setWordsDescriptors(std::multimap<int, cv::Mat>());
|
||||
@@ -2090,28 +2102,25 @@ Transform Memory::computeTransform(
|
||||
tmpTo.setWordsDescriptors(std::multimap<int, cv::Mat>());
|
||||
tmpTo.sensorData().setFeatures(std::vector<cv::KeyPoint>(), cv::Mat());
|
||||
}
|
||||
else
|
||||
{
|
||||
// set back features
|
||||
tmpFrom.sensorData().setFeatures(fromS->sensorData().keypoints(), fromS->sensorData().descriptors());
|
||||
tmpTo.sensorData().setFeatures(toS->sensorData().keypoints(), toS->sensorData().descriptors());
|
||||
}
|
||||
|
||||
if(guess.isNull())
|
||||
{
|
||||
if(!_registrationPipeline->isImageRequired())
|
||||
{
|
||||
UDEBUG("");
|
||||
// no visual in the pipeline, make visual registration for guess
|
||||
guess = regVis.computeTransformation(tmpFrom, tmpTo, guess, info);
|
||||
}
|
||||
else
|
||||
{
|
||||
UDEBUG("");
|
||||
guess.setIdentity();
|
||||
}
|
||||
}
|
||||
|
||||
if(!guess.isNull())
|
||||
{
|
||||
UDEBUG("");
|
||||
transform = _registrationPipeline->computeTransformation(tmpFrom, tmpTo, guess, info);
|
||||
|
||||
if(!transform.isNull())
|
||||
@@ -3202,7 +3211,17 @@ Signature * Memory::createSignature(const SensorData & data, const Transform & p
|
||||
|
||||
if(descriptors.empty())
|
||||
{
|
||||
descriptors = _feature2D->generateDescriptors(data.imageRaw(), keypoints);
|
||||
cv::Mat imageMono;
|
||||
if(data.imageRaw().channels() == 3)
|
||||
{
|
||||
cv::cvtColor(data.imageRaw(), imageMono, CV_BGR2GRAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageMono = data.imageRaw();
|
||||
}
|
||||
|
||||
descriptors = _feature2D->generateDescriptors(imageMono, keypoints);
|
||||
t = timer.ticks();
|
||||
if(stats) stats->addStatistic(Statistics::kTimingMemDescriptors_extraction(), t*1000.0f);
|
||||
UDEBUG("time descriptors (%d) = %fs", descriptors.rows, t);
|
||||
|
||||
@@ -480,6 +480,12 @@ Transform RegistrationVis::computeTransformationImpl(
|
||||
}
|
||||
else if(!fromSignature.sensorData().imageRaw().empty())
|
||||
{
|
||||
if(fromSignature.sensorData().imageRaw().channels() > 1)
|
||||
{
|
||||
cv::Mat tmp;
|
||||
cv::cvtColor(fromSignature.sensorData().imageRaw(), tmp, cv::COLOR_BGR2GRAY);
|
||||
fromSignature.sensorData().setImageRaw(tmp);
|
||||
}
|
||||
descriptorsFrom = detector->generateDescriptors(fromSignature.sensorData().imageRaw(), kptsFrom);
|
||||
}
|
||||
|
||||
@@ -505,6 +511,13 @@ Transform RegistrationVis::computeTransformationImpl(
|
||||
}
|
||||
else if(!toSignature.sensorData().imageRaw().empty())
|
||||
{
|
||||
if(toSignature.sensorData().imageRaw().channels() > 1)
|
||||
{
|
||||
cv::Mat tmp;
|
||||
cv::cvtColor(toSignature.sensorData().imageRaw(), tmp, cv::COLOR_BGR2GRAY);
|
||||
toSignature.sensorData().setImageRaw(tmp);
|
||||
}
|
||||
|
||||
descriptorsTo = detector->generateDescriptors(toSignature.sensorData().imageRaw(), kptsTo);
|
||||
}
|
||||
}
|
||||
@@ -512,16 +525,26 @@ Transform RegistrationVis::computeTransformationImpl(
|
||||
// create 3D keypoints
|
||||
std::vector<cv::Point3f> kptsFrom3D;
|
||||
std::vector<cv::Point3f> kptsTo3D;
|
||||
if(fromSignature.getWords3().empty())
|
||||
if(fromSignature.getWords3().empty() || kptsFrom.size() != fromSignature.getWords3().size())
|
||||
{
|
||||
if(fromSignature.getWords3().size() && kptsFrom.size() != fromSignature.getWords3().size())
|
||||
{
|
||||
UWARN("kptsFrom (%d) is not the same size as fromSignature.getWords3() (%d), there "
|
||||
"is maybe a problem with the logic above (getWords3() should be null or equal to kptsfrom).");
|
||||
}
|
||||
kptsFrom3D = detector->generateKeypoints3D(fromSignature.sensorData(), kptsFrom);
|
||||
}
|
||||
else
|
||||
{
|
||||
kptsFrom3D = uValues(fromSignature.getWords3());
|
||||
}
|
||||
if(toSignature.getWords3().empty())
|
||||
if(toSignature.getWords3().empty() || kptsTo.size() != toSignature.getWords3().size())
|
||||
{
|
||||
if(toSignature.getWords3().size() && kptsTo.size() != toSignature.getWords3().size())
|
||||
{
|
||||
UWARN("kptsTo (%d) is not the same size as toSignature.getWords3() (%d), there "
|
||||
"is maybe a problem with the logic above (getWords3() should be null or equal to kptsTo).");
|
||||
}
|
||||
kptsTo3D = detector->generateKeypoints3D(toSignature.sensorData(), kptsTo);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user