fix:issue #205
This commit is contained in:
@@ -860,20 +860,8 @@ namespace Ink_Canvas
|
||||
// 输出当前灵敏度值(调试用)
|
||||
Debug.WriteLine($"IsPotentialStraightLine - sensitivity: {sensitivity}, length: {lineLength}");
|
||||
|
||||
// 根据灵敏度调整快速检查阈值
|
||||
double quickThreshold;
|
||||
|
||||
// 如果灵敏度超过1.0,使用更宽松的快速检查标准
|
||||
if (sensitivity > 1.0)
|
||||
{
|
||||
// 高灵敏度模式 - 使用更宽松的阈值
|
||||
quickThreshold = Math.Min(0.2 + (sensitivity - 1.0) * 0.3, 0.5); // 映射到0.2-0.5范围
|
||||
}
|
||||
else
|
||||
{
|
||||
// 常规灵敏度模式
|
||||
quickThreshold = Math.Min(sensitivity * 1.5, 0.20);
|
||||
}
|
||||
// 将灵敏度转换为阈值:灵敏度0.05-2.0映射到阈值0.01-0.4
|
||||
double quickThreshold = Math.Max(0.01, sensitivity * 0.2); // 确保最小阈值为0.01
|
||||
|
||||
Debug.WriteLine($"使用快速检查阈值: {quickThreshold}");
|
||||
|
||||
@@ -899,26 +887,13 @@ namespace Ink_Canvas
|
||||
// 记录检测到的偏差(调试用)
|
||||
Debug.WriteLine($"Deviations: q={quarterDeviation}, m={midDeviation}, tq={threeQuarterDeviation}, threshold={quickRelativeThreshold}");
|
||||
|
||||
// 如果灵敏度超过1.5,则即使有一个点满足条件也认为可能是直线
|
||||
if (sensitivity > 1.5)
|
||||
// 修复后的逻辑:灵敏度越大,容许的偏差越大
|
||||
// 如果任一点偏离太大,直接排除(使用统一的判断标准)
|
||||
if (quarterDeviation > quickRelativeThreshold ||
|
||||
midDeviation > quickRelativeThreshold ||
|
||||
threeQuarterDeviation > quickRelativeThreshold)
|
||||
{
|
||||
// 超高灵敏度模式:只要有一个关键点偏差小,就认为可能是直线
|
||||
if (quarterDeviation <= quickRelativeThreshold ||
|
||||
midDeviation <= quickRelativeThreshold ||
|
||||
threeQuarterDeviation <= quickRelativeThreshold)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 常规判断:如果任一点偏离太大,直接排除
|
||||
if (quarterDeviation > quickRelativeThreshold ||
|
||||
midDeviation > quickRelativeThreshold ||
|
||||
threeQuarterDeviation > quickRelativeThreshold)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1353,23 +1328,7 @@ namespace Ink_Canvas
|
||||
|
||||
// 支持更广泛的灵敏度范围 (0.05-2.0)
|
||||
|
||||
// 如果灵敏度高于1.0,使用更宽松的判断标准
|
||||
if (sensitivity > 1.0)
|
||||
{
|
||||
// 高灵敏度模式 - 允许更大的偏差
|
||||
double adjustedSensitivity = 0.5 + (sensitivity - 1.0) * 1.5; // 映射到0.5-2.0范围
|
||||
|
||||
// 只判断平均偏差和相对偏差
|
||||
if (maxDeviation / lineLength < adjustedSensitivity && avgDeviation < lineLength * 0.1 * adjustedSensitivity)
|
||||
{
|
||||
Debug.WriteLine("接受拉直 (高灵敏度模式)");
|
||||
return true;
|
||||
}
|
||||
|
||||
Debug.WriteLine("拒绝拉直 (高灵敏度模式)");
|
||||
return false;
|
||||
}
|
||||
// 否则使用常规判断标准
|
||||
// 移除特殊的高灵敏度模式,使用统一的阈值计算逻辑
|
||||
|
||||
// 检查点分布的一致性 - 如果有些点偏离很大而其他点很接近直线,表明线条有明显弯曲
|
||||
double deviationVariance = 0;
|
||||
@@ -1462,19 +1421,22 @@ namespace Ink_Canvas
|
||||
// 输出更多调试信息
|
||||
Debug.WriteLine($"Deviation variance: {deviationVariance}, Threshold: {sensitivity * lineLength * 0.05}");
|
||||
|
||||
// 如果最大偏差超过线长的阈值比例,或者偏差方差较大(表示不均匀弯曲),则不拉直
|
||||
// 灵敏度越大,容许的偏差越大,更容易将线条识别为直线
|
||||
if ((maxDeviation / lineLength) > sensitivity)
|
||||
// 修复灵敏度逻辑:灵敏度越大,容许的偏差越大,更容易将线条识别为直线
|
||||
// 将灵敏度转换为阈值:灵敏度0.05-1.0映射到阈值0.01-0.2
|
||||
double threshold = Math.Max(0.01, sensitivity * 0.2); // 确保最小阈值为0.01
|
||||
|
||||
if ((maxDeviation / lineLength) > threshold)
|
||||
{
|
||||
Debug.WriteLine("拒绝拉直:最大偏差过大");
|
||||
Debug.WriteLine($"拒绝拉直:最大偏差过大 {maxDeviation / lineLength:F3} > {threshold:F3}");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果偏差方差大,说明线条弯曲不均匀
|
||||
// 灵敏度越大,容许的偏差方差越大
|
||||
if (deviationVariance > (sensitivity * lineLength * 0.05))
|
||||
double varianceThreshold = threshold * lineLength * 0.25; // 调整方差阈值比例
|
||||
if (deviationVariance > varianceThreshold)
|
||||
{
|
||||
Debug.WriteLine("拒绝拉直:偏差方差过大");
|
||||
Debug.WriteLine($"拒绝拉直:偏差方差过大 {deviationVariance:F3} > {varianceThreshold:F3}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1486,13 +1448,14 @@ namespace Ink_Canvas
|
||||
double midDeviation = DistanceFromLineToPoint(start, end, midPoint);
|
||||
|
||||
// 输出中点偏差信息
|
||||
Debug.WriteLine($"Mid deviation: {midDeviation}, Threshold: {lineLength * sensitivity * 0.8}");
|
||||
double midThreshold = lineLength * threshold * 0.8;
|
||||
Debug.WriteLine($"Mid deviation: {midDeviation:F3}, Threshold: {midThreshold:F3}");
|
||||
|
||||
// 如果中点偏离过大,不拉直
|
||||
// 使用灵敏度作为判断基准,灵敏度越大,容许的中点偏离越大
|
||||
if (midDeviation > (lineLength * sensitivity * 0.8))
|
||||
// 使用调整后的阈值,灵敏度越大,容许的中点偏离越大
|
||||
if (midDeviation > midThreshold)
|
||||
{
|
||||
Debug.WriteLine("拒绝拉直:中点偏差过大");
|
||||
Debug.WriteLine($"拒绝拉直:中点偏差过大 {midDeviation:F3} > {midThreshold:F3}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user