tooltip bounds done i think
This commit is contained in:
parent
bb2b9cf507
commit
528453a321
1 changed files with 19 additions and 5 deletions
|
|
@ -280,11 +280,25 @@ void HandleDiffOcr(Request req, TesseractEngine engine)
|
||||||
int maxX = Math.Min(bestColEnd + pad, w - 1);
|
int maxX = Math.Min(bestColEnd + pad, w - 1);
|
||||||
int maxY = Math.Min(bestRowEnd + pad, h - 1);
|
int maxY = Math.Min(bestRowEnd + pad, h - 1);
|
||||||
|
|
||||||
// Trim 5px from left/right/bottom to remove tooltip border/shadow artifacts
|
// Dynamic right-edge trim: if the rightmost columns are much sparser than
|
||||||
int trim = 5;
|
// the tooltip body, trim them. This handles the ~5% of cases where ambient
|
||||||
minX = Math.Min(minX + trim, maxX);
|
// noise extends the detected region slightly on the right.
|
||||||
maxX = Math.Max(maxX - trim, minX);
|
int colSpan = maxX - minX + 1;
|
||||||
maxY = Math.Max(maxY - trim, minY);
|
if (colSpan > 100)
|
||||||
|
{
|
||||||
|
// Compute median column density in the middle 50% of the range
|
||||||
|
int q1 = minX + colSpan / 4;
|
||||||
|
int q3 = minX + colSpan * 3 / 4;
|
||||||
|
long midSum = 0;
|
||||||
|
int midCount = 0;
|
||||||
|
for (int x = q1; x <= q3; x++) { midSum += colCounts[x]; midCount++; }
|
||||||
|
double avgMidDensity = (double)midSum / midCount;
|
||||||
|
double cutoff = avgMidDensity * 0.3; // column must have >=30% of avg density
|
||||||
|
|
||||||
|
// Trim from right while below cutoff
|
||||||
|
while (maxX > minX + 100 && colCounts[maxX] < cutoff)
|
||||||
|
maxX--;
|
||||||
|
}
|
||||||
int rw = maxX - minX + 1;
|
int rw = maxX - minX + 1;
|
||||||
int rh = maxY - minY + 1;
|
int rh = maxY - minY + 1;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue