简体   繁体   English

在C#中检测扫描图像的旋转

[英]Detect Rotation of a scanned image in C#

We want ac# solution to correct the scanned image because it is rotated. 我们希望ac#解决方案可以校正扫描的图像,因为它是旋转的。 To solve this problem we must detect the rotation angle first and then rotate the image. 为了解决这个问题,我们必须首先检测旋转角度,然后旋转图像。 This was our first thought for our problem. 这是我们首先想到的问题。 But then we thought image warping would be more accurate as I think it would make the scanned image like our template. 但是后来我们认为图像变形会更准确,因为我认为它会使扫描的图像像我们的模板一样。 Then we can process it as we know all the coordinates of our template... I searched for a free SDK or a free solution in c#. 然后我们就可以知道模板的所有坐标,就可以对其进行处理...我在c#中搜索了免费的SDK或免费的解决方案。 Helping me in this will be great as it is the last task in our work. 在这方面给我很大帮助,因为这是我们工作中的最后一项任务。 Really, thanks for all. 真的,谢谢大家。

We used the PrimeOCR product to do this. 我们使用PrimeOCR产品来做到这一点。 It's not free, but we couldn't find a free program that was comparable. 它不是免费的,但我们找不到可比的免费程序。

So, the hard part is to detect the angle of the page. 因此,最困难的部分是检测页面的角度。

If you have full control over the template, the simplest way to do this is probably to come up with an easily-detectable symbol (eg a solid black circle) and stick 3 of them on the template. 如果您完全控制模板,那么最简单的方法可能是拿出一个易于检测的符号(例如,实心黑色圆圈)并将其中的3个粘贴在模板上。 Then, detect them (just look for big blocks of pixels with high saturation, in the case of a solid black circle). 然后,检测它们(在黑色实心圆的情况下,只需寻找具有高饱和度的大像素块)。

So, you'll then have 3 sets of coordinates. 这样,您将获得3组坐标。 If you have a top circle, a left circle, and a right circle with all 3 circles at difference distances from one another, detecting which circle is the top circle should be pretty easy. 如果您有一个顶圆,一个左圆和一个右圆,并且所有3个圆之间的距离都不同,那么检测哪个圆是顶圆应该很容易。

Then just call a rotation function. 然后只需调用旋转函数即可。 This part is easy and has been done before (eg http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate ). 这部分很容易并且已经完成(例如, http : //www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate )。

Edit: I suggested a circle because it's easier to find the center, but a rectangle should work, too. 编辑:我建议一个圆形,因为它更容易找到中心,但是矩形也应该起作用。

To be more explicit about how to actually locate the rectangles/circles, take the average Brightness value of every a × a group of pixels. 为了更明确地说明如何实际定位矩形/圆形,请获取每a×一组像素的平均亮度值。 If that value is greater than b, then that a × a group of pixels is part of a rectangle. 如果该值大于b,则a×一组像素是矩形的一部分。 a and b are varables you'll want to come up with yourself. a和b是变量,您需要自己提出。

Use flood-fill (or, more precisely, Connected Component Labeling ) group the resulting pixels together. 使用泛洪填充 (或更准确地说,使用连接组件标签 )将生成的像素分组在一起。 The end result should give you your rectangles. 最终结果应为您提供矩形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM