DistanceTransform 在 OpenCVSharp 中不起作用吗?
Does DistanceTransform not work in OpenCVSharp?
我的代码非常简单——我正在对图像进行阈值处理,然后尝试对其应用 DistanceTransform
:
var source = new Mat(path, ImreadModes.AnyDepth | ImreadModes.AnyColor);
var bgr = new Mat[3];
var thresh = new Mat();
var dist = new Mat();
Cv2.Split(source, out bgr);
Cv2.AdaptiveThreshold(bgr[2], thresh, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 13, 2);
Cv2.ImShow("thresh", thresh);
Cv2.DistanceTransform(thresh, dist, DistanceTypes.L2, DistanceMaskSize.Mask5);
Cv2.ImShow("dist", dist);
但好像根本没有应用过滤器:
事实证明,无法 Normalize
将图像从 32 位还原为 8 位(如 this answer 所述)。
添加以下行后,图像符合预期:
Cv2.Normalize(dist, dist, 0, 1, NormTypes.MinMax);
我的代码非常简单——我正在对图像进行阈值处理,然后尝试对其应用 DistanceTransform
:
var source = new Mat(path, ImreadModes.AnyDepth | ImreadModes.AnyColor);
var bgr = new Mat[3];
var thresh = new Mat();
var dist = new Mat();
Cv2.Split(source, out bgr);
Cv2.AdaptiveThreshold(bgr[2], thresh, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 13, 2);
Cv2.ImShow("thresh", thresh);
Cv2.DistanceTransform(thresh, dist, DistanceTypes.L2, DistanceMaskSize.Mask5);
Cv2.ImShow("dist", dist);
但好像根本没有应用过滤器:
事实证明,无法 Normalize
将图像从 32 位还原为 8 位(如 this answer 所述)。
添加以下行后,图像符合预期:
Cv2.Normalize(dist, dist, 0, 1, NormTypes.MinMax);