使用平铺进行透视图像转换

发布于 2024-11-02 14:52:16 字数 445 浏览 0 评论 0原文

在寻找一个可以用于我计划创建的新应用程序的良好图像处理库。我将使用 C#.NET (VS 2008)

我的应用程序需要执行以下操作:

  1. 在启动时加载图像并将其显示在图片框中
  2. 然后我应该能够在任何地方选择四个点(TopLeft、TopRight、BottomLeft、BottomRight)在图片框中。
  3. 然后,我需要使用 4 个源点和目标点将源图像转换为正确的视角。

不仅如此,我需要最终的输出图像具有指定的尺寸。我希望应用程序能够使用相同的视角并返回我指定的指定矩形尺寸(不是 4 点的尺寸)的图像。我希望你明白我的意思。需要对源图像进行平铺和转换,以生成完全适合指定区域的输出。

我尝试了一些库,如 Aforge.NET、ImageMagick、EMGU 等。有些库速度很慢。有些只能产生小尺寸的透视图像。有些会出现内存错误。找不到合适的解决方案。

On the hunt of a good image processing library which can be used for a new application I plan to create. I will be using C#.NET (VS 2008)

My application needs to do the following:

  1. Load an image at startup and display it in a picture box
  2. I should then be able to select four points (TopLeft, TopRight, BottomLeft, BottomRight) anywhere in the picture box.
  3. I then need to transform the source image to the correct perspective using the 4 source and destination points.

Not just that, I need the final output image to be of a specified size. I want the application to be able to use the same perspective and return an image of the specified rectangular size (not the size of 4 points) I specify. I hope you understand what I mean. The source image needs to be tiled and transformed to produce an output that fits the specified area completely.

I tried some libraries like Aforge.NET, ImageMagick, EMGU etc. Some are slow. Some can only produce a perspective image of small size. Some give memory errors. Can't find a proper solution.

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

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

发布评论

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

评论(2

时光病人 2024-11-09 14:52:16

您可能想看看这个,因为它可以解决您的部分问题,或者引导您走向正确的方向:
http://www.codeproject.com/KB/graphics/YLScsFreeTransform.aspx

它将拍摄图像并使用您提供的 4 个 X/Y 坐标对其进行扭曲。

快速、免费、简单的代码。经过测试,效果非常好。只需从链接下载代码,然后像这样使用 FreeTransform.cs:

using (System.Drawing.Bitmap sourceImg = new System.Drawing.Bitmap(@"c:\image.jpg")) 
{ 
    YLScsDrawing.Imaging.Filters.FreeTransform filter = new YLScsDrawing.Imaging.Filters.FreeTransform(); 
    filter.Bitmap = sourceImg;
    // assign FourCorners (the four X/Y coords) of the new perspective shape
    filter.FourCorners = new System.Drawing.PointF[] { new System.Drawing.PointF(0, 0), new System.Drawing.PointF(300, 50), new System.Drawing.PointF(300, 411), new System.Drawing.PointF(0, 461)}; 
    filter.IsBilinearInterpolation = true; // optional for higher quality
    using (System.Drawing.Bitmap perspectiveImg = filter.Bitmap) 
    {
        // perspectiveImg contains your completed image. save the image or do whatever.
    } 
}

仅供参考,我相信 .NET 有 2GB 对象内存限制,因此如果您正在处理非常大的图像,则可能会遇到内存错误。

You may want to take a look at this, as it may solve a portion of your problem, or lead you in the right direction:
http://www.codeproject.com/KB/graphics/YLScsFreeTransform.aspx

It will take an image and distort it using 4 X/Y coordinates you provide.

Fast, free, simple code. Tested and it works beautifully. Simply download the code from the link, then use FreeTransform.cs like this:

using (System.Drawing.Bitmap sourceImg = new System.Drawing.Bitmap(@"c:\image.jpg")) 
{ 
    YLScsDrawing.Imaging.Filters.FreeTransform filter = new YLScsDrawing.Imaging.Filters.FreeTransform(); 
    filter.Bitmap = sourceImg;
    // assign FourCorners (the four X/Y coords) of the new perspective shape
    filter.FourCorners = new System.Drawing.PointF[] { new System.Drawing.PointF(0, 0), new System.Drawing.PointF(300, 50), new System.Drawing.PointF(300, 411), new System.Drawing.PointF(0, 461)}; 
    filter.IsBilinearInterpolation = true; // optional for higher quality
    using (System.Drawing.Bitmap perspectiveImg = filter.Bitmap) 
    {
        // perspectiveImg contains your completed image. save the image or do whatever.
    } 
}

FYI, I believe that .NET has a 2gb object memory limit, so if you're working with really large images, you may run into a memory error.

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