Skip to content

Commit

Permalink
Reject when findCirclesGrid creates duplicates (#30)
Browse files Browse the repository at this point in the history
* Reject when opencv finds duplicate circles per opencv/opencv#4775
  • Loading branch information
smith-doug authored Mar 27, 2020
1 parent daae176 commit a7851ce
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rct_image_tools/src/rct_image_tools/image_observation_finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ static bool extractKeyPoints(const ObservationPoints& centers, ObservationPoints
}
}

// OpenCV creates duplicate centers sometimes. https://github.com/opencv/opencv/issues/4775
// Make sure every center has a matching keypoint. It may be sufficient just to check centers for duplicates.
ObservationPoints centers_tmp = centers;
for (auto&& keypoint : keypoints)
{
auto it = std::find_if(centers_tmp.begin(), centers_tmp.end(),
[&](const cv::Point2f& pt) { return (pt.x == keypoint.pt.x && pt.y == keypoint.pt.y); });

if (it != centers_tmp.end())
{
centers_tmp.erase(it);
}
}

if (!centers_tmp.empty())
{
// ROS_ERROR_STREAM("Centers and keypoints didn't match. It's probably this: "
// "https://github.com/opencv/opencv/issues/4775");
return false;
}

// If a flipped pattern is found, flip the rows/columns
std::size_t temp_rows = flipped ? cols : rows;
std::size_t temp_cols = flipped ? rows : cols;
Expand Down

0 comments on commit a7851ce

Please sign in to comment.