Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么要根据y和x坐标做两次排序? #69

Open
1000374 opened this issue Oct 25, 2023 · 1 comment
Open

为什么要根据y和x坐标做两次排序? #69

1000374 opened this issue Oct 25, 2023 · 1 comment

Comments

@1000374
Copy link

1000374 commented Oct 25, 2023

PaddleOcrDetector.cs的 public RotatedRect[] Run(Mat src)函数内已经对区域做了排序
RotatedRect[] rects = contours
.Where(x => BoxScoreThreahold == null || GetScore(x, pred) > BoxScoreThreahold)
.Select(x => Cv2.MinAreaRect(x))
.Where(x => x.Size.Width > MinSize && x.Size.Height > MinSize)
.Select(rect =>
{
float minEdge = Math.Min(rect.Size.Width, rect.Size.Height);
Size2f newSize = new(
(rect.Size.Width + UnclipRatio * minEdge) * scaleRate,
(rect.Size.Height + UnclipRatio * minEdge) * scaleRate);
RotatedRect largerRect = new(rect.Center * scaleRate, newSize, rect.Angle);
return largerRect;
})
.OrderBy(v => v.Center.Y)
.ThenBy(v => v.Center.X)
.ToArray();
PaddleOcrResult.cs 为什么还要在取Text的时候重新排序?
public string Text => string.Join("\n", Regions
.OrderBy(x => x.Rect.Center.Y)
.ThenBy(x => x.Rect.Center.X)
.Select(x => x.Text));
这不是重复了么?

@n0099
Copy link
Contributor

n0099 commented Oct 25, 2023

RotatedRect[] rects = contours
.Where(x => BoxScoreThreahold == null || GetScore(x, pred) > BoxScoreThreahold)
.Select(x => Cv2.MinAreaRect(x))
.Where(x => x.Size.Width > MinSize && x.Size.Height > MinSize)
.Select(rect =>
{
float minEdge = Math.Min(rect.Size.Width, rect.Size.Height);
Size2f newSize = new(
(rect.Size.Width + UnclipRatio * minEdge) * scaleRate,
(rect.Size.Height + UnclipRatio * minEdge) * scaleRate);
RotatedRect largerRect = new(rect.Center * scaleRate, newSize, rect.Angle);
return largerRect;
})
.OrderBy(v => v.Center.Y)
.ThenBy(v => v.Center.X)
.ToArray();

/// <summary>
/// Concatenates the text from each <see cref="PaddleOcrResultRegion"/> object in <see cref="Regions"/>
/// and returns the resulting string, ordered by the region's center positions.
/// </summary>
/// <value>A string containing the concatenated text from each <see cref="PaddleOcrResultRegion"/> object
/// in <see cref="Regions"/>, ordered by the region's center positions.</value>
public string Text => string.Join("\n", Regions
.OrderBy(x => x.Rect.Center.Y)
.ThenBy(x => x.Rect.Center.X)
.Select(x => x.Text));

#55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants