findContours outputs different result, if the camera is parallel to the contour border
Actually this some kind of repetition of my previous post , but now I know where the problem is.
So basically, I can switch between Threshold (threshValue
does not have an effect here, but is not important for the question)
thresh = Imgproc.threshold(gray, edged, threshValue, 255, Imgproc.THRESH_BINARY | Imgproc.THRESH_OTSU );
Imgproc.findContours(edged, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
and canny edge detection
Imgproc.Canny(gray, edged, 100, 200, 3);
Imgproc.findContours(edged, contours, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
As the problem occur for both of them, I will only show it for Threshold. I applied some filters to limit the found contours, but the only one, which are relevant are the number of contour points and the convexity of the contour.
MatOfPoint2f approxCurve = new MatOfPoint2f();
Imgproc.approxPolyDP(tempMatPoint2f, approxCurve, contours[i].rows() * detectorParameters.get_polygonalApproxAccuracyRate(), true);
var numberPoints = approxCurve.rows();
if (filterNumberCorners && (numberPoints < minNumberCorners || numberPoints > maxNumberCorners))
{
contours.RemoveAt(i);
continue;
}
if (filterConvexity && !Imgproc.isContourConvex(new MatOfPoint(approxPoints)))
{
contours.RemoveAt(i);
continue;
}
As I adapted some parts from the offical c++ implementation of the aruco detection (I use OpenCVForUnity), there are still parts which look similars, like detectorParameters.get_polygonalApproxAccuracyRate()
.
So if the camera is a bit rotated and both of the above mentioned filters are applied, all contours I want to detect are found
If I hold the camera parallel to the contour border and apply only the convexity filter and set the max number of contour points to 18, also all contours are found.
But if I then filter them by convexity I get this
This is how the straight and rotated black/white looks like.
So my question is: How can I make it happen, that the contours in the last two images are found, even if I apply the two filters?