Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在c语言中裁剪倾斜图像#_C#_Asp.net_Image Processing_Aforge_Omr - Fatal编程技术网

C# 如何在c语言中裁剪倾斜图像#

C# 如何在c语言中裁剪倾斜图像#,c#,asp.net,image-processing,aforge,omr,C#,Asp.net,Image Processing,Aforge,Omr,我用手机拍摄倾斜图像。我想在两边的两个矩形之间切割图像的部分,找出它们之间的圆圈。我有中间部分的所有4个坐标,比如(x0,y0),(x1,y1),(x2,y2),(x3,y3) 我的形象是, 但是作物函数我有类似的东西 public static Bitmap CropImage(int x, int y, int width, int height, Bitmap bitmap) { Bitmap croppedImage; var originalImage = bitm

我用手机拍摄倾斜图像。我想在两边的两个矩形之间切割图像的部分,找出它们之间的圆圈。我有中间部分的所有4个坐标,比如(x0,y0),(x1,y1),(x2,y2),(x3,y3)

我的形象是,

但是作物函数我有类似的东西

public static Bitmap CropImage(int x, int y, int width, int height, Bitmap bitmap)
{

    Bitmap croppedImage;
    var originalImage = bitmap;
    {
        Rectangle crop = new Rectangle(x, y, width, height);
        croppedImage = originalImage.Clone(crop, originalImage.PixelFormat);

    } // Here we release the original resource - bitmap in memory and file on disk.

    return croppedImage;
}  
但上面的函数将部分剪切为矩形,如第一个和第二个红色框所示。
我正在寻找代码,以削减部分显示在第三个红色矩形。我搜索了代码,找到了下面的代码

List<IntPoint> corners = new List<IntPoint>();

corners.Add(new IntPoint(x0, y0));
corners.Add(new IntPoint(x3, y3));
corners.Add(new IntPoint(x1 + 30, y1 + 20));
corners.Add(new IntPoint(x2 + 30, y2 + 0));
AForge.Imaging.Filters.QuadrilateralTransformation filter = new AForge.Imaging.Filters.QuadrilateralTransformation(corners, WidthOfCut, HeightOfCut);
Bitmap newImage = filter.Apply(mainOuterWindow);
列表角点=新列表();
添加(新的积分点(x0,y0));
添加(新输入点(x3,y3));
添加(新积分点(x1+30,y1+20));
添加(新积分点(x2+30,y2+0));
a forge.Imaging.Filters.quadralateralTransformation filter=新的a forge.Imaging.Filters.quadralateralTransformation(拐角、切口宽度、切口高度);
位图newImage=filter.Apply(mainOuterWindow);
关于一个巨大的影像学。图书馆,但它将削减药水如下

这会干扰圆的形状,使其成为椭圆,从而导致其他计算出现问题。
请告诉我如何使用4个点裁剪图像。

或者有没有办法通过通过校正角度来校正图像的倾斜?

如果四边形包括有角度的边,那么得到的变换实际上看起来相当不错

使用此图像:

通过此代码转换:

        var i = Image.FromFile("pic.png");

        List<IntPoint> corners = new List<IntPoint>();
        corners.Add(new IntPoint(63, 183));
        corners.Add(new IntPoint(863, 151));
        corners.Add(new IntPoint(869, 182));
        corners.Add(new IntPoint(65, 211));
        QuadrilateralTransformation filter = new QuadrilateralTransformation(corners, 869 - 63, 211 - 183);
        var i2 = filter.Apply(i);

        i2.Save("pic2.png");
var i=Image.FromFile(“pic.png”);
列表角点=新列表();
添加(新输入点(63183));
添加(新的输入点(863151));
新增(新积分点(869182));
添加(新输入点(65211));
四边形变换过滤器=新的四边形变换(角落,869-63211-183);
var i2=过滤器。应用(i);
i2.保存(“pic2.png”);
此图像中的结果:

我想那正是你想要的

诀窍是确保四边形变换使用有角度的边来避免倾斜。我的观点大致如下:


只提取圆可以吗,还是你真的想修复像素失真?如果你使用距离公式和宽度和高度的平均值,效果会更好。您好,非常感谢,这对我很有用。