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
|
|
|
|
|
System.SysUtils,
|
|
|
|
|
System.Classes,
|
|
|
|
|
System.SyncObjs,
|
|
|
|
|
uOCVTypes,
|
|
|
|
|
core.types_c;
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
|
|
TocvCustomImageOperation = class(TPersistent)
|
|
|
|
|
private
|
2013-12-02 19:39:13 +01:00
|
|
|
|
CS: TCriticalSection;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
FOwner: TComponent;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
protected
|
|
|
|
|
procedure LockTransform;
|
|
|
|
|
procedure UnlockTransform;
|
|
|
|
|
public
|
2014-02-24 20:18:30 +01:00
|
|
|
|
constructor Create(AOwner: TComponent); virtual;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; virtual; abstract;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvImageOperationClass = class of TocvCustomImageOperation;
|
|
|
|
|
|
|
|
|
|
TocvImageOperation_None = class(TocvCustomImageOperation)
|
|
|
|
|
public
|
|
|
|
|
function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; override;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvImageOperation_GrayScale = class(TocvCustomImageOperation)
|
|
|
|
|
public
|
|
|
|
|
function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; override;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TovcImageOperation_Canny = 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
|
2013-12-02 19:39:13 +01:00
|
|
|
|
FThreshold2: double;
|
|
|
|
|
FThreshold1: double;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
FApertureSize: Integer;
|
|
|
|
|
procedure SetApertureSize(const Value: Integer);
|
|
|
|
|
procedure SetThreshold1(const Value: double);
|
|
|
|
|
procedure SetThreshold2(const Value: double);
|
|
|
|
|
protected
|
|
|
|
|
public
|
2014-02-24 20:18:30 +01:00
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; override;
|
|
|
|
|
published
|
2013-12-02 19:39:13 +01:00
|
|
|
|
property Threshold1: double Read FThreshold1 write SetThreshold1;
|
|
|
|
|
property Threshold2: double Read FThreshold2 write SetThreshold2;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
property ApertureSize: Integer Read FApertureSize write SetApertureSize default 100;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvSmoothOperations = (BLUR_NO_SCALE, BLUR, GAUSSIAN, MEDIAN, BILATERAL);
|
|
|
|
|
|
|
|
|
|
TovcImageOperation_Smooth = 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
|
2013-12-02 19:39:13 +01:00
|
|
|
|
FSigma2: double;
|
|
|
|
|
FSize2: Integer;
|
|
|
|
|
FSigma1: double;
|
|
|
|
|
FSize1: Integer;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
FSmoothOperation: TocvSmoothOperations;
|
|
|
|
|
procedure SetSigma1(const Value: double);
|
|
|
|
|
procedure Setsigma2(const Value: double);
|
|
|
|
|
procedure SetSize1(const Value: Integer);
|
|
|
|
|
procedure SetSize2(const Value: Integer);
|
|
|
|
|
procedure SetSmoothOperation(const Value: TocvSmoothOperations);
|
|
|
|
|
public
|
2014-02-24 20:18:30 +01:00
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; override;
|
|
|
|
|
published
|
2013-12-02 19:39:13 +01:00
|
|
|
|
property sigma1: double read FSigma1 write SetSigma1;
|
|
|
|
|
property sigma2: double read FSigma2 write Setsigma2;
|
|
|
|
|
property size1: Integer read FSize1 write SetSize1 default 3;
|
|
|
|
|
property size2: Integer read FSize2 write SetSize2 default 3;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
property SmoothOperation: TocvSmoothOperations read FSmoothOperation write SetSmoothOperation default GAUSSIAN;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
IocvEditorPropertiesContainer = interface
|
|
|
|
|
['{418F88DD-E35D-4425-BF24-E753E83D35D6}']
|
|
|
|
|
function GetProperties: TocvCustomImageOperation;
|
|
|
|
|
function GetPropertiesClass: TocvImageOperationClass;
|
|
|
|
|
procedure SetPropertiesClass(Value: TocvImageOperationClass);
|
|
|
|
|
end;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
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-02-24 20:18:30 +01:00
|
|
|
|
FProperties: TocvCustomImageOperation;
|
|
|
|
|
FPropertiesClass: TocvImageOperationClass;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
procedure LockTransform;
|
|
|
|
|
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);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
protected
|
|
|
|
|
procedure TakeImage(const IplImage: pIplImage); 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-02-24 20:18:30 +01:00
|
|
|
|
property PropertiesClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
published
|
2014-02-24 20:18:30 +01:00
|
|
|
|
property PropertiesClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
|
|
|
|
property Properties: TocvCustomImageOperation read GetProperties write SetProperties;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TRegisteredImageOperations = class(TStringList)
|
|
|
|
|
public
|
|
|
|
|
function FindByClassName(const ClassName: String): TocvImageOperationClass;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
Uses
|
|
|
|
|
core_c,
|
|
|
|
|
imgproc_c,
|
|
|
|
|
imgproc.types_c;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
{ TocvImageOperation }
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
procedure TocvImageOperation.SetProperties(const Value: TocvCustomImageOperation);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-02-24 20:18:30 +01:00
|
|
|
|
if (FProperties <> nil) and (Value <> nil) then
|
|
|
|
|
FProperties.Assign(Value);
|
|
|
|
|
end;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
procedure TocvImageOperation.SetPropertiesClass(Value: TocvImageOperationClass);
|
|
|
|
|
begin
|
|
|
|
|
if FPropertiesClass <> Value then
|
|
|
|
|
begin
|
|
|
|
|
FPropertiesClass := Value;
|
|
|
|
|
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-02-24 20:18:30 +01:00
|
|
|
|
if FPropertiesClass <> nil then
|
|
|
|
|
FProperties := FPropertiesClass.Create(Self);
|
|
|
|
|
end;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
procedure TocvImageOperation.DestroyProperties;
|
|
|
|
|
begin
|
|
|
|
|
FreeAndNil(FProperties);
|
|
|
|
|
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
|
|
|
|
|
PropertiesClass := TocvImageOperationClass(GetRegisteredImageOperations.FindByClassName(Value));
|
2013-09-12 12:50:55 +02:00
|
|
|
|
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;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvImageOperation.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
if Assigned(FProperties) then
|
|
|
|
|
FreeAndNil(FProperties);
|
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
|
|
|
|
|
if not Assigned(FProperties) then
|
|
|
|
|
FProperties := TocvImageOperation_None.Create(Self);
|
|
|
|
|
Result := FProperties;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperation.GetPropertiesClass: TocvImageOperationClass;
|
|
|
|
|
begin
|
|
|
|
|
Result := TocvImageOperationClass(Properties.ClassType);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImageOperation.GetPropertiesClassName: string;
|
|
|
|
|
begin
|
|
|
|
|
Result := Properties.ClassName;
|
|
|
|
|
end;
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
procedure TocvImageOperation.LockTransform;
|
|
|
|
|
begin
|
|
|
|
|
CS.Enter;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperation.TakeImage(const IplImage: pIplImage);
|
|
|
|
|
var
|
|
|
|
|
Destanation: pIplImage;
|
|
|
|
|
begin
|
2014-02-24 20:18:30 +01:00
|
|
|
|
if Assigned(FProperties) and FProperties.Transform(IplImage, Destanation) then
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
|
LockTransform;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
try
|
2013-12-02 19:39:13 +01:00
|
|
|
|
NotifyReceiver(Destanation);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
finally
|
2013-12-02 19:39:13 +01:00
|
|
|
|
UnlockTransform;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvImageOperation.UnlockTransform;
|
|
|
|
|
begin
|
|
|
|
|
CS.Leave;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TovcImageOperationCanny }
|
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
|
procedure TovcImageOperation_Canny.AssignTo(Dest: TPersistent);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
|
if Dest is TovcImageOperation_Canny then
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
|
FThreshold1 := (Dest as TovcImageOperation_Canny).FThreshold1;
|
|
|
|
|
FThreshold2 := (Dest as TovcImageOperation_Canny).FThreshold2;
|
|
|
|
|
FApertureSize := (Dest as TovcImageOperation_Canny).FApertureSize;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
inherited;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TovcImageOperation_Canny.Create { (AOwner: TPersistent) };
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
FThreshold1 := 10;
|
|
|
|
|
FThreshold2 := 100;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
FApertureSize := 3;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TovcImageOperation_Canny.SetApertureSize(const Value: Integer);
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
FApertureSize := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TovcImageOperation_Canny.SetThreshold1(const Value: double);
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
FThreshold1 := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TovcImageOperation_Canny.SetThreshold2(const Value: double);
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
FThreshold2 := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TovcImageOperation_Canny.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
|
|
|
|
|
Var
|
|
|
|
|
gray: pIplImage;
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
// c<><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2013-12-02 19:39:13 +01:00
|
|
|
|
gray := cvCreateImage(cvGetSize(Source), IPL_DEPTH_8U, 1);
|
|
|
|
|
Destanation := cvCreateImage(cvGetSize(Source), IPL_DEPTH_8U, 1);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> c<><63><EFBFBD><EFBFBD><EFBFBD>
|
2013-12-02 19:39:13 +01:00
|
|
|
|
cvCvtColor(Source, gray, CV_RGB2GRAY);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2013-12-02 19:39:13 +01:00
|
|
|
|
cvCanny(gray, Destanation, Threshold1, Threshold2, ApertureSize);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
cvReleaseImage(gray);
|
|
|
|
|
Result := true;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TocvImageOperationGrayScale }
|
|
|
|
|
|
|
|
|
|
function TocvImageOperation_GrayScale.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
|
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
|
Destanation := cvCreateImage(cvGetSize(Source), IPL_DEPTH_8U, 1);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> c<><63><EFBFBD><EFBFBD><EFBFBD>
|
2013-12-02 19:39:13 +01:00
|
|
|
|
cvCvtColor(Source, Destanation, CV_RGB2GRAY);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
Result := true;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TocvImageOperationNone }
|
|
|
|
|
|
|
|
|
|
function TocvImageOperation_None.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
|
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
|
Destanation := cvCloneImage(Source);
|
|
|
|
|
Result := true;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TCustomOpenCVImgOperation }
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
constructor TocvCustomImageOperation.Create(AOwner: TComponent);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
FOwner := AOwner;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
CS := TCriticalSection.Create;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvCustomImageOperation.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
CS.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvCustomImageOperation.LockTransform;
|
|
|
|
|
begin
|
|
|
|
|
CS.Enter;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvCustomImageOperation.UnlockTransform;
|
|
|
|
|
begin
|
|
|
|
|
CS.Leave;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TovcImageOperationSmooth }
|
|
|
|
|
Const
|
2013-12-02 19:39:13 +01: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
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
|
procedure TovcImageOperation_Smooth.AssignTo(Dest: TPersistent);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
|
if Dest is TovcImageOperation_Smooth then
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
|
FSmoothOperation := (Dest as TovcImageOperation_Smooth).FSmoothOperation;
|
|
|
|
|
FSize1 := (Dest as TovcImageOperation_Smooth).FSize1;
|
|
|
|
|
FSize2 := (Dest as TovcImageOperation_Smooth).FSize2;
|
|
|
|
|
FSigma1 := (Dest as TovcImageOperation_Smooth).FSigma1;
|
|
|
|
|
FSigma2 := (Dest as TovcImageOperation_Smooth).FSigma2;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
inherited;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TovcImageOperation_Smooth.Create { (AOwner: TPersistent) };
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
FSmoothOperation := GAUSSIAN;
|
2013-12-02 19:39:13 +01:00
|
|
|
|
FSize1 := 3;
|
|
|
|
|
FSize2 := 3;
|
|
|
|
|
FSigma1 := 0;
|
|
|
|
|
FSigma2 := 0;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TovcImageOperation_Smooth.SetSigma1(const Value: double);
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
FSigma1 := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
procedure TovcImageOperation_Smooth.Setsigma2(const Value: double);
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
FSigma2 := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
procedure TovcImageOperation_Smooth.SetSize1(const Value: Integer);
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
FSize1 := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
procedure TovcImageOperation_Smooth.SetSize2(const Value: Integer);
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
FSize2 := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TovcImageOperation_Smooth.SetSmoothOperation(const Value: TocvSmoothOperations);
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
FSmoothOperation := Value;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TovcImageOperation_Smooth.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
|
|
|
|
|
begin
|
|
|
|
|
LockTransform;
|
|
|
|
|
try
|
|
|
|
|
Destanation := cvCloneImage(Source);
|
2013-12-02 19:39:13 +01:00
|
|
|
|
cvSmooth(Source, Destanation, ocvSmoothOperations[SmoothOperation], size1, size2, sigma1, sigma2);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
Result := true;
|
|
|
|
|
finally
|
|
|
|
|
UnlockTransform;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
{ TRegisteredImageOperations }
|
|
|
|
|
|
|
|
|
|
function TRegisteredImageOperations.FindByClassName(const ClassName: String): TocvImageOperationClass;
|
|
|
|
|
Var
|
|
|
|
|
i: Integer;
|
|
|
|
|
begin
|
|
|
|
|
i := IndexOf(ClassName);
|
|
|
|
|
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;
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
initialization
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvImageOperation_None, 'None');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TocvImageOperation_GrayScale, 'GrayScale');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TovcImageOperation_Canny, 'Canny');
|
|
|
|
|
GetRegisteredImageOperations.RegisterIOClass(TovcImageOperation_Smooth, 'Smooth');
|
|
|
|
|
|
|
|
|
|
finalization
|
|
|
|
|
|
|
|
|
|
if Assigned(_RegisteredImageOperations) then
|
|
|
|
|
FreeAndNil(_RegisteredImageOperations);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
|
|
end.
|