Skip to content

Commit c158171

Browse files
committed
OrganizedNeighbor: add additional check to make sure the cloud is suitable
1 parent 6356e1b commit c158171

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

search/include/pcl/search/impl/organized.hpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,11 @@ pcl::search::OrganizedNeighbor<PointT>::estimateProjectionMatrix ()
358358
}
359359

360360
double residual_sqr = pcl::estimateProjectionMatrix<PointT> (input_, projection_matrix_, indices);
361+
PCL_DEBUG_STREAM("[pcl::" << this->getName () << "::estimateProjectionMatrix] projection matrix=" << std::endl << projection_matrix_ << std::endl << "residual_sqr=" << residual_sqr << std::endl);
361362

362363
if (std::abs (residual_sqr) > eps_ * static_cast<float>(indices.size ()))
363364
{
364-
PCL_ERROR ("[pcl::%s::estimateProjectionMatrix] Input dataset is not from a projective device!\nResidual (MSE) %f, using %d valid points\n", this->getName ().c_str (), residual_sqr / double (indices.size()), indices.size ());
365+
PCL_ERROR ("[pcl::%s::estimateProjectionMatrix] Input dataset is not from a projective device!\nResidual (MSE) %g, using %d valid points\n", this->getName ().c_str (), residual_sqr / double (indices.size()), indices.size ());
365366
return;
366367
}
367368

@@ -371,6 +372,19 @@ pcl::search::OrganizedNeighbor<PointT>::estimateProjectionMatrix ()
371372

372373
// precalculate KR * KR^T needed by calculations during nn-search
373374
KR_KRT_ = KR_ * KR_.transpose ();
375+
376+
// final test: project a few points at known image coordinates and test if the projected coordinates are close
377+
for(std::size_t i=0; i<11; ++i) {
378+
const std::size_t test_index = input_->size()*i/11u;
379+
if (!mask_[test_index])
380+
continue;
381+
const auto& test_point = (*input_)[test_index];
382+
pcl::PointXY q;
383+
if (!projectPoint(test_point, q) || std::abs(q.x-test_index%input_->width)>1 || std::abs(q.y-test_index/input_->width)>1) {
384+
PCL_WARN ("[pcl::%s::estimateProjectionMatrix] Input dataset does not seem to be from a projective device! (point %zu (%g,%g,%g) projected to pixel coordinates (%g,%g), but actual pixel coordinates are (%zu,%zu))\n",
385+
this->getName ().c_str (), test_index, test_point.x, test_point.y, test_point.z, q.x, q.y, static_cast<std::size_t>(test_index%input_->width), static_cast<std::size_t>(test_index/input_->width));
386+
}
387+
}
374388
}
375389

376390
//////////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)