LEADTOOLS画像処理(Leadtools.ImageProcessing.Coreアセンブリ)

フレームを表示

CoreUtilitiesクラス








メンバ 
ユーティリティクラスを中心から切り離します。
オブジェクトモデル
構文
public sealed class CoreUtilities 
'Declaration
 
Public NotInheritable Class CoreUtilities 
'Usage
 
Dim instance As CoreUtilities
public sealed sealed class CoreUtilities 
@interface LTCoreUtilities : NSObject
public class CoreUtilities
function Leadtools.ImageProcessing.Core.CoreUtilities()
public ref class CoreUtilities sealed 
サンプル

このサンプルは、移動パラメーターを計算します。サンプルでは、ファイル内の参照画像の登録商標の位置を保存済みという前提です。このサンプルは自分で修正してください。手動割り当てのrmDataを自分のコードに置き換えて、このサンプルをテストする前に参照登録商標データをロードします。

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing.Core

   
Public Sub GetTransformationParametersExample()
   Dim codecs As New RasterCodecs()
   codecs.ThrowExceptionsOnInvalidImages = True
   Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "RGSRef.cmp"))

   ' Prepare the command
   Dim rmData(2) As SearchRegistrationMarksCommandData
   ' Mark1
   rmData(0) = New SearchRegistrationMarksCommandData
   rmData(0).Rectangle = New LeadRect(680, 20, 941 - 680, 218 - 20)
   Dim pt0(0) As LeadPoint
   rmData(0).MarkDetectedPoints = pt0
   rmData(0).Width = 31
   rmData(0).Height = 29
   rmData(0).Type = RegistrationMarkCommandType.TShape
   rmData(0).MinimumScale = 90
   rmData(0).MaximumScale = 110
   rmData(0).SearchMarkCount = 1

   ' Mark2
   rmData(1) = New SearchRegistrationMarksCommandData
   rmData(1).Rectangle = New LeadRect(665, 790, 899 - 665, 961 - 790)
   Dim pt1(0) As LeadPoint
   rmData(1).MarkDetectedPoints = pt1
   rmData(1).Width = 31
   rmData(1).Height = 29
   rmData(1).Type = RegistrationMarkCommandType.TShape
   rmData(1).MinimumScale = 90
   rmData(1).MaximumScale = 110
   rmData(1).SearchMarkCount = 1

   ' Mark3
   rmData(2) = New SearchRegistrationMarksCommandData
   rmData(2).Rectangle = New LeadRect(7, 1073, 298 - 7, 1246 - 1073)
   Dim pt2(0) As LeadPoint
   rmData(2).MarkDetectedPoints = pt2
   rmData(2).Width = 31
   rmData(2).Height = 29
   rmData(2).Type = RegistrationMarkCommandType.TShape
   rmData(2).MinimumScale = 90
   rmData(2).MaximumScale = 110
   rmData(2).SearchMarkCount = 1
   Dim command1 As New SearchRegistrationMarksCommand(rmData)
   command1.Run(leadImage)

   If ((rmData(2).MarkDetectedCount <> 1) OrElse (rmData(1).MarkDetectedCount <> 1) OrElse (rmData(0).MarkDetectedCount <> 1)) Then
      Return
   End If

   Dim original() As LeadPoint = _
   { _
      New LeadPoint(81400, 11300), _
      New LeadPoint(78600, 87400), _
      New LeadPoint(14300, 115400) _
   }

   Dim detected() As LeadPoint = _
   { _
      rmData(0).MarkDetectedPoints(0), _
      rmData(1).MarkDetectedPoints(0), _
      rmData(2).MarkDetectedPoints(0) _
   }

   ' Find center of mass for detected registration marks in the transformed image
   Dim transformed() As LeadPoint = CoreUtilities.GetRegistrationMarksCenterMass(leadImage, detected)
   ' Find transformation parameters
   Dim parameters As TransformationParameters = CoreUtilities.GetTransformationParameters(leadImage, original, transformed)
   ' Apply transformatin parameters to correct the image
   Dim applyCommand As New ApplyTransformationParametersCommand(parameters.XTranslation, parameters.YTranslation, _
                                                                parameters.Angle, parameters.XScale, _
                                                                parameters.YScale, ApplyTransformationParametersCommandFlags.Normal)

   applyCommand.Run(leadImage)

End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;

      
public void GetTransformationParametersExample()
{
   // Load an image
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "RGSRef.cmp"));

   // Prepare the command
   SearchRegistrationMarksCommandData[] rmData = new SearchRegistrationMarksCommandData[3];

   //Mark1
   rmData[0] = new SearchRegistrationMarksCommandData();
   rmData[0].Rectangle = new LeadRect(680, 20, 941 - 680, 218 - 20);
   rmData[0].MarkDetectedPoints = new LeadPoint[1];
   rmData[0].Width = 31;
   rmData[0].Height = 29;
   rmData[0].Type = RegistrationMarkCommandType.TShape;
   rmData[0].MinimumScale = 90;
   rmData[0].MaximumScale = 110;
   rmData[0].SearchMarkCount = 1;

   //Mark2
   rmData[1] = new SearchRegistrationMarksCommandData();
   rmData[1].Rectangle = new LeadRect(665, 790, 899 - 665, 961 - 790);
   rmData[1].MarkDetectedPoints = new LeadPoint[1];
   rmData[1].Width = 31;
   rmData[1].Height = 29;
   rmData[1].Type = RegistrationMarkCommandType.TShape;
   rmData[1].MinimumScale = 90;
   rmData[1].MaximumScale = 110;
   rmData[1].SearchMarkCount = 1;

   //Mark3
   rmData[2] = new SearchRegistrationMarksCommandData();
   rmData[2].Rectangle = new LeadRect(7, 1073, 298 - 7, 1246 - 1073);
   rmData[2].MarkDetectedPoints = new LeadPoint[1];
   rmData[2].Width = 31;
   rmData[2].Height = 29;
   rmData[2].Type = RegistrationMarkCommandType.TShape;
   rmData[2].MinimumScale = 90;
   rmData[2].MaximumScale = 110;
   rmData[2].SearchMarkCount = 1;
   SearchRegistrationMarksCommand command1 = new SearchRegistrationMarksCommand(rmData);
   command1.Run(image);
   if ((rmData[2].MarkDetectedCount != 1) || (rmData[1].MarkDetectedCount != 1) || (rmData[0].MarkDetectedCount != 1))
      return;

   LeadPoint[] original =
   {
      new LeadPoint(81400, 11300),
      new LeadPoint(78600, 87400),
      new LeadPoint(14300, 115400)
   };

   LeadPoint[] detected =
   {
      rmData[0].MarkDetectedPoints[0],
      rmData[1].MarkDetectedPoints[0],
      rmData[2].MarkDetectedPoints[0]
   };

   //Find center of mass for detected registration marks in the transformed image
   LeadPoint[] transformed = CoreUtilities.GetRegistrationMarksCenterMass(image, detected);
   //Find transformation parameters
   TransformationParameters parameters = CoreUtilities.GetTransformationParameters(image, original, transformed);
   //Apply transformation parameters to correct the image
   ApplyTransformationParametersCommand applyCommand = new ApplyTransformationParametersCommand(parameters.XTranslation, parameters.YTranslation, parameters.Angle, parameters.XScale, parameters.YScale,
         ApplyTransformationParametersCommandFlags.Normal);
   applyCommand.Run(image);

}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
//   
//   public async Task GetTransformationParametersExample()
//   {
//      // Load an image
//      RasterCodecs codecs = new RasterCodecs();
//      codecs.ThrowExceptionsOnInvalidImages = true;

//      // Load the image
//      string srcFileName = @"Assets\Image1.cmp";
//      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
//      RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

//      // Prepare the command
//      SearchRegistrationMarksCommandData[] rmData = new SearchRegistrationMarksCommandData[3];

//      //Mark1
//      rmData[0] = new SearchRegistrationMarksCommandData();
//      rmData[0].Rectangle = LeadRectHelper.Create(680, 20, 941 - 680, 218 - 20);
//      rmData[0].MarkDetectedPoints = new LeadPoint[1];
//      rmData[0].Width = 31;
//      rmData[0].Height = 29;
//      rmData[0].Type = RegistrationMarkCommandType.TShape;
//      rmData[0].MinimumScale = 90;
//      rmData[0].MaximumScale = 110;
//      rmData[0].SearchMarkCount = 1;

//      //Mark2
//      rmData[1] = new SearchRegistrationMarksCommandData();
//      rmData[1].Rectangle = LeadRectHelper.Create(665, 790, 899 - 665, 961 - 790);
//      rmData[1].MarkDetectedPoints = new LeadPoint[1];
//      rmData[1].Width = 31;
//      rmData[1].Height = 29;
//      rmData[1].Type = RegistrationMarkCommandType.TShape;
//      rmData[1].MinimumScale = 90;
//      rmData[1].MaximumScale = 110;
//      rmData[1].SearchMarkCount = 1;

//      //Mark3
//      rmData[2] = new SearchRegistrationMarksCommandData();
//      rmData[2].Rectangle = LeadRectHelper.Create(7, 1073, 298 - 7, 1246 - 1073);
//      rmData[2].MarkDetectedPoints = new LeadPoint[1];
//      rmData[2].Width = 31;
//      rmData[2].Height = 29;
//      rmData[2].Type = RegistrationMarkCommandType.TShape;
//      rmData[2].MinimumScale = 90;
//      rmData[2].MaximumScale = 110;
//      rmData[2].SearchMarkCount = 1;
//      SearchRegistrationMarksCommand command1 = new SearchRegistrationMarksCommand(rmData);
//      command1.Run(image);
//      if ((rmData[2].MarkDetectedCount != 1) || (rmData[1].MarkDetectedCount != 1) || (rmData[0].MarkDetectedCount != 1))
//         return;

//      LeadPoint[] original =
//      {
//         LeadPointHelper.Create(81400, 11300),
//         LeadPointHelper.Create(78600, 87400),
//         LeadPointHelper.Create(14300, 115400)
//      };

//      LeadPoint[] detected =
//      {
//         rmData[0].MarkDetectedPoints[0],
//         rmData[1].MarkDetectedPoints[0],
//         rmData[2].MarkDetectedPoints[0]
//      };

//      //Find center of mass for detected registration marks in the transformed image
//      LeadPoint[] transformed = CoreUtilities.GetRegistrationMarksCenterMass(image, detected);
//      //Find transformation parameters
//      TransformationParameters parameters = CoreUtilities.GetTransformationParameters(image, original, transformed);
//      //Apply transformation parameters to correct the image
//      ApplyTransformationParametersCommand applyCommand = new ApplyTransformationParametersCommand(parameters.XTranslation, parameters.YTranslation, parameters.Angle, parameters.XScale, parameters.YScale, ApplyTransformationParametersCommandFlags.Normal);
//      applyCommand.Run(image);

//   }
//
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Core;

      
public async Task GetTransformationParametersExample()
{
   // Load an image
   RasterCodecs codecs = new RasterCodecs();
   codecs.ThrowExceptionsOnInvalidImages = true;
   // Load the image
   string srcFileName = @"Assets\Image1.cmp";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // Prepare the command
   SearchRegistrationMarksCommandData[] rmData = new SearchRegistrationMarksCommandData[3];

   //Mark1
   rmData[0] = new SearchRegistrationMarksCommandData();
   rmData[0].Rectangle = LeadRectHelper.Create(680, 20, 941 - 680, 218 - 20);
   rmData[0].MarkDetectedPoints = new LeadPoint[1];
   rmData[0].Width = 31;
   rmData[0].Height = 29;
   rmData[0].Type = RegistrationMarkCommandType.TShape;
   rmData[0].MinimumScale = 90;
   rmData[0].MaximumScale = 110;
   rmData[0].SearchMarkCount = 1;

   //Mark2
   rmData[1] = new SearchRegistrationMarksCommandData();
   rmData[1].Rectangle = LeadRectHelper.Create(665, 790, 899 - 665, 961 - 790);
   rmData[1].MarkDetectedPoints = new LeadPoint[1];
   rmData[1].Width = 31;
   rmData[1].Height = 29;
   rmData[1].Type = RegistrationMarkCommandType.TShape;
   rmData[1].MinimumScale = 90;
   rmData[1].MaximumScale = 110;
   rmData[1].SearchMarkCount = 1;

   //Mark3
   rmData[2] = new SearchRegistrationMarksCommandData();
   rmData[2].Rectangle = LeadRectHelper.Create(7, 1073, 298 - 7, 1246 - 1073);
   rmData[2].MarkDetectedPoints = new LeadPoint[1];
   rmData[2].Width = 31;
   rmData[2].Height = 29;
   rmData[2].Type = RegistrationMarkCommandType.TShape;
   rmData[2].MinimumScale = 90;
   rmData[2].MaximumScale = 110;
   rmData[2].SearchMarkCount = 1;
   SearchRegistrationMarksCommand command1 = new SearchRegistrationMarksCommand(rmData);
   command1.Run(image);
   if ((rmData[2].MarkDetectedCount != 1) || (rmData[1].MarkDetectedCount != 1) || (rmData[0].MarkDetectedCount != 1))
      return;

   LeadPoint[] original =
   {
      LeadPointHelper.Create(81400, 11300),
      LeadPointHelper.Create(78600, 87400),
      LeadPointHelper.Create(14300, 115400)
   };

   LeadPoint[] detected =
   {
      rmData[0].MarkDetectedPoints[0],
      rmData[1].MarkDetectedPoints[0],
      rmData[2].MarkDetectedPoints[0]
   };

   //Find center of mass for detected registration marks in the transformed image
   LeadPoint[] transformed = CoreUtilities.GetRegistrationMarksCenterMass(image, detected);
   //Find transformation parameters
   TransformationParameters parameters = CoreUtilities.GetTransformationParameters(image, original, transformed);
   //Apply transformation parameters to correct the image
   ApplyTransformationParametersCommand applyCommand = new ApplyTransformationParametersCommand(parameters.XTranslation, parameters.YTranslation, parameters.Angle, parameters.XScale, parameters.YScale,
         ApplyTransformationParametersCommandFlags.Normal);
   applyCommand.Run(image);

}
必要条件

ターゲットプラットホーム

参照

参照

CoreUtilitiesメンバ
Leadtools.ImageProcessing.Core名前空間