IsInverseTransform Свойство (QuadrilateralWarpCommand)
В этом разделе
Возвращает или задает значение, указывающее, должна ли команда работать как обратное преобразование.
Синтаксис
Property Value
True - команда должна работать как обратное преобразование; false - команда должна работать как прямое преобразование.
Значение по умолчанию: false.
Ремарки
Обратное преобразование можно использовать для коррекции перспективы.
Пример
Вот C#/VB.NET код, который демонстрирует, как загрузить изображение с диска, исправить искажение перспективы в изображении документа и сохранить результат в новый файл изображения.
''' <summary>
''' Corrects perspective distortion of document image.
''' </summary>
''' <param name="sourceFile">Source image file.</param>
''' <param name="resultFile">Result image file.</param>
''' <param name="documentImagePoints">An array of four points, which define the corner points of document image.
''' Points should be set in the following order: 0 - top-left, 1 - top-right,
''' 2 - bottom-left, 3 - bottom-right.</param>
Public Sub ApplyQuadrilateralUnwarp(sourceFile As String, resultFile As String, documentImagePoints As System.Drawing.PointF())
Using image As New Vintasoft.Imaging.VintasoftImage(sourceFile)
' create the perspective correction command
Dim command As New Vintasoft.Imaging.ImageProcessing.Transforms.QuadrilateralWarpCommand()
' specify that command must use invert transform (command must work as unwarp command)
command.IsInverseTransform = True
' set the corner points of document image
command.DestinationPoints = documentImagePoints
' apply perspective correction to a document image
command.ExecuteInPlace(image)
' save the result image to a file
image.Save(resultFile)
End Using
End Sub
/// <summary>
/// Corrects perspective distortion of document image.
/// </summary>
/// <param name="sourceFile">Source image file.</param>
/// <param name="resultFile">Result image file.</param>
/// <param name="documentImagePoints">An array of four points, which define the corner points of document image.
/// Points should be set in the following order: 0 - top-left, 1 - top-right,
/// 2 - bottom-left, 3 - bottom-right.</param>
public void ApplyQuadrilateralUnwarp(string sourceFile, string resultFile, System.Drawing.PointF[] documentImagePoints)
{
using (Vintasoft.Imaging.VintasoftImage image =
new Vintasoft.Imaging.VintasoftImage(sourceFile))
{
// create the perspective correction command
Vintasoft.Imaging.ImageProcessing.Transforms.QuadrilateralWarpCommand command =
new Vintasoft.Imaging.ImageProcessing.Transforms.QuadrilateralWarpCommand();
// specify that command must use invert transform (command must work as unwarp command)
command.IsInverseTransform = true;
// set the corner points of document image
command.DestinationPoints = documentImagePoints;
// apply perspective correction to a document image
command.ExecuteInPlace(image);
// save the result image to a file
image.Save(resultFile);
}
}
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также