Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Fixed the memorization of the voting points for the CHT #1502

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions modules/imgproc/include/visp3/imgproc/vpCircleHoughTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -1042,10 +1042,39 @@ class VISP_EXPORT vpCircleHoughTransform
}
}

/*!
* \brief Set the mask that permits to ignore some pixels when performing the circle detection.
*
* \param[in] mask A boolean image where pixels set to true means that the pixel
* must be considered and set to false means that the pixel must be ignored.
*/
inline void setMask(const vpImage<bool> &mask)
{
mp_mask = &mask;
}

/*!
* \brief Set the mask that permits to ignore some pixels when performing the circle detection.
*
* \param[in] mask Either a boolean image where pixels set to true means that the pixel
* must be considered and set to false means that the pixel must be ignored, or nullptr
* to deactivate the mask.
*/
inline void setMask(const vpImage<bool> *mask)
{
mp_mask = mask;
}

/*!
* \brief Permits to either activate or deactivate the memorization
* of the points that voted for the detected circles.
*
* \param[in] record True to activate the feature, false to deactivate it.
*/
inline void setRecordVotingPoints(const bool &record)
{
m_algoParams.m_recordVotingPoints = record;
}
//@}

/** @name Getters */
Expand Down Expand Up @@ -1179,6 +1208,25 @@ class VISP_EXPORT vpCircleHoughTransform
{
return m_finalCircleVotes;
}

/*!
* Get the points that voted for the detections that are outputed by vpCircleHoughTransform::detect().
*/
inline std::vector<std::vector<std::pair<unsigned int, unsigned int> > > getDetectionsVotingPoints() const
{
if (!m_algoParams.m_recordVotingPoints) {
throw(vpException(vpException::fatalError, "Asking voting points when it was not asked to remember them."));
}
return m_finalCirclesVotingPoints;
}

/*!
* Returns true if it was asked to record the points that voted for the detections.
*/
inline bool getRecordVotingPoints() const
{
return m_algoParams.getRecordVotingPoints();
}
//@}

/*!
Expand Down
2 changes: 1 addition & 1 deletion modules/imgproc/src/vpCircleHoughTransform_circles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ vpCircleHoughTransform::computeCircleCandidates()
nbBins = std::max<int>(static_cast<int>(1), nbBins); // Avoid having 0 bins, which causes segfault
std::vector<float> radiusAccumList; // Radius accumulator for each center candidates.
std::vector<float> radiusActualValueList; // Vector that contains the actual distance between the edge points and the center candidates.
std::vector<std::vector<std::pair<unsigned int, unsigned int> > > votingPoints(nbBins); // Vectors that contain the points voting for each radius bin

float rmin2 = m_algoParams.m_minRadius * m_algoParams.m_minRadius;
float rmax2 = m_algoParams.m_maxRadius * m_algoParams.m_maxRadius;
Expand All @@ -153,6 +152,7 @@ vpCircleHoughTransform::computeCircleCandidates()
data.m_recordVotingPoints = m_algoParams.m_recordVotingPoints;

for (size_t i = 0; i < nbCenterCandidates; ++i) {
std::vector<std::vector<std::pair<unsigned int, unsigned int> > > votingPoints(nbBins); // Vectors that contain the points voting for each radius bin
std::pair<float, float> centerCandidate = m_centerCandidatesList[i];
// Initialize the radius accumulator of the candidate with 0s
radiusAccumList.clear();
Expand Down
3 changes: 3 additions & 0 deletions modules/imgproc/src/vpCircleHoughTransform_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,11 @@ vpCircleHoughTransform::detect(const vpImage<unsigned char> &I)
m_circleCandidates.clear();
m_circleCandidatesVotes.clear();
m_circleCandidatesProbabilities.clear();
m_circleCandidatesVotingPoints.clear();
m_finalCircles.clear();
m_finalCircleVotes.clear();
m_finalCirclesProbabilities.clear();
m_finalCirclesVotingPoints.clear();

// Ensuring that the difference between the max and min radii is big enough to take into account
// the pixelization of the image
Expand Down
Loading