C# 中的图像修改(裁剪和去倾斜)

发布于 2024-10-31 19:35:12 字数 328 浏览 5 评论 0原文

我使用移动设备拍摄黑暗表面上的平面光物体的照片。 (例如从报纸上剪下的优惠券)。

然后图像通过亮度/对比度滤镜。如果太暗,重要的成分就会被遗漏。如果太亮,优惠券上的文字就会丢失。

然后将该图像转换为黑白图像。任何 50% 或更多暗的像素都会转换为黑色,其他所有像素都为白色。 (完成)

我留下了一个倾斜的双色调图像(想象一个黑色背景的较大矩形内的白色梯形)。

我需要弄清楚如何裁剪图像 - 当它在黑色背景上时比在白色背景上时更容易。然后,我必须对图像进行倾斜校正,使其成为矩形而不是梯形,同时尝试保留纵横比。

最终结果应该是一张剪裁精美、黑白、可读的优惠券图像。

With a mobile device I take a picture of a flat light object on a dark surface. (for instance a coupon clipped out of a newspaper).

The image is then run through a brightness/contrast filter. If it is too dark, vital components are left out. If it is too bright, the writing on the coupon is lost.

This image is then converted into a bitonal image. Any pixel that is 50% or more dark is converted to black, everything else is white. (done)

I am left with a skewed bitonal image (think of a white trapezoid inside a larger rectangle with a black background).

I need to figure out how to crop the image - which when it's on a black background is easier than when it's on a white background. Then, I have to de-skew the image so it is rectangular instead of trapezoidal, while attempting to preserve aspect.

The end result should be a nicely cropped, bitonal, readable image of the coupon.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事和酒 2024-11-07 19:35:12

要裁剪图像,您可以使用 LockBits 方法并扫描所有像素,分别从顶部、左侧、右侧和底部找到包含内容的第一个像素。这里很好地描述了如何使用 LockBits: https:// /web.archive.org/web/20141229164101/http://bobpowell.net/lockingbits.aspx

假设您的图像未旋转,并且倾斜来自与桌子成一定角度的相机,其中正在拍摄优惠券,您现在应该有一张倾斜的优惠券图像,完全符合裁剪后的位图的范围。您还应该知道梯形的四个角。

不过,“消除图像失真”并不像您想象的那么容易。然而,好人已经解决了这个问题,您可能可以将他们的代码移植到您自己的使用中。这是我前段时间在类似案例中探讨此问题的链接:

http://ryoushin.com/cmerighi/en-US/2007-10-29_61/Image_Distortion_Enhancements

如果您无法理解所发现的内容,我还存储了一些代码。

To crop your image, you can use the LockBits method and scan through all your pixels to find the first pixel with content from the top, left, right and bottom, respectively. How to use LockBits is described nicely here: https://web.archive.org/web/20141229164101/http://bobpowell.net/lockingbits.aspx

Assuming your image is not rotated, and that the skewing comes from the camera held at an angle against the table where the coupon is being photographed, you should now have a skewed image of the coupon, fitting perfectly within the bounds of the cropped bitmap. You should also know the four corners of the trapezoid.

"Undistorting" an image is not as easy as you might think though. However, good people have solved this problem and you can probably port their code to your own use. Here is a link I used to explore this problem in a similar case some time ago:

http://ryoushin.com/cmerighi/en-US/2007-10-29_61/Image_Distortion_Enhancements

I also have some code stored somewhere if you can't make any sense of what you find.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文