2013-09-12 12:50:55 +02:00
|
|
|
|
// *****************************************************************
|
|
|
|
|
// Delphi-OpenCV Demo
|
|
|
|
|
// Copyright (C) 2013 Project Delphi-OpenCV
|
|
|
|
|
// ****************************************************************
|
|
|
|
|
// Contributor:
|
|
|
|
|
// Laentir Valetov
|
|
|
|
|
// email:laex@bk.ru
|
|
|
|
|
// ****************************************************************
|
|
|
|
|
// You may retrieve the latest version of this file at the GitHub,
|
|
|
|
|
// located at git://github.com/Laex/Delphi-OpenCV.git
|
|
|
|
|
// ****************************************************************
|
|
|
|
|
// The contents of this file are used with permission, subject to
|
|
|
|
|
// the Mozilla Public License Version 1.1 (the "License"); you may
|
|
|
|
|
// not use this file except in compliance with the License. You may
|
|
|
|
|
// obtain a copy of the License at
|
|
|
|
|
// http://www.mozilla.org/MPL/MPL-1_1Final.html
|
|
|
|
|
//
|
|
|
|
|
// Software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
|
// implied. See the License for the specific language governing
|
|
|
|
|
// rights and limitations under the License.
|
|
|
|
|
// *******************************************************************
|
|
|
|
|
|
|
|
|
|
unit uOCVImageOperation;
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2014-05-07 13:14:32 +02:00
|
|
|
|
Winapi.Windows,
|
2013-09-12 12:50:55 +02:00
|
|
|
|
System.SysUtils,
|
|
|
|
|
System.Classes,
|
|
|
|
|
System.SyncObjs,
|
2014-05-07 13:14:32 +02:00
|
|
|
|
System.Types,
|
2013-09-12 12:50:55 +02:00
|
|
|
|
uOCVTypes,
|
2014-05-11 15:15:21 +02:00
|
|
|
|
objdetect_c,
|
2014-05-08 22:52:42 +02:00
|
|
|
|
core.types_c,
|
|
|
|
|
Vcl.Graphics;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
2014-05-11 02:42:34 +02:00
|
|
|
|
TocvCustomImageOperation = class(TComponent)
|
2014-05-07 13:14:32 +02:00
|
|
|
|
protected
|
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
private
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FCriticalSection: TCriticalSection;
|
|
|
|
|
FOwner: TPersistent;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
FFloatParams: TArray<Double>;
|
|
|
|
|
FIntParams: TArray<Integer>;
|
|
|
|
|
FBoolParams: TArray<Boolean>;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
FOnAfterPaint: TOnOcvAfterTransform;
|
|
|
|
|
FOnBeforePaint: TOnOcvBeforeTransform;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
protected
|
2014-05-07 13:14:32 +02:00
|
|
|
|
function GetFloatParam(const index: Integer): Double;
|
|
|
|
|
function GetIntParam(const index: Integer): Integer;
|
|
|
|
|
procedure SetFloatParam(const index: Integer; const Value: Double);
|
|
|
|
|
procedure SetIntParam(const index: Integer; const Value: Integer);
|
|
|
|
|
function GetBoolParam(const index: Integer): Boolean;
|
|
|
|
|
procedure SetBoolParam(const index: Integer; const Value: Boolean);
|
2014-05-06 21:13:57 +02:00
|
|
|
|
function LockTransform: Boolean;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
procedure UnlockTransform;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
function GetOwner: TPersistent; override;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; virtual;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
property FloatParams[const index: Integer]: Double Read GetFloatParam write SetFloatParam;
|
|
|
|
|
property IntParams[const index: Integer]: Integer Read GetIntParam write SetIntParam;
|
|
|
|
|
property BoolParams[const index: Integer]: Boolean Read GetBoolParam write SetBoolParam;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
public
|
2014-05-11 02:42:34 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); reintroduce; virtual;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
destructor Destroy; override;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function Transform(const Source: IocvImage; var Destanation: IocvImage): Boolean; virtual;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
function GetNamePath: string; override;
|
|
|
|
|
property Name;
|
|
|
|
|
published
|
2014-05-15 02:09:58 +02:00
|
|
|
|
property OnAfterPaint: TOnOcvAfterTransform read FOnAfterPaint write FOnAfterPaint;
|
|
|
|
|
property OnBeforePaint: TOnOcvBeforeTransform read FOnBeforePaint write FOnBeforePaint;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvImageOperationClass = class of TocvCustomImageOperation;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TocvNoneOperation = class(TocvCustomImageOperation)
|
2013-09-12 12:50:55 +02:00
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TocvGrayScaleOperation = class(TocvCustomImageOperation)
|
2013-09-12 12:50:55 +02:00
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TovcCannyOperation = class(TocvCustomImageOperation)
|
2013-09-12 12:50:55 +02:00
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
published
|
2014-05-08 22:52:42 +02:00
|
|
|
|
property Threshold1: Double index 0 Read GetFloatParam write SetFloatParam;
|
|
|
|
|
property Threshold2: Double index 1 Read GetFloatParam write SetFloatParam;
|
|
|
|
|
property ApertureSize: Integer index 0 Read GetIntParam write SetIntParam;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
TocvErodeDilateMode = (SHAPE_RECT, SHAPE_CROSS, SHAPE_ELLIPSE, SHAPE_CUSTOM);
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TovcCustomErodeDilateOperation = class(TocvCustomImageOperation)
|
2014-05-06 21:13:57 +02:00
|
|
|
|
protected
|
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
|
|
|
|
private
|
|
|
|
|
FMorphOp: TocvErodeDilateMode;
|
|
|
|
|
procedure SetMorphOp(const Value: TocvErodeDilateMode);
|
|
|
|
|
protected
|
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
published
|
2014-05-08 22:52:42 +02:00
|
|
|
|
property Radius: Integer index 0 Read GetIntParam write SetIntParam;
|
|
|
|
|
property Iterations: Integer index 1 Read GetIntParam write SetIntParam;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
property MorphOp: TocvErodeDilateMode read FMorphOp write SetMorphOp default SHAPE_RECT;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TovcErodeOperation = class(TovcCustomErodeDilateOperation)
|
2014-05-06 21:13:57 +02:00
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TovcDilateOperation = class(TovcCustomErodeDilateOperation)
|
2014-05-06 21:13:57 +02:00
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TocvLaplaceOperation = class(TocvCustomImageOperation)
|
2014-05-06 21:13:57 +02:00
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
published
|
2014-05-08 22:52:42 +02:00
|
|
|
|
property Aperture: Integer index 0 Read GetIntParam write SetIntParam;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TovcSobelOperation = class(TocvCustomImageOperation)
|
2014-05-06 21:13:57 +02:00
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
published
|
2014-05-08 22:52:42 +02:00
|
|
|
|
property XOrder: Integer index 0 Read GetIntParam write SetIntParam;
|
|
|
|
|
property YOrder: Integer index 1 Read GetIntParam write SetIntParam;
|
|
|
|
|
property Aperture: Integer index 2 Read GetIntParam write SetIntParam;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
TocvSmoothOperations = (BLUR_NO_SCALE, BLUR, GAUSSIAN, MEDIAN, BILATERAL);
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TovcSmoothOperation = class(TocvCustomImageOperation)
|
2013-12-02 19:39:13 +01:00
|
|
|
|
protected
|
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
private
|
|
|
|
|
FSmoothOperation: TocvSmoothOperations;
|
|
|
|
|
procedure SetSmoothOperation(const Value: TocvSmoothOperations);
|
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
published
|
2014-05-08 22:52:42 +02:00
|
|
|
|
property sigma1: Double index 0 Read GetFloatParam write SetFloatParam;
|
|
|
|
|
property sigma2: Double index 1 Read GetFloatParam write SetFloatParam;
|
|
|
|
|
property size1: Integer index 0 Read GetIntParam write SetIntParam;
|
|
|
|
|
property size2: Integer index 1 Read GetIntParam write SetIntParam;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
property SmoothOperation: TocvSmoothOperations read FSmoothOperation write SetSmoothOperation default GAUSSIAN;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TocvThresholdType = (THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV, THRESH_MASK,
|
|
|
|
|
THRESH_OTSU);
|
|
|
|
|
|
|
|
|
|
TocvCustomThresholdOperation = class(TocvCustomImageOperation)
|
|
|
|
|
private
|
|
|
|
|
function GetThresholdType: TocvThresholdType;
|
|
|
|
|
procedure SetThresholdType(const Value: TocvThresholdType);
|
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
published
|
|
|
|
|
property MaxValue: Double index 0 Read GetFloatParam write SetFloatParam; // default 250;
|
|
|
|
|
property ThresholdType: TocvThresholdType read GetThresholdType write SetThresholdType default THRESH_BINARY; // index 0
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvThresholdOperation = class(TocvCustomThresholdOperation)
|
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
published
|
|
|
|
|
property Threshold: Double index 1 Read GetFloatParam write SetFloatParam; // default 50;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvAdaptiveThresholdType = (ADAPTIVE_THRESH_MEAN_C, ADAPTIVE_THRESH_GAUSSIAN_C);
|
|
|
|
|
|
|
|
|
|
TocvAdaptiveThresholdOperation = class(TocvCustomThresholdOperation)
|
|
|
|
|
private
|
|
|
|
|
function GetAdaptiveThresholdType: TocvAdaptiveThresholdType;
|
|
|
|
|
procedure SetAdaptiveThresholdType(const Value: TocvAdaptiveThresholdType);
|
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
published
|
|
|
|
|
property AdaptiveThresholdType: TocvAdaptiveThresholdType read GetAdaptiveThresholdType write SetAdaptiveThresholdType
|
|
|
|
|
default ADAPTIVE_THRESH_MEAN_C; // index 1
|
|
|
|
|
property BlockSize: Integer index 2 Read GetIntParam write SetIntParam; // 3
|
|
|
|
|
property Param: Double index 1 Read GetFloatParam write SetFloatParam; // 5;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvPoint = class(TPersistent)
|
|
|
|
|
protected
|
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
|
|
|
|
private
|
|
|
|
|
FPoint: TPoint;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
public
|
|
|
|
|
constructor Create(const AX: Integer = 0; const AY: Integer = 0);
|
2014-05-07 13:14:32 +02:00
|
|
|
|
published
|
|
|
|
|
property X: Integer read FPoint.X write FPoint.X;
|
|
|
|
|
property Y: Integer read FPoint.Y write FPoint.Y;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 23:33:52 +02:00
|
|
|
|
TocvInterpolationMethod = (INTER_NN, INTER_LINEAR, INTER_CUBIC, INTER_AREA, INTER_LANCZOS4);
|
|
|
|
|
|
|
|
|
|
TocvInterpolationWarpingFlag = (WARP_FILL_OUTLIERS, WARP_INVERSE_MAP);
|
|
|
|
|
TocvInterpolationWarpingFlagSet = set of TocvInterpolationWarpingFlag;
|
|
|
|
|
|
|
|
|
|
TocvRotateOperation = class(TocvCustomImageOperation)
|
2014-05-07 13:14:32 +02:00
|
|
|
|
protected
|
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
|
|
|
|
private
|
2014-05-08 23:33:52 +02:00
|
|
|
|
FCustomCenter: TocvPoint;
|
|
|
|
|
FMethod: TocvInterpolationMethod;
|
|
|
|
|
FWarpingFlag: TocvInterpolationWarpingFlagSet;
|
|
|
|
|
FScale: Double;
|
|
|
|
|
public
|
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
published
|
2014-05-08 23:33:52 +02:00
|
|
|
|
property Angle: Integer index 0 Read GetIntParam write SetIntParam;
|
|
|
|
|
property RotateAroundCenter: Boolean index 0 Read GetBoolParam write SetBoolParam;
|
|
|
|
|
property CustomCenter: TocvPoint Read FCustomCenter write FCustomCenter;
|
|
|
|
|
property Method: TocvInterpolationMethod read FMethod write FMethod default INTER_LINEAR;
|
|
|
|
|
property WarpingFlag: TocvInterpolationWarpingFlagSet read FWarpingFlag write FWarpingFlag default [WARP_FILL_OUTLIERS];
|
|
|
|
|
property Scale: Double read FScale write FScale;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
TocvAbsDiff = class(TocvCustomImageOperation)
|
|
|
|
|
protected
|
|
|
|
|
FPrevFrame: IocvImage;
|
|
|
|
|
public
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
end;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TocvLineType = (LT_FILLED, LT_8, LT_AA);
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
TocvDraw = class(TPersistent)
|
2014-05-07 13:14:32 +02:00
|
|
|
|
protected
|
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
|
|
|
|
function GetOwner: TPersistent; override;
|
|
|
|
|
private
|
|
|
|
|
FOwner: TPersistent;
|
|
|
|
|
FOffset: TocvPoint;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
FEnabled: Boolean;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
FThickness: Integer;
|
|
|
|
|
FLineType: TocvLineType;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
FColor: TColor;
|
|
|
|
|
FShift: Integer;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
public
|
|
|
|
|
constructor Create(AOwner: TPersistent);
|
|
|
|
|
destructor Destroy; override;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
property Color: TColor read FColor write FColor default clGreen;
|
|
|
|
|
property Shift: Integer read FShift write FShift default 0;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
published
|
2014-05-11 15:15:21 +02:00
|
|
|
|
property Enabled: Boolean read FEnabled write FEnabled default True;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
property Thickness: Integer read FThickness write FThickness default 2;
|
|
|
|
|
property LineType: TocvLineType read FLineType write FLineType default LT_AA;
|
|
|
|
|
property Offset: TocvPoint read FOffset write FOffset;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-15 02:09:58 +02:00
|
|
|
|
TocvMatchTemplateMethod = (TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED);
|
|
|
|
|
|
|
|
|
|
TocvMatchTemplate = class(TocvCustomImageOperation)
|
|
|
|
|
protected
|
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
|
|
|
|
private
|
|
|
|
|
FMethod: TocvMatchTemplateMethod;
|
|
|
|
|
FIPLTemplate: pIplImage;
|
|
|
|
|
FTemplate: TPicture;
|
|
|
|
|
FOnMathTemplateRect: TOnOcvRect;
|
|
|
|
|
FDrawRect: TocvDraw;
|
|
|
|
|
procedure SetFIPLTemplate(const Value: pIplImage);
|
|
|
|
|
function GetIPLTemplate: pIplImage;
|
|
|
|
|
procedure TemplateOnChange(Sender: TObject);
|
|
|
|
|
public
|
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
|
|
|
|
property IPLTemplate: pIplImage read GetIPLTemplate write SetFIPLTemplate;
|
|
|
|
|
published
|
|
|
|
|
property Method: TocvMatchTemplateMethod read FMethod write FMethod default TM_CCOEFF_NORMED;
|
|
|
|
|
property Template: TPicture Read FTemplate write FTemplate;
|
|
|
|
|
property DrawRect: TocvDraw read FDrawRect write FDrawRect;
|
|
|
|
|
property OnMathTemplateRect: TOnOcvRect read FOnMathTemplateRect write FOnMathTemplateRect;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
TocvFaceDraw = class(TocvDraw)
|
|
|
|
|
published
|
|
|
|
|
property Color;
|
|
|
|
|
property Shift;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvHaarFrontalFace = (HCFFA, HCFFA2, HCFFD, HCFFAT);
|
|
|
|
|
|
|
|
|
|
TocvHaarCascadeFlag = (HAAR_DO_CANNY_PRUNING, HAAR_SCALE_IMAGE, HAAR_FIND_BIGGEST_OBJECT, HAAR_DO_ROUGH_SEARCH);
|
|
|
|
|
TocvHaarCascadeFlagSet = set of TocvHaarCascadeFlag;
|
|
|
|
|
|
|
|
|
|
TocvFaceDetect = class(TocvCustomImageOperation)
|
|
|
|
|
private
|
|
|
|
|
FFrontalFace: TocvHaarFrontalFace;
|
|
|
|
|
FLockFrontalFaceChange: TCriticalSection;
|
|
|
|
|
FCascade: pCvHaarClassifierCascade;
|
|
|
|
|
FMinSize: TocvPoint;
|
|
|
|
|
FMaxSize: TocvPoint;
|
|
|
|
|
FDrawFace: TocvFaceDraw;
|
|
|
|
|
FCascadeFlags: TocvHaarCascadeFlagSet;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
FOnFace: TOnOcvFaces;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
procedure SetFrontalFace(const Value: TocvHaarFrontalFace);
|
|
|
|
|
procedure ReleaseCascade;
|
|
|
|
|
function GetHaarCascadeFlag: Integer;
|
|
|
|
|
protected
|
|
|
|
|
FPrevFrame: IocvImage;
|
|
|
|
|
public
|
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
|
|
|
|
published
|
|
|
|
|
property FrontalFace: TocvHaarFrontalFace read FFrontalFace write SetFrontalFace default HCFFA;
|
|
|
|
|
property Equalize: Boolean index 1 Read GetBoolParam write SetBoolParam;
|
|
|
|
|
property Scale: Double index 0 Read GetFloatParam write SetFloatParam; // 1.3
|
|
|
|
|
property MinNeighbors: Integer index 0 Read GetIntParam write SetIntParam; // 3
|
|
|
|
|
property MinSize: TocvPoint read FMinSize write FMinSize; // CV_DEFAULT(cvSize(0,0))
|
|
|
|
|
property MaxSize: TocvPoint read FMaxSize write FMaxSize; // {CV_DEFAULT(cvSize(0,0))}
|
|
|
|
|
property DrawFace: TocvFaceDraw read FDrawFace write FDrawFace;
|
|
|
|
|
property CascadeFlags: TocvHaarCascadeFlagSet read FCascadeFlags write FCascadeFlags default [];
|
2014-05-15 02:09:58 +02:00
|
|
|
|
property OnFaces: TOnOcvFaces read FOnFace write FOnFace;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
IocvEditorPropertiesContainer = interface
|
|
|
|
|
['{418F88DD-E35D-4425-BF24-E753E83D35D6}']
|
|
|
|
|
function GetProperties: TocvCustomImageOperation;
|
|
|
|
|
function GetPropertiesClass: TocvImageOperationClass;
|
|
|
|
|
procedure SetPropertiesClass(Value: TocvImageOperationClass);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvContourDraw = class(TocvDraw)
|
|
|
|
|
protected
|
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
|
|
|
|
private
|
|
|
|
|
FHoleColor: TColor;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
FMaxLevel: Integer;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
public
|
|
|
|
|
constructor Create(AOwner: TPersistent);
|
|
|
|
|
published
|
|
|
|
|
property ExternalColor: TColor read FColor write FColor default clGreen;
|
|
|
|
|
property HoleColor: TColor read FHoleColor write FHoleColor default clRed;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
property MaxLevel: Integer read FMaxLevel write FMaxLevel default 2;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvContourRetrievalModes = (RETR_EXTERNAL, RETR_LIST, RETR_CCOMP, RETR_TREE, RETR_FLOODFILL);
|
|
|
|
|
|
|
|
|
|
TocvContourApproximationMethods = (CHAIN_CODE, CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, CHAIN_APPROX_TC89_L1,
|
|
|
|
|
CHAIN_APPROX_TC89_KCOS, LINK_RUNS);
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
TocvContourApprox = class(TPersistent)
|
|
|
|
|
protected
|
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
|
|
|
|
function GetOwner: TPersistent; override;
|
|
|
|
|
private
|
|
|
|
|
FOwner: TPersistent;
|
|
|
|
|
FEnabled: Boolean;
|
|
|
|
|
FRecursive: Boolean;
|
|
|
|
|
FEps: Double;
|
|
|
|
|
public
|
|
|
|
|
constructor Create(AOwner: TPersistent);
|
|
|
|
|
published
|
|
|
|
|
property Enabled: Boolean read FEnabled write FEnabled default True;
|
|
|
|
|
property Eps: Double read FEps write FEps;
|
|
|
|
|
property Recursive: Boolean read FRecursive write FRecursive default True;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
TocvContoursOperation = class(TocvCustomImageOperation, IocvEditorPropertiesContainer)
|
|
|
|
|
private
|
|
|
|
|
CS: TCriticalSection;
|
|
|
|
|
FOperation: TocvCustomImageOperation;
|
|
|
|
|
FOperationClass: TocvImageOperationClass;
|
|
|
|
|
FRetrievalMode: TocvContourRetrievalModes;
|
|
|
|
|
FApproximationMethod: TocvContourApproximationMethods;
|
|
|
|
|
FOffset: TocvPoint;
|
|
|
|
|
FContourDraw: TocvContourDraw;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FApprox: TocvContourApprox;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FOnContour: TOnOcvContour;
|
|
|
|
|
FContours: pCvSeq;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
function LockTransform: Boolean;
|
|
|
|
|
procedure UnlockTransform;
|
|
|
|
|
procedure CreateProperties;
|
|
|
|
|
procedure DestroyProperties;
|
|
|
|
|
procedure RecreateProperties;
|
|
|
|
|
function GetPropertiesClassName: string;
|
|
|
|
|
procedure SetProperties(const Value: TocvCustomImageOperation);
|
|
|
|
|
procedure SetPropertiesClass(Value: TocvImageOperationClass);
|
|
|
|
|
procedure SetPropertiesClassName(const Value: string);
|
2014-05-08 22:52:42 +02:00
|
|
|
|
procedure DoNotifyContours(const Image: IocvImage; const ContourCount: Integer; const Contours: pCvSeq);
|
2014-05-07 13:14:32 +02:00
|
|
|
|
protected
|
|
|
|
|
function GetProperties: TocvCustomImageOperation;
|
|
|
|
|
function GetPropertiesClass: TocvImageOperationClass;
|
|
|
|
|
{IInterface}
|
|
|
|
|
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
|
|
|
|
|
function _AddRef: Integer; stdcall;
|
|
|
|
|
function _Release: Integer; stdcall;
|
|
|
|
|
public
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor Create(AOwner: TPersistent); override;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
destructor Destroy; override;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
property OperationClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
property Contours: pCvSeq read FContours;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
published
|
|
|
|
|
property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
|
|
|
|
property Preprocessing: TocvCustomImageOperation read GetProperties write SetProperties;
|
|
|
|
|
property RetrievalMode: TocvContourRetrievalModes read FRetrievalMode write FRetrievalMode default RETR_LIST;
|
|
|
|
|
property ApproximationMethod: TocvContourApproximationMethods read FApproximationMethod write FApproximationMethod
|
|
|
|
|
default CHAIN_APPROX_SIMPLE;
|
|
|
|
|
property Offset: TocvPoint read FOffset write FOffset;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
property MinArea: Integer index 0 Read GetIntParam write SetIntParam;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
property ContourDraw: TocvContourDraw read FContourDraw write FContourDraw;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
property ApproxPoly: TocvContourApprox read FApprox write FApprox;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
property OnContour: TOnOcvContour read FOnContour write FOnContour;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
TocvImageOperationCollectionItem = class(TCollectionItem, IocvEditorPropertiesContainer)
|
|
|
|
|
private
|
|
|
|
|
CS: TCriticalSection;
|
|
|
|
|
FOperation: TocvCustomImageOperation;
|
|
|
|
|
FOperationClass: TocvImageOperationClass;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
FOnAfterPaint: TOnOcvAfterTransform;
|
|
|
|
|
FOnBeforePaint: TOnOcvBeforeTransform;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FOwner: TCollection;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
function LockTransform: Boolean;
|
|
|
|
|
procedure UnlockTransform;
|
|
|
|
|
procedure CreateProperties;
|
|
|
|
|
procedure DestroyProperties;
|
|
|
|
|
procedure RecreateProperties;
|
|
|
|
|
function GetPropertiesClassName: string;
|
|
|
|
|
procedure SetProperties(const Value: TocvCustomImageOperation);
|
|
|
|
|
procedure SetPropertiesClass(Value: TocvImageOperationClass);
|
|
|
|
|
procedure SetPropertiesClassName(const Value: string);
|
|
|
|
|
protected
|
2014-05-15 02:09:58 +02:00
|
|
|
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; virtual;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
function GetProperties: TocvCustomImageOperation;
|
|
|
|
|
function GetPropertiesClass: TocvImageOperationClass;
|
|
|
|
|
function GetDisplayName: string; override;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
function GetOwner: TPersistent; override;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
{IInterface}
|
|
|
|
|
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
|
|
|
|
|
function _AddRef: Integer; stdcall;
|
|
|
|
|
function _Release: Integer; stdcall;
|
|
|
|
|
public
|
|
|
|
|
constructor Create(Collection: TCollection); override;
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
procedure Assign(Source: TPersistent); override;
|
|
|
|
|
property OperationClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
function Transform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
published
|
|
|
|
|
property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
|
|
|
|
property Operation: TocvCustomImageOperation read GetProperties write SetProperties;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
property OnAfterPaint: TOnOcvAfterTransform read FOnAfterPaint write FOnAfterPaint;
|
|
|
|
|
property OnBeforePaint: TOnOcvBeforeTransform read FOnBeforePaint write FOnBeforePaint;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvImageOperationCollection = class(TOwnedCollection);
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
TocvImageOperation = class(TocvDataSourceAndReceiver, IocvEditorPropertiesContainer)
|
2013-09-12 12:50:55 +02:00
|
|
|
|
private
|
2013-12-02 19:39:13 +01:00
|
|
|
|
CS: TCriticalSection;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FOperation: TocvCustomImageOperation;
|
|
|
|
|
FOperationClass: TocvImageOperationClass;
|
|
|
|
|
FOperations: TocvImageOperationCollection;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FUseCollection: Boolean;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
function LockTransform: Boolean;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
procedure UnlockTransform;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
procedure CreateProperties;
|
|
|
|
|
procedure DestroyProperties;
|
|
|
|
|
procedure RecreateProperties;
|
|
|
|
|
function GetPropertiesClassName: string;
|
|
|
|
|
procedure SetProperties(const Value: TocvCustomImageOperation);
|
|
|
|
|
procedure SetPropertiesClass(Value: TocvImageOperationClass);
|
|
|
|
|
procedure SetPropertiesClassName(const Value: string);
|
2014-05-11 02:42:34 +02:00
|
|
|
|
procedure SetUseCollection(const Value: Boolean);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
protected
|
2014-05-08 22:52:42 +02:00
|
|
|
|
procedure TakeImage(const IplImage: IocvImage); override;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
function GetProperties: TocvCustomImageOperation;
|
|
|
|
|
function GetPropertiesClass: TocvImageOperationClass;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
public
|
2013-12-02 19:39:13 +01:00
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
destructor Destroy; override;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
property OperationClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
published
|
2014-05-06 21:13:57 +02:00
|
|
|
|
property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
|
|
|
|
property Operation: TocvCustomImageOperation read GetProperties write SetProperties;
|
|
|
|
|
property Operations: TocvImageOperationCollection Read FOperations write FOperations;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
property OperationsEnabled: Boolean read FUseCollection write SetUseCollection default True;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TRegisteredImageOperations = class(TStringList)
|
|
|
|
|
public
|
|
|
|
|
function FindByClassName(const ClassName: String): TocvImageOperationClass;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
function FindByName(const Name: String): TocvImageOperationClass;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
function GetNameByClass(const IOClass: TClass): String;
|
|
|
|
|
procedure RegisterIOClass(const IOClass: TClass; const ClassName: String);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
function GetRegisteredImageOperations: TRegisteredImageOperations;
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
implementation
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
{$R opencv.dres}
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
Uses
|
|
|
|
|
core_c,
|
|
|
|
|
imgproc_c,
|
2014-05-11 15:15:21 +02:00
|
|
|
|
imgproc.types_c, cvUtils;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2014-05-11 02:42:34 +02:00
|
|
|
|
type
|
|
|
|
|
TPersistentAccessProtected = class(TPersistent);
|
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
|
Var
|
2014-02-24 20:18:30 +01:00
|
|
|
|
_RegisteredImageOperations: TRegisteredImageOperations = nil;
|
|
|
|
|
|
|
|
|
|
function GetRegisteredImageOperations: TRegisteredImageOperations;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
begin
|
2014-02-24 20:18:30 +01:00
|
|
|
|
if not Assigned(_RegisteredImageOperations) then
|
|
|
|
|
_RegisteredImageOperations := TRegisteredImageOperations.Create;
|
|
|
|
|
Result := _RegisteredImageOperations;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
const
|
|
|
|
|
cLineType: array [TocvLineType] of Integer = (CV_FILLED, 8, CV_AA);
|
|
|
|
|
|
|
|
|
|
procedure GetRGBValue(const AColor: TColor; var r, g, b: byte);
|
|
|
|
|
Var
|
|
|
|
|
RGBColor: TColor;
|
|
|
|
|
begin
|
|
|
|
|
RGBColor := ColorToRGB(AColor);
|
|
|
|
|
r := GetRValue(RGBColor);
|
|
|
|
|
g := GetGValue(RGBColor);
|
|
|
|
|
b := GetBValue(RGBColor);
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
{TocvImageOperation}
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
procedure TocvImageOperation.SetProperties(const Value: TocvCustomImageOperation);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
if (FOperation <> nil) and (Value <> nil) then
|
|
|
|
|
FOperation.Assign(Value);
|
2014-02-24 20:18:30 +01:00
|
|
|
|
end;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
procedure TocvImageOperation.SetPropertiesClass(Value: TocvImageOperationClass);
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
if FOperationClass <> Value then
|
2014-02-24 20:18:30 +01:00
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FOperationClass := Value;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
RecreateProperties;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
procedure TocvImageOperation.CreateProperties;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
if FOperationClass <> nil then
|
|
|
|
|
FOperation := FOperationClass.Create(Self);
|
2014-02-24 20:18:30 +01:00
|
|
|
|
end;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
procedure TocvImageOperation.DestroyProperties;
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FreeAndNil(FOperation);
|
2014-02-24 20:18:30 +01:00
|
|
|
|
end;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
procedure TocvImageOperation.RecreateProperties;
|
|
|
|
|
begin
|
|
|
|
|
DestroyProperties;
|
|
|
|
|
CreateProperties;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperation.SetPropertiesClassName(const Value: string);
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
OperationClass := TocvImageOperationClass(GetRegisteredImageOperations.FindByClassName(Value));
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 02:42:34 +02:00
|
|
|
|
procedure TocvImageOperation.SetUseCollection(const Value: Boolean);
|
|
|
|
|
begin
|
|
|
|
|
if FUseCollection <> Value then
|
|
|
|
|
begin
|
|
|
|
|
CS.Enter;
|
|
|
|
|
try
|
|
|
|
|
FUseCollection := Value;
|
|
|
|
|
finally
|
|
|
|
|
CS.Leave;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
|
constructor TocvImageOperation.Create(AOwner: TComponent);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
|
inherited;
|
|
|
|
|
CS := TCriticalSection.Create;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FOperations := TocvImageOperationCollection.Create(Self, TocvImageOperationCollectionItem);
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FUseCollection := True;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvImageOperation.Destroy;
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
if LockTransform then
|
|
|
|
|
if Assigned(FOperation) then
|
|
|
|
|
FreeAndNil(FOperation);
|
|
|
|
|
FOperations.Free;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
CS.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
function TocvImageOperation.GetProperties: TocvCustomImageOperation;
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
if not Assigned(FOperation) then
|
2014-05-07 13:14:32 +02:00
|
|
|
|
FOperation := TocvNoneOperation.Create(Self);
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Result := FOperation;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperation.GetPropertiesClass: TocvImageOperationClass;
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Result := TocvImageOperationClass(Operation.ClassType);
|
2014-02-24 20:18:30 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperation.GetPropertiesClassName: string;
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Result := Operation.ClassName;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
function TocvImageOperation.LockTransform: Boolean;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Result := CS.TryEnter;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
procedure TocvImageOperation.TakeImage(const IplImage: IocvImage);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
var
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Destanation: IocvImage;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
i: Integer;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
if LockTransform then
|
2013-09-12 12:50:55 +02:00
|
|
|
|
try
|
2014-05-11 02:42:34 +02:00
|
|
|
|
Destanation := IplImage;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
|
2014-05-11 02:42:34 +02:00
|
|
|
|
if OperationsEnabled and (FOperations.Count > 0) then
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
|
|
|
|
for i := 0 to FOperations.Count - 1 do
|
2014-05-15 02:09:58 +02:00
|
|
|
|
if not(FOperations.Items[i] as TocvImageOperationCollectionItem).Transform(Destanation, Destanation) then
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Exit;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
end
|
2014-05-11 02:42:34 +02:00
|
|
|
|
else if Assigned(FOperation) then
|
2014-05-15 02:09:58 +02:00
|
|
|
|
FOperation.Transform(IplImage, Destanation);
|
|
|
|
|
|
2014-05-11 02:42:34 +02:00
|
|
|
|
NotifyReceiver(Destanation);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
finally
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Destanation := nil;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
UnlockTransform;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
procedure TocvImageOperation.UnlockTransform;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
CS.Leave;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
{TovcImageOperationCanny}
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor TovcCannyOperation.Create {(AOwner: TPersistent)};
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
inherited;
|
|
|
|
|
Threshold1 := 10;
|
|
|
|
|
Threshold2 := 100;
|
|
|
|
|
ApertureSize := 3;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TovcCannyOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Destanation := TocvImage.Create(cvCreateImage(cvGetSize(Source.IpImage), IPL_DEPTH_8U, 1));
|
|
|
|
|
cvCanny(Source.GrayImage.IpImage, Destanation.IpImage, Threshold1, Threshold2, ApertureSize);
|
|
|
|
|
Result := True;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
{TocvImageOperationGrayScale}
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvGrayScaleOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Destanation := Source.GrayImage;
|
|
|
|
|
Result := True;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
{TocvImageOperationNone}
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvNoneOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Destanation := Source;
|
|
|
|
|
Result := True;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
{TCustomOpenCVImgOperation}
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
procedure TocvCustomImageOperation.AssignTo(Dest: TPersistent);
|
|
|
|
|
begin
|
|
|
|
|
if Dest is TocvCustomImageOperation then
|
|
|
|
|
begin
|
|
|
|
|
FFloatParams := (Dest as TocvCustomImageOperation).FFloatParams;
|
|
|
|
|
FIntParams := (Dest as TocvCustomImageOperation).FIntParams;
|
|
|
|
|
FBoolParams := (Dest as TocvCustomImageOperation).FBoolParams;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor TocvCustomImageOperation.Create(AOwner: TPersistent);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-11 02:42:34 +02:00
|
|
|
|
if AOwner is TComponent then
|
|
|
|
|
inherited Create(AOwner as TComponent)
|
|
|
|
|
else
|
|
|
|
|
inherited Create(nil);
|
|
|
|
|
SetSubComponent(True);
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
FOwner := AOwner;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FCriticalSection := TCriticalSection.Create;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvCustomImageOperation.Destroy;
|
|
|
|
|
begin
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FCriticalSection.Free;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvCustomImageOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
|
|
|
|
begin
|
2014-05-11 02:42:34 +02:00
|
|
|
|
Result := False;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
function TocvCustomImageOperation.GetBoolParam(const index: Integer): Boolean;
|
|
|
|
|
begin
|
|
|
|
|
if (index >= 0) and (index < Length(FBoolParams)) then
|
|
|
|
|
Result := FBoolParams[index]
|
|
|
|
|
else
|
2014-05-11 02:42:34 +02:00
|
|
|
|
Result := False;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvCustomImageOperation.GetFloatParam(const index: Integer): Double;
|
|
|
|
|
begin
|
|
|
|
|
if (index >= 0) and (index < Length(FFloatParams)) then
|
|
|
|
|
Result := FFloatParams[index]
|
|
|
|
|
else
|
|
|
|
|
Result := 0;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvCustomImageOperation.GetIntParam(const index: Integer): Integer;
|
|
|
|
|
begin
|
|
|
|
|
if (index >= 0) and (index < Length(FIntParams)) then
|
|
|
|
|
Result := FIntParams[index]
|
|
|
|
|
else
|
|
|
|
|
Result := 0;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 02:42:34 +02:00
|
|
|
|
function TocvCustomImageOperation.GetNamePath: string;
|
|
|
|
|
var
|
|
|
|
|
S: string;
|
|
|
|
|
lOwner: TPersistent;
|
|
|
|
|
begin
|
|
|
|
|
Result := inherited GetNamePath;
|
|
|
|
|
lOwner := GetOwner;
|
|
|
|
|
if
|
|
|
|
|
{} (lOwner <> nil) and
|
|
|
|
|
{} (
|
|
|
|
|
{} (csSubComponent in TComponent(lOwner).ComponentStyle) or
|
|
|
|
|
{} (TPersistentAccessProtected(lOwner).GetOwner <> nil)
|
|
|
|
|
{} ) then
|
|
|
|
|
begin
|
|
|
|
|
S := lOwner.GetNamePath;
|
|
|
|
|
if S <> '' then
|
|
|
|
|
Result := S + '.' + Result;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvCustomImageOperation.GetOwner: TPersistent;
|
|
|
|
|
begin
|
|
|
|
|
Result := FOwner;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
function TocvCustomImageOperation.LockTransform: Boolean;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-11 02:42:34 +02:00
|
|
|
|
Result := FCriticalSection.TryEnter;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
procedure TocvCustomImageOperation.SetBoolParam(const index: Integer; const Value: Boolean);
|
|
|
|
|
begin
|
|
|
|
|
if (index >= 0) and LockTransform then
|
|
|
|
|
try
|
|
|
|
|
if index > High(FBoolParams) then
|
|
|
|
|
SetLength(FBoolParams, index + 1);
|
|
|
|
|
FBoolParams[index] := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvCustomImageOperation.SetFloatParam(const index: Integer; const Value: Double);
|
|
|
|
|
begin
|
|
|
|
|
if (index >= 0) and LockTransform then
|
|
|
|
|
try
|
|
|
|
|
if index > High(FFloatParams) then
|
|
|
|
|
SetLength(FFloatParams, index + 1);
|
|
|
|
|
FFloatParams[index] := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvCustomImageOperation.SetIntParam(const index: Integer; const Value: Integer);
|
|
|
|
|
begin
|
|
|
|
|
if (index >= 0) and LockTransform then
|
|
|
|
|
try
|
|
|
|
|
if index > High(FIntParams) then
|
|
|
|
|
SetLength(FIntParams, index + 1);
|
|
|
|
|
FIntParams[index] := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvCustomImageOperation.Transform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
Var
|
|
|
|
|
Transform: Boolean;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
begin
|
|
|
|
|
Result := LockTransform;
|
|
|
|
|
if Result then
|
|
|
|
|
try
|
2014-05-15 02:09:58 +02:00
|
|
|
|
Transform := True;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
if Assigned(OnBeforePaint) then
|
2014-05-15 02:09:58 +02:00
|
|
|
|
OnBeforePaint(Self, Source, Transform);
|
|
|
|
|
if Transform then
|
|
|
|
|
Result := DoTransform(Source, Destanation)
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
Destanation := Source;
|
|
|
|
|
Result := True;
|
|
|
|
|
end;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
if Result and Assigned(OnAfterPaint) then
|
|
|
|
|
OnAfterPaint(Self, Source);
|
2014-05-08 22:52:42 +02:00
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
procedure TocvCustomImageOperation.UnlockTransform;
|
|
|
|
|
begin
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FCriticalSection.Leave;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
{TovcImageOperationSmooth}
|
2013-09-12 12:50:55 +02:00
|
|
|
|
Const
|
2014-05-06 21:13:57 +02:00
|
|
|
|
ocvSmoothOperations: array [TocvSmoothOperations] of Integer = (CV_BLUR_NO_SCALE, CV_BLUR, CV_GAUSSIAN, CV_MEDIAN,
|
|
|
|
|
CV_BILATERAL);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
procedure TovcSmoothOperation.AssignTo(Dest: TPersistent);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
inherited;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
if Dest is TovcSmoothOperation then
|
|
|
|
|
FSmoothOperation := (Dest as TovcSmoothOperation).FSmoothOperation;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
constructor TovcSmoothOperation.Create {(AOwner: TPersistent)};
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
FSmoothOperation := GAUSSIAN;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
size1 := 3;
|
|
|
|
|
size2 := 3;
|
|
|
|
|
sigma1 := 0;
|
|
|
|
|
sigma2 := 0;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
procedure TovcSmoothOperation.SetSmoothOperation(const Value: TocvSmoothOperations);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
if LockTransform then
|
|
|
|
|
try
|
|
|
|
|
FSmoothOperation := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TovcSmoothOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
|
|
|
|
Var
|
|
|
|
|
Image: pIplImage;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Image := cvCloneImage(Source.IpImage);
|
|
|
|
|
cvSmooth(Source.IpImage, Image, ocvSmoothOperations[SmoothOperation], size1, size2, sigma1, sigma2);
|
|
|
|
|
Destanation := TocvImage.Create(Image);
|
|
|
|
|
Result := True;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
{TRegisteredImageOperations}
|
2014-02-24 20:18:30 +01:00
|
|
|
|
|
|
|
|
|
function TRegisteredImageOperations.FindByClassName(const ClassName: String): TocvImageOperationClass;
|
|
|
|
|
Var
|
|
|
|
|
i: Integer;
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
for i := 0 to Count - 1 do
|
|
|
|
|
if TocvImageOperationClass(Objects[i]).ClassName = ClassName then
|
|
|
|
|
Exit(TocvImageOperationClass(Objects[i]));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TRegisteredImageOperations.FindByName(const Name: String): TocvImageOperationClass;
|
|
|
|
|
Var
|
|
|
|
|
i: Integer;
|
|
|
|
|
begin
|
|
|
|
|
i := IndexOf(Name);
|
2014-02-24 20:18:30 +01:00
|
|
|
|
if i <> -1 then
|
|
|
|
|
Result := TocvImageOperationClass(Objects[i])
|
|
|
|
|
else
|
|
|
|
|
Result := Nil;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TRegisteredImageOperations.GetNameByClass(const IOClass: TClass): String;
|
|
|
|
|
Var
|
|
|
|
|
i: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := '';
|
|
|
|
|
for i := 0 to Count - 1 do
|
|
|
|
|
if Integer(Objects[i]) = Integer(IOClass) then
|
|
|
|
|
begin
|
|
|
|
|
Result := Self[i];
|
|
|
|
|
Break;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TRegisteredImageOperations.RegisterIOClass(const IOClass: TClass; const ClassName: String);
|
|
|
|
|
begin
|
|
|
|
|
AddObject(ClassName, TObject(IOClass));
|
|
|
|
|
RegisterClass(TPersistentClass(IOClass));
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
{TovcCustomErodeDilate}
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
procedure TovcCustomErodeDilateOperation.AssignTo(Dest: TPersistent);
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
inherited;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
if Dest is TovcCustomErodeDilateOperation then
|
|
|
|
|
FMorphOp := (Dest as TovcCustomErodeDilateOperation).MorphOp;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor TovcCustomErodeDilateOperation.Create {(AOwner: TComponent)};
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Radius := 5;
|
|
|
|
|
Iterations := 5;
|
|
|
|
|
FMorphOp := SHAPE_RECT;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
procedure TovcCustomErodeDilateOperation.SetMorphOp(const Value: TocvErodeDilateMode);
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
|
|
|
|
if LockTransform then
|
|
|
|
|
try
|
|
|
|
|
FMorphOp := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
EDMorpgOp: array [TocvErodeDilateMode] of Integer = (CV_SHAPE_RECT, CV_SHAPE_CROSS, CV_SHAPE_ELLIPSE, CV_SHAPE_CUSTOM);
|
|
|
|
|
|
|
|
|
|
{TovcErode}
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TovcErodeOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Var
|
|
|
|
|
Kern: pIplConvKernel;
|
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Destanation := TocvImage.Create(cvCloneImage(Source.IpImage));
|
|
|
|
|
Kern := cvCreateStructuringElementEx(Radius * 2 + 1, Radius * 2 + 1, Radius, Radius, EDMorpgOp[FMorphOp]);
|
|
|
|
|
cvErode(Source.IpImage, Destanation.IpImage, Kern, Iterations);
|
|
|
|
|
cvReleaseStructuringElement(Kern);
|
|
|
|
|
Result := True;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TovcDilate}
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TovcDilateOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Var
|
|
|
|
|
Kern: pIplConvKernel;
|
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Destanation := TocvImage.Create(cvCloneImage(Source.IpImage));
|
|
|
|
|
Kern := cvCreateStructuringElementEx(Radius * 2 + 1, Radius * 2 + 1, Radius, Radius, EDMorpgOp[FMorphOp]);
|
|
|
|
|
cvDilate(Source.IpImage, Destanation.IpImage, Kern, Iterations);
|
|
|
|
|
cvReleaseStructuringElement(Kern);
|
|
|
|
|
Result := True;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TocvLaplace}
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor TocvLaplaceOperation.Create {(AOwner: TComponent)};
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Aperture := 3;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvLaplaceOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Var
|
2014-05-08 22:52:42 +02:00
|
|
|
|
TempImg: pIplImage;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
TempImg := cvCreateImage(cvGetSize(Source.IpImage), IPL_DEPTH_16S, Source.IpImage^.nChannels);
|
|
|
|
|
Destanation := TocvImage.Create(cvCreateImage(cvGetSize(Source.IpImage), Source.IpImage^.depth, Source.IpImage^.nChannels));
|
|
|
|
|
cvLaplace(Source.IpImage, TempImg, Aperture);
|
|
|
|
|
cvConvertScale(TempImg, Destanation.IpImage);
|
|
|
|
|
cvReleaseImage(TempImg);
|
|
|
|
|
Result := True;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TovcSobel}
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor TovcSobelOperation.Create {(AOwner: TComponent)};
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
XOrder := 1;
|
|
|
|
|
YOrder := 1;
|
|
|
|
|
Aperture := 3;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TovcSobelOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Var
|
2014-05-08 22:52:42 +02:00
|
|
|
|
TmpImg: pIplImage;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
TmpImg := cvCreateImage(cvGetSize(Source.IpImage), IPL_DEPTH_16S, Source.IpImage^.nChannels);
|
|
|
|
|
Destanation := TocvImage.Create(cvCreateImage(cvGetSize(Source.IpImage), Source.IpImage^.depth, Source.IpImage^.nChannels));
|
|
|
|
|
cvSobel(Source.IpImage, TmpImg, XOrder, YOrder, Aperture);
|
|
|
|
|
cvConvertScale(TmpImg, Destanation.IpImage);
|
|
|
|
|
cvReleaseImage(TmpImg);
|
|
|
|
|
Result := True;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TocvImageOperationCollectionItem}
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperationCollectionItem.Assign(Source: TPersistent);
|
|
|
|
|
begin
|
|
|
|
|
if Source is TocvImageOperationCollectionItem then
|
|
|
|
|
Operation.Assign(TocvImageOperationCollectionItem(Source).Operation)
|
|
|
|
|
else
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TocvImageOperationCollectionItem.Create(Collection: TCollection);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FOwner := Collection;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
CS := TCriticalSection.Create;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperationCollectionItem.CreateProperties;
|
|
|
|
|
begin
|
|
|
|
|
if FOperationClass <> nil then
|
2014-05-11 02:42:34 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FOperation := FOperationClass.Create(Self);
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FOperation.SetParentComponent((GetOwner as TOwnedCollection).Owner as TComponent);
|
|
|
|
|
end;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvImageOperationCollectionItem.Destroy;
|
|
|
|
|
begin
|
2014-05-07 13:14:32 +02:00
|
|
|
|
if Assigned(FOperation) then
|
|
|
|
|
FOperation.Free;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
CS.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperationCollectionItem.DestroyProperties;
|
|
|
|
|
begin
|
|
|
|
|
FreeAndNil(FOperation);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperationCollectionItem.GetDisplayName: string;
|
|
|
|
|
begin
|
|
|
|
|
Result := GetRegisteredImageOperations.GetNameByClass(FOperation.ClassType);
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 02:42:34 +02:00
|
|
|
|
function TocvImageOperationCollectionItem.GetOwner: TPersistent;
|
|
|
|
|
begin
|
|
|
|
|
Result := FOwner;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
function TocvImageOperationCollectionItem.GetProperties: TocvCustomImageOperation;
|
|
|
|
|
begin
|
|
|
|
|
if not Assigned(FOperation) then
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FOperation := TocvNoneOperation.Create(Self);
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Result := FOperation;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperationCollectionItem.GetPropertiesClass: TocvImageOperationClass;
|
|
|
|
|
begin
|
|
|
|
|
Result := TocvImageOperationClass(Operation.ClassType);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperationCollectionItem.GetPropertiesClassName: string;
|
|
|
|
|
begin
|
|
|
|
|
Result := Operation.ClassName;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperationCollectionItem.LockTransform: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := CS.TryEnter;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperationCollectionItem.QueryInterface(const IID: TGUID; out Obj): HResult;
|
|
|
|
|
begin
|
|
|
|
|
if GetInterface(IID, Obj) then
|
|
|
|
|
Result := 0
|
|
|
|
|
else
|
|
|
|
|
Result := E_NOINTERFACE;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperationCollectionItem.RecreateProperties;
|
|
|
|
|
begin
|
|
|
|
|
DestroyProperties;
|
|
|
|
|
CreateProperties;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperationCollectionItem.SetProperties(const Value: TocvCustomImageOperation);
|
|
|
|
|
begin
|
|
|
|
|
if (FOperation <> nil) and (Value <> nil) then
|
|
|
|
|
FOperation.Assign(Value);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperationCollectionItem.SetPropertiesClass(Value: TocvImageOperationClass);
|
|
|
|
|
begin
|
|
|
|
|
if FOperationClass <> Value then
|
|
|
|
|
begin
|
|
|
|
|
FOperationClass := Value;
|
|
|
|
|
RecreateProperties;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperationCollectionItem.SetPropertiesClassName(const Value: string);
|
|
|
|
|
begin
|
|
|
|
|
OperationClass := TocvImageOperationClass(GetRegisteredImageOperations.FindByClassName(Value));
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvImageOperationCollectionItem.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
begin
|
|
|
|
|
Result := Assigned(FOperation) and FOperation.DoTransform(Source, Destanation);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperationCollectionItem.Transform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
|
|
|
|
Var
|
|
|
|
|
Transform: Boolean;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
2014-05-11 02:42:34 +02:00
|
|
|
|
Result := LockTransform;
|
|
|
|
|
if Result then
|
2014-05-06 21:13:57 +02:00
|
|
|
|
try
|
2014-05-15 02:09:58 +02:00
|
|
|
|
Transform := True;
|
|
|
|
|
if Assigned(OnBeforePaint) then
|
|
|
|
|
OnBeforePaint(Self, Source, Transform);
|
|
|
|
|
if Transform then
|
|
|
|
|
Result := DoTransform(Source, Destanation)
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
Destanation := Source;
|
|
|
|
|
Result := True;
|
|
|
|
|
end;
|
|
|
|
|
if Result and Assigned(OnAfterPaint) then
|
|
|
|
|
OnAfterPaint(Self, Source);
|
2014-05-06 21:13:57 +02:00
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperationCollectionItem.UnlockTransform;
|
|
|
|
|
begin
|
|
|
|
|
CS.Leave;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperationCollectionItem._AddRef: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := -1;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperationCollectionItem._Release: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := -1;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
{TocvThresholdOperation}
|
|
|
|
|
|
|
|
|
|
Const
|
|
|
|
|
cThreshold: array [TocvThresholdType] of Integer = (CV_THRESH_BINARY, CV_THRESH_BINARY_INV, CV_THRESH_TRUNC, CV_THRESH_TOZERO,
|
|
|
|
|
CV_THRESH_TOZERO_INV, CV_THRESH_MASK, CV_THRESH_OTSU);
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor TocvThresholdOperation.Create {(AOwner: TComponent)};
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
Threshold := 50;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor TocvCustomThresholdOperation.Create {(AOwner: TComponent)};
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
MaxValue := 250;
|
|
|
|
|
ThresholdType := THRESH_BINARY;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvCustomThresholdOperation.GetThresholdType: TocvThresholdType;
|
|
|
|
|
begin
|
|
|
|
|
Result := TocvThresholdType(GetIntParam(0));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvCustomThresholdOperation.SetThresholdType(const Value: TocvThresholdType);
|
|
|
|
|
begin
|
|
|
|
|
SetIntParam(0, Integer(Value));
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvThresholdOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Destanation := TocvImage.Create(cvCreateImage(cvGetSize(Source.IpImage), IPL_DEPTH_8U, 1));
|
|
|
|
|
cvThreshold(Source.GrayImage.IpImage, Destanation.IpImage, Threshold, MaxValue, cThreshold[ThresholdType]);
|
|
|
|
|
Result := True;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TocvAdaptiveThresholdOperation}
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
cAdaptiveThresholdType: array [TocvAdaptiveThresholdType] of Integer = (CV_ADAPTIVE_THRESH_MEAN_C,
|
|
|
|
|
CV_ADAPTIVE_THRESH_GAUSSIAN_C);
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor TocvAdaptiveThresholdOperation.Create {(AOwner: TComponent)};
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
AdaptiveThresholdType := ADAPTIVE_THRESH_MEAN_C;
|
|
|
|
|
BlockSize := 3;
|
|
|
|
|
Param := 5;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvAdaptiveThresholdOperation.GetAdaptiveThresholdType: TocvAdaptiveThresholdType;
|
|
|
|
|
begin
|
|
|
|
|
Result := TocvAdaptiveThresholdType(GetIntParam(1));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvAdaptiveThresholdOperation.SetAdaptiveThresholdType(const Value: TocvAdaptiveThresholdType);
|
|
|
|
|
begin
|
|
|
|
|
SetIntParam(1, Integer(Value));
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvAdaptiveThresholdOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Destanation := TocvImage.Create(cvCreateImage(cvGetSize(Source.IpImage), IPL_DEPTH_8U, 1));
|
|
|
|
|
cvAdaptiveThreshold(Source.GrayImage.IpImage, Destanation.IpImage, MaxValue, cAdaptiveThresholdType[AdaptiveThresholdType],
|
|
|
|
|
cThreshold[ThresholdType], BlockSize, Param);
|
|
|
|
|
Result := True;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TocvContoursOperation}
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
constructor TocvContoursOperation.Create {(AOwner: TComponent)};
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
CS := TCriticalSection.Create;
|
|
|
|
|
FOffset := TocvPoint.Create;
|
|
|
|
|
FContourDraw := TocvContourDraw.Create(Self);
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FApprox := TocvContourApprox.Create(Self);
|
2014-05-07 13:14:32 +02:00
|
|
|
|
OperationClass := TocvThresholdOperation;
|
|
|
|
|
With Preprocessing as TocvThresholdOperation do
|
|
|
|
|
begin
|
|
|
|
|
Threshold := 128;
|
|
|
|
|
MaxValue := 255;
|
|
|
|
|
ThresholdType := THRESH_BINARY_INV;
|
|
|
|
|
end;
|
|
|
|
|
RetrievalMode := RETR_LIST;
|
|
|
|
|
ApproximationMethod := CHAIN_APPROX_SIMPLE;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
MinArea := 100;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvContoursOperation.CreateProperties;
|
|
|
|
|
begin
|
|
|
|
|
if FOperationClass <> nil then
|
|
|
|
|
FOperation := FOperationClass.Create(nil);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvContoursOperation.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FOperation) then
|
|
|
|
|
FOperation.Free;
|
|
|
|
|
CS.Free;
|
|
|
|
|
FOffset.Free;
|
|
|
|
|
FContourDraw.Free;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FApprox.Free;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvContoursOperation.DestroyProperties;
|
|
|
|
|
begin
|
|
|
|
|
FreeAndNil(FOperation);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvContoursOperation.GetProperties: TocvCustomImageOperation;
|
|
|
|
|
begin
|
|
|
|
|
if not Assigned(FOperation) then
|
|
|
|
|
FOperation := TocvNoneOperation.Create(nil);
|
|
|
|
|
Result := FOperation;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvContoursOperation.GetPropertiesClass: TocvImageOperationClass;
|
|
|
|
|
begin
|
|
|
|
|
Result := TocvImageOperationClass(Preprocessing.ClassType);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvContoursOperation.GetPropertiesClassName: string;
|
|
|
|
|
begin
|
|
|
|
|
Result := Preprocessing.ClassName;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvContoursOperation.LockTransform: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := CS.TryEnter;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvContoursOperation.QueryInterface(const IID: TGUID; out Obj): HResult;
|
|
|
|
|
begin
|
|
|
|
|
if GetInterface(IID, Obj) then
|
|
|
|
|
Result := 0
|
|
|
|
|
else
|
|
|
|
|
Result := E_NOINTERFACE;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvContoursOperation.RecreateProperties;
|
|
|
|
|
begin
|
|
|
|
|
DestroyProperties;
|
|
|
|
|
CreateProperties;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvContoursOperation.SetProperties(const Value: TocvCustomImageOperation);
|
|
|
|
|
begin
|
|
|
|
|
if (FOperation <> nil) and (Value <> nil) then
|
|
|
|
|
FOperation.Assign(Value);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvContoursOperation.SetPropertiesClass(Value: TocvImageOperationClass);
|
|
|
|
|
begin
|
|
|
|
|
if FOperationClass <> Value then
|
|
|
|
|
begin
|
|
|
|
|
FOperationClass := Value;
|
|
|
|
|
RecreateProperties;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvContoursOperation.SetPropertiesClassName(const Value: string);
|
|
|
|
|
begin
|
|
|
|
|
OperationClass := TocvImageOperationClass(GetRegisteredImageOperations.FindByClassName(Value));
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvContoursOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
Var
|
2014-05-08 22:52:42 +02:00
|
|
|
|
th_image: IocvImage;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
storage: pCvMemStorage;
|
|
|
|
|
contoursCont: Integer;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
er, eg, eb: byte;
|
|
|
|
|
hr, hg, hb: byte;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
s_contours: pCvSeq;
|
|
|
|
|
area: Double;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
2014-05-11 02:42:34 +02:00
|
|
|
|
Result := False;
|
|
|
|
|
FContours := nil;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
th_image := nil;
|
|
|
|
|
storage := cvCreateMemStorage(0);
|
|
|
|
|
try
|
|
|
|
|
Destanation := Source; // .Clone;
|
|
|
|
|
if Preprocessing.Transform(Source, th_image) then
|
|
|
|
|
begin
|
|
|
|
|
contoursCont := cvFindContours(th_image.IpImage, storage, @Contours, SizeOf(TCvContour), Integer(RetrievalMode),
|
|
|
|
|
Integer(ApproximationMethod), cvPoint(Offset.X, Offset.Y));
|
|
|
|
|
if ApproxPoly.Enabled then
|
2014-05-11 02:42:34 +02:00
|
|
|
|
FContours := cvApproxPoly(Contours, SizeOf(TCvContour), storage, CV_POLY_APPROX_DP, ApproxPoly.Eps,
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Integer(ApproxPoly.Recursive));
|
|
|
|
|
DoNotifyContours(Destanation, contoursCont, Contours);
|
|
|
|
|
if (contoursCont > 0) and ContourDraw.Enabled then
|
|
|
|
|
begin
|
|
|
|
|
GetRGBValue(ContourDraw.ExternalColor, er, eg, eb);
|
|
|
|
|
GetRGBValue(ContourDraw.HoleColor, hr, hg, hb);
|
2014-05-11 02:42:34 +02:00
|
|
|
|
if MinArea > 0 then
|
|
|
|
|
begin
|
|
|
|
|
s_contours := Contours;
|
|
|
|
|
while (s_contours <> nil) do
|
|
|
|
|
begin
|
|
|
|
|
area := cvContourArea(s_contours, CV_WHOLE_SEQ);
|
|
|
|
|
if abs(area) > MinArea then
|
|
|
|
|
cvDrawContours(Destanation.IpImage, s_contours, CV_RGB(er, eg, eb), CV_RGB(hr, hg, hb), ContourDraw.MaxLevel,
|
|
|
|
|
ContourDraw.Thickness, cLineType[ContourDraw.LineType], cvPoint(ContourDraw.Offset.X, ContourDraw.Offset.Y));
|
|
|
|
|
s_contours := s_contours.h_next;
|
|
|
|
|
end;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
cvDrawContours(Destanation.IpImage, FContours, CV_RGB(er, eg, eb), CV_RGB(hr, hg, hb), ContourDraw.MaxLevel,
|
|
|
|
|
ContourDraw.Thickness, cLineType[ContourDraw.LineType], cvPoint(ContourDraw.Offset.X, ContourDraw.Offset.Y));
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Result := True;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
finally
|
|
|
|
|
cvReleaseMemStorage(storage)
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvContoursOperation.DoNotifyContours(const Image: IocvImage; const ContourCount: Integer; const Contours: pCvSeq);
|
2014-05-11 02:42:34 +02:00
|
|
|
|
begin
|
|
|
|
|
if Assigned(OnContour) then
|
|
|
|
|
OnContour(Self, Image, ContourCount, Contours);
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvContoursOperation.UnlockTransform;
|
|
|
|
|
begin
|
|
|
|
|
CS.Leave;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvContoursOperation._AddRef: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := -1;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvContoursOperation._Release: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := -1;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 08:28:13 +02:00
|
|
|
|
{TocvRotateOperation}
|
|
|
|
|
|
|
|
|
|
procedure TocvRotateOperation.AssignTo(Dest: TPersistent);
|
|
|
|
|
begin
|
2014-05-15 02:09:58 +02:00
|
|
|
|
inherited;
|
2014-05-08 08:28:13 +02:00
|
|
|
|
if Dest is TocvRotateOperation then
|
|
|
|
|
begin
|
2014-05-08 23:33:52 +02:00
|
|
|
|
FCustomCenter := (Dest as TocvRotateOperation).FCustomCenter;
|
|
|
|
|
FMethod := (Dest as TocvRotateOperation).FMethod;
|
|
|
|
|
FWarpingFlag := (Dest as TocvRotateOperation).FWarpingFlag;
|
|
|
|
|
FScale := (Dest as TocvRotateOperation).FScale;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
end;
|
2014-05-08 08:28:13 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 23:33:52 +02:00
|
|
|
|
constructor TocvRotateOperation.Create(AOwner: TPersistent);
|
2014-05-08 08:28:13 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2014-05-08 23:33:52 +02:00
|
|
|
|
Angle := 90;
|
|
|
|
|
FCustomCenter := TocvPoint.Create;
|
|
|
|
|
RotateAroundCenter := True;
|
|
|
|
|
Method := INTER_LINEAR;
|
|
|
|
|
WarpingFlag := [WARP_FILL_OUTLIERS];
|
|
|
|
|
Scale := 1;
|
2014-05-08 08:28:13 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 23:33:52 +02:00
|
|
|
|
destructor TocvRotateOperation.Destroy;
|
2014-05-08 08:28:13 +02:00
|
|
|
|
begin
|
2014-05-08 23:33:52 +02:00
|
|
|
|
FCustomCenter.Free;
|
|
|
|
|
inherited;
|
2014-05-08 08:28:13 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 23:33:52 +02:00
|
|
|
|
function TocvRotateOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
2014-05-08 08:28:13 +02:00
|
|
|
|
Var
|
|
|
|
|
rot_mat: pCvMat;
|
|
|
|
|
center: TcvPoint2D32f;
|
|
|
|
|
D: pIplImage;
|
2014-05-08 23:33:52 +02:00
|
|
|
|
M: Integer;
|
2014-05-08 08:28:13 +02:00
|
|
|
|
begin
|
2014-05-08 23:33:52 +02:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
rot_mat := cvCreateMat(2, 3, CV_32FC1);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if RotateAroundCenter then
|
|
|
|
|
begin
|
|
|
|
|
center.X := Source.IpImage^.width div 2;
|
|
|
|
|
center.Y := Source.IpImage^.height div 2;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
center.X := CustomCenter.X;
|
|
|
|
|
center.Y := CustomCenter.Y;
|
|
|
|
|
end;
|
|
|
|
|
cv2DRotationMatrix(center, Angle, Scale, rot_mat);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
D := cvCreateImage(cvGetSize(Source.IpImage), Source.IpImage^.depth, Source.IpImage^.nChannels);
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
M := Integer(Method);
|
|
|
|
|
if WARP_FILL_OUTLIERS in FWarpingFlag then
|
|
|
|
|
M := M or CV_WARP_FILL_OUTLIERS;
|
|
|
|
|
if WARP_INVERSE_MAP in FWarpingFlag then
|
|
|
|
|
M := M or CV_WARP_INVERSE_MAP;
|
|
|
|
|
cvWarpAffine(Source.IpImage, D, rot_mat, M, cvScalarAll(0));
|
|
|
|
|
cvReleaseMat(rot_mat);
|
|
|
|
|
Destanation := TocvImage.Create(D);
|
|
|
|
|
Result := True;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
{TPersistentPoint}
|
|
|
|
|
|
|
|
|
|
procedure TocvPoint.AssignTo(Dest: TPersistent);
|
|
|
|
|
begin
|
2014-05-11 15:15:21 +02:00
|
|
|
|
inherited;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
if Dest is TocvPoint then
|
|
|
|
|
FPoint := (Dest as TocvPoint).FPoint;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TocvCountourDraw}
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
procedure TocvDraw.AssignTo(Dest: TPersistent);
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
2014-05-11 15:15:21 +02:00
|
|
|
|
inherited;
|
|
|
|
|
if Dest is TocvDraw then
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
2014-05-11 15:15:21 +02:00
|
|
|
|
FOffset.FPoint := (Dest as TocvDraw).FOffset.FPoint;
|
|
|
|
|
FEnabled := (Dest as TocvDraw).FEnabled;
|
|
|
|
|
FThickness := (Dest as TocvDraw).FThickness;
|
|
|
|
|
FLineType := (Dest as TocvDraw).FLineType;
|
|
|
|
|
FColor := (Dest as TocvDraw).FColor;
|
|
|
|
|
end;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
constructor TocvDraw.Create(AOwner: TPersistent);
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
FOwner := AOwner;
|
|
|
|
|
FOffset := TocvPoint.Create;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
FEnabled := True;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FThickness := 1;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
FLineType := LT_AA;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
FColor := clGreen;
|
|
|
|
|
FShift := 0;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
destructor TocvDraw.Destroy;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
|
|
|
|
FOffset.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
function TocvDraw.GetOwner: TPersistent;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
|
|
|
|
Result := FOwner;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TocvContourApprox}
|
|
|
|
|
|
|
|
|
|
procedure TocvContourApprox.AssignTo(Dest: TPersistent);
|
|
|
|
|
begin
|
|
|
|
|
if Dest is TocvContourApprox then
|
|
|
|
|
begin
|
|
|
|
|
FEnabled := (Dest as TocvContourApprox).Enabled;
|
|
|
|
|
FEps := (Dest as TocvContourApprox).Eps;
|
|
|
|
|
FRecursive := (Dest as TocvContourApprox).Recursive;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TocvContourApprox.Create(AOwner: TPersistent);
|
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
FOwner := AOwner;
|
|
|
|
|
FEnabled := True;
|
|
|
|
|
FEps := 3;
|
|
|
|
|
FRecursive := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvContourApprox.GetOwner: TPersistent;
|
|
|
|
|
begin
|
|
|
|
|
Result := FOwner;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
{TocvAbsDiff}
|
|
|
|
|
|
|
|
|
|
function TocvAbsDiff.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
|
|
|
|
Var
|
|
|
|
|
GrayImage: IocvImage;
|
|
|
|
|
begin
|
|
|
|
|
GrayImage := Source.GrayImage;
|
|
|
|
|
Destanation := GrayImage.Same;
|
|
|
|
|
if Assigned(FPrevFrame) then
|
|
|
|
|
cvAbsDiff(FPrevFrame.IpImage, GrayImage.IpImage, Destanation.IpImage);
|
|
|
|
|
FPrevFrame := GrayImage;
|
|
|
|
|
Result := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TocvFaceDetect}
|
|
|
|
|
|
|
|
|
|
constructor TocvFaceDetect.Create(AOwner: TPersistent);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
FLockFrontalFaceChange := TCriticalSection.Create;
|
|
|
|
|
FMinSize := TocvPoint.Create(30, 30);
|
|
|
|
|
FMaxSize := TocvPoint.Create;
|
|
|
|
|
FrontalFace := HCFFA;
|
|
|
|
|
FDrawFace := TocvFaceDraw.Create(Self);
|
|
|
|
|
Scale := 1.3;
|
|
|
|
|
MinNeighbors := 3;
|
|
|
|
|
Equalize := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvFaceDetect.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
FLockFrontalFaceChange.Free;
|
|
|
|
|
FMinSize.Free;
|
|
|
|
|
FMaxSize.Free;
|
|
|
|
|
FDrawFace.Free;
|
|
|
|
|
ReleaseCascade;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvFaceDetect.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
|
|
|
|
Var
|
|
|
|
|
storage: pCvMemStorage;
|
|
|
|
|
gray: IocvImage;
|
|
|
|
|
detected_objects: pCvSeq;
|
|
|
|
|
i: Integer;
|
|
|
|
|
cvr: pCvRect;
|
|
|
|
|
r, g, b: byte;
|
|
|
|
|
Faces: TocvFaces;
|
|
|
|
|
begin
|
|
|
|
|
Destanation := Source;
|
|
|
|
|
if Assigned(FCascade) then
|
|
|
|
|
begin
|
|
|
|
|
storage := cvCreateMemStorage(0);
|
|
|
|
|
try
|
|
|
|
|
gray := Source.GrayImage;
|
|
|
|
|
if Equalize then
|
|
|
|
|
cvEqualizeHist(gray.IpImage, gray.IpImage);
|
|
|
|
|
detected_objects := cvHaarDetectObjects(gray.IpImage, FCascade, storage, Scale, MinNeighbors, GetHaarCascadeFlag,
|
|
|
|
|
cvSize(MinSize.X, MinSize.Y), cvSize(MaxSize.X, MaxSize.Y));
|
|
|
|
|
|
|
|
|
|
if Assigned(detected_objects) then
|
|
|
|
|
begin
|
2014-05-15 02:09:58 +02:00
|
|
|
|
|
|
|
|
|
if Assigned(OnFaces) then
|
2014-05-11 15:15:21 +02:00
|
|
|
|
begin
|
|
|
|
|
SetLength(Faces, detected_objects^.total);
|
|
|
|
|
i := 0;
|
|
|
|
|
While i < detected_objects^.total do
|
|
|
|
|
begin
|
|
|
|
|
cvr := pCvRect(cvGetSeqElem(detected_objects, i));
|
2014-05-15 02:09:58 +02:00
|
|
|
|
Faces[i] := ocvRect(cvr^.X, cvr^.Y, (cvr^.X) + (cvr^.width), (cvr^.Y) + (cvr^.height));
|
2014-05-11 15:15:21 +02:00
|
|
|
|
Inc(i);
|
|
|
|
|
end;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
OnFaces(Self, Destanation, Faces);
|
2014-05-11 15:15:21 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
if DrawFace.Enabled then
|
|
|
|
|
begin
|
|
|
|
|
GetRGBValue(DrawFace.Color, r, g, b);
|
|
|
|
|
i := 0;
|
|
|
|
|
While i < detected_objects^.total do
|
|
|
|
|
begin
|
|
|
|
|
cvr := pCvRect(cvGetSeqElem(detected_objects, i));
|
|
|
|
|
cvRectangle(Destanation.IpImage, cvPoint(cvr^.X, cvr^.Y), cvPoint((cvr^.X) + (cvr^.width), (cvr^.Y) + (cvr^.height)),
|
|
|
|
|
CV_RGB(r, g, b), DrawFace.Thickness, cLineType[DrawFace.LineType], DrawFace.Shift);
|
|
|
|
|
Inc(i);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
Result := True;
|
|
|
|
|
finally
|
|
|
|
|
cvReleaseMemStorage(storage);
|
|
|
|
|
end;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvFaceDetect.GetHaarCascadeFlag: Integer;
|
|
|
|
|
Var
|
|
|
|
|
i: TocvHaarCascadeFlag;
|
|
|
|
|
j: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := 0;
|
|
|
|
|
j := 1;
|
|
|
|
|
for i := HAAR_DO_CANNY_PRUNING to HAAR_DO_ROUGH_SEARCH do
|
|
|
|
|
begin
|
|
|
|
|
if i in FCascadeFlags then
|
|
|
|
|
Result := Result or j;
|
|
|
|
|
j := j * 2;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvFaceDetect.ReleaseCascade;
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FCascade) then
|
|
|
|
|
cvReleaseHaarClassifierCascade(FCascade);
|
|
|
|
|
FCascade := nil;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvFaceDetect.SetFrontalFace(const Value: TocvHaarFrontalFace);
|
|
|
|
|
Type
|
|
|
|
|
TFrontalFaceData = record
|
|
|
|
|
Name: String;
|
|
|
|
|
FileName: String;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
|
FrontalFaceXML: array [TocvHaarFrontalFace] of TFrontalFaceData =
|
|
|
|
|
{} ((Name: 'HCFFA'; FileName: 'haarcascade_frontalface_alt.xml'),
|
|
|
|
|
{} (Name: 'HCFFA2'; FileName: 'haarcascade_frontalface_alt2.xml'),
|
|
|
|
|
{} (Name: 'HCFFD'; FileName: 'haarcascade_frontalface_default.xml'),
|
|
|
|
|
{} (Name: 'HCFFAT'; FileName: 'haarcascade_frontalface_alt_tree.xml'));
|
|
|
|
|
|
|
|
|
|
function TempPath: string;
|
|
|
|
|
var
|
|
|
|
|
BufSize: Cardinal;
|
|
|
|
|
begin
|
|
|
|
|
BufSize := GetTempPath(0, nil);
|
|
|
|
|
SetLength(Result, BufSize);
|
|
|
|
|
GetTempPath(BufSize, PChar(Result));
|
|
|
|
|
Result := Trim(Result);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
Var
|
|
|
|
|
FullFileName: String;
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
FLockFrontalFaceChange.Enter;
|
|
|
|
|
try
|
|
|
|
|
if FFrontalFace <> Value then
|
|
|
|
|
begin
|
|
|
|
|
FFrontalFace := Value;
|
|
|
|
|
ReleaseCascade;
|
|
|
|
|
end;
|
|
|
|
|
if not(csDesigning in ComponentState) then
|
|
|
|
|
begin
|
|
|
|
|
if not Assigned(FCascade) then
|
|
|
|
|
try
|
|
|
|
|
FullFileName := TempPath + FrontalFaceXML[FFrontalFace].FileName;
|
|
|
|
|
if not FileExists(FullFileName) then
|
|
|
|
|
begin
|
|
|
|
|
with TResourceStream.Create(hInstance, FrontalFaceXML[FFrontalFace].Name, RT_RCDATA) do
|
|
|
|
|
try
|
|
|
|
|
SaveToFile(FullFileName);
|
|
|
|
|
finally
|
|
|
|
|
Free;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
if FileExists(FullFileName) then
|
|
|
|
|
FCascade := cvLoad(c_str(FullFileName), nil, nil, nil);
|
|
|
|
|
except
|
|
|
|
|
ReleaseCascade;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
finally
|
|
|
|
|
FLockFrontalFaceChange.Leave;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TocvPoint.Create(const AX, AY: Integer);
|
|
|
|
|
begin
|
|
|
|
|
FPoint.X := AX;
|
|
|
|
|
FPoint.Y := AY;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TocvContourDraw}
|
|
|
|
|
|
|
|
|
|
procedure TocvContourDraw.AssignTo(Dest: TPersistent);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
if Dest is TocvContourDraw then
|
2014-05-15 02:09:58 +02:00
|
|
|
|
begin
|
2014-05-11 15:15:21 +02:00
|
|
|
|
FHoleColor := (Dest as TocvContourDraw).FHoleColor;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
FMaxLevel := (Dest as TocvContourDraw).FMaxLevel;
|
|
|
|
|
end;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TocvContourDraw.Create(AOwner: TPersistent);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
FHoleColor := clRed;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
FMaxLevel := 2;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{TocvMatchTemplate}
|
|
|
|
|
|
|
|
|
|
procedure TocvMatchTemplate.AssignTo(Dest: TPersistent);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
if Dest is TocvMatchTemplate then
|
|
|
|
|
begin
|
|
|
|
|
FMethod := (Dest as TocvMatchTemplate).FMethod;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TocvMatchTemplate.Create(AOwner: TPersistent);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
FTemplate := TPicture.Create;
|
|
|
|
|
FTemplate.OnChange := TemplateOnChange;
|
|
|
|
|
FDrawRect := TocvDraw.Create(Self);
|
|
|
|
|
FMethod := TM_CCOEFF_NORMED;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvMatchTemplate.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FIPLTemplate) then
|
|
|
|
|
cvReleaseImage(FIPLTemplate);
|
|
|
|
|
FTemplate.Free;
|
|
|
|
|
FDrawRect.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvMatchTemplate.TemplateOnChange(Sender: TObject);
|
|
|
|
|
begin
|
|
|
|
|
IPLTemplate := nil;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvMatchTemplate.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
|
|
|
|
Var
|
|
|
|
|
imgMat: pIplImage;
|
|
|
|
|
p1, p2: TCvPoint;
|
|
|
|
|
min: Double;
|
|
|
|
|
r, g, b: byte;
|
|
|
|
|
begin
|
|
|
|
|
Destanation := Source;
|
|
|
|
|
if Assigned(IPLTemplate) then
|
|
|
|
|
begin
|
|
|
|
|
imgMat := cvCreateImage(cvSize(Source.IpImage^.width - IPLTemplate^.width + 1, Source.IpImage^.height - IPLTemplate^.height +
|
|
|
|
|
1), IPL_DEPTH_32F, 1);
|
|
|
|
|
cvMatchTemplate(Source.IpImage, IPLTemplate, imgMat, Integer(FMethod));
|
|
|
|
|
|
|
|
|
|
if Assigned(OnMathTemplateRect) or DrawRect.Enabled then
|
|
|
|
|
begin
|
|
|
|
|
cvMinMaxLoc(imgMat, @min, @min, nil, @p1, nil);
|
|
|
|
|
p2.X := p1.X + IPLTemplate^.width - 1;
|
|
|
|
|
p2.Y := p1.Y + IPLTemplate^.height - 1;
|
|
|
|
|
|
|
|
|
|
if Assigned(OnMathTemplateRect) then
|
|
|
|
|
OnMathTemplateRect(Self, Source, ocvRect(p1.X, p1.Y, p2.X, p2.Y));
|
|
|
|
|
|
|
|
|
|
if DrawRect.Enabled then
|
|
|
|
|
begin
|
|
|
|
|
GetRGBValue(DrawRect.Color, r, g, b);
|
|
|
|
|
cvRectangle(Destanation.IpImage, p1, p2, CV_RGB(r, g, b));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
cvReleaseImage(imgMat);
|
|
|
|
|
|
|
|
|
|
Result := True;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvMatchTemplate.GetIPLTemplate: pIplImage;
|
|
|
|
|
begin
|
|
|
|
|
if not Assigned(FIPLTemplate) then
|
|
|
|
|
begin
|
|
|
|
|
if not Template.Bitmap.Empty then
|
|
|
|
|
FIPLTemplate := BitmapToIplImage(Template.Bitmap);
|
|
|
|
|
end;
|
|
|
|
|
Result := FIPLTemplate;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvMatchTemplate.SetFIPLTemplate(const Value: pIplImage);
|
|
|
|
|
begin
|
|
|
|
|
if FIPLTemplate <> Value then
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FIPLTemplate) then
|
|
|
|
|
cvReleaseImage(FIPLTemplate);
|
|
|
|
|
FIPLTemplate := Value;
|
|
|
|
|
end;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
initialization
|
|
|
|
|
|
2014-05-07 13:14:32 +02:00
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvNoneOperation, 'None');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvGrayScaleOperation, 'GrayScale');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TovcCannyOperation, 'Canny');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TovcSmoothOperation, 'Smooth');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TovcErodeOperation, 'Erode');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TovcDilateOperation, 'Dilate');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvLaplaceOperation, 'Laplace');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TovcSobelOperation, 'Sobel');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvThresholdOperation, 'Threshold');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvAdaptiveThresholdOperation, 'AdaptiveThreshold');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvContoursOperation, 'Contours');
|
2014-05-08 08:28:13 +02:00
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvRotateOperation, 'Rotate');
|
2014-05-11 15:15:21 +02:00
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvAbsDiff, 'AbsDiff');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvFaceDetect, 'FaceDetect');
|
2014-05-15 02:09:58 +02:00
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvMatchTemplate, 'MatchTemplate');
|
2014-02-24 20:18:30 +01:00
|
|
|
|
|
|
|
|
|
finalization
|
|
|
|
|
|
|
|
|
|
if Assigned(_RegisteredImageOperations) then
|
|
|
|
|
FreeAndNil(_RegisteredImageOperations);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
|
|
end.
|