Crop Image with multiple X and Y points c#

人盡茶涼 提交于 2021-01-29 06:46:27

问题


I have images that I need to crop and have multiple X,Y co-ordinates to cut out the business card or paper. What would be the best way to do it.

My Co Ordinates is the following. X: 490, y: 0 X: 1442, y: 0 X: 1442, y: 4031 X: 490, y: 4031


回答1:


You could check out the KeyStoneCommand from the Leadtools Image Processing Nuget

This Nuget package also includes a detect document ip command that you can use if you don't know the bounding box of the business card that will detect and give you back the 4 points of the card.

Here is a code snippet:

private RasterImage DetectAndDeskew(RasterImage image)
{
   DetectDocumentCommand detectDocumentCommand = new DetectDocumentCommand();
   detectDocumentCommand.Run(image);

   if (detectDocumentCommand.DocumentArea == null)
   {
      Console.WriteLine("No document detected");
      return null;
   }

   KeyStoneCommand command = new KeyStoneCommand(detectDocumentCommand.DocumentArea);
   command.Run(image);

   image = command.TransformedImage;
   return image;
}

Here is the output image from this process:

Disclaimer: I am an employed by the maker of this nuget



来源:https://stackoverflow.com/questions/60828712/crop-image-with-multiple-x-and-y-points-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!