I\'m trying to detect and fine-locate some objects in images from contours. The contours that I get often include some noise (maybe form the background, I don\'t know). The
As a starting point and assuming the defects are never too big relative to the object you are trying to recognize, you can try a simple erode+dilate strategy before using cv::matchShapes
as shown below.
int max = 40; // depending on expected object and defect size
cv::Mat img = cv::imread("example.png");
cv::Mat eroded, dilated;
cv::Mat element = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(max*2,max*2), cv::Point(max,max));
cv::erode(img, eroded, element);
cv::dilate(eroded, dilated, element);
cv::imshow("original", img);
cv::imshow("eroded", eroded);
cv::imshow("dilated", dilated);