diff --git a/component/OpenCV.dpk b/component/OpenCV.dpk
index abdf041..af62af0 100644
--- a/component/OpenCV.dpk
+++ b/component/OpenCV.dpk
@@ -28,7 +28,7 @@ package OpenCV;
{$ALIGN 8}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
-{$DEBUGINFO ON}
+{$DEBUGINFO OFF}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
@@ -61,7 +61,6 @@ contains
uOCVView in 'uOCVView.pas',
uOCVImageOperation in 'uOCVImageOperation.pas',
uOCVRegister in 'uOCVRegister.pas',
- uOCVSplitter in 'uOCVSplitter.pas',
uOCVIOProperties in 'uOCVIOProperties.pas';
end.
diff --git a/component/OpenCV.dproj b/component/OpenCV.dproj
index 3b64f1f..8652bed 100644
--- a/component/OpenCV.dproj
+++ b/component/OpenCV.dproj
@@ -2,7 +2,7 @@
{67FAAD9E-2FAD-44C3-8F98-56827C3D1CE8}
OpenCV.dpk
- 15.3
+ 15.4
VCL
True
Debug
@@ -50,6 +50,7 @@
true
+ OpenCV
true
All
true
@@ -103,7 +104,6 @@
-
Cfg_2
diff --git a/component/uOCVCamera.pas b/component/uOCVCamera.pas
index 08de7fd..9c037dc 100644
--- a/component/uOCVCamera.pas
+++ b/component/uOCVCamera.pas
@@ -103,8 +103,7 @@ type
destructor Destroy; override;
published
property Enabled : Boolean Read FEnabled write SetEnabled default False;
- property CameraCaptureSource: TocvCameraCaptureSource read FCameraCaptureSource write SetCameraCaptureSource
- default CAP_ANY;
+ property CameraCaptureSource: TocvCameraCaptureSource read FCameraCaptureSource write SetCameraCaptureSource default CAP_ANY;
property Resolution: TocvResolution read FResolution write setResolution;
end;
diff --git a/component/uOCVIOProperties.pas b/component/uOCVIOProperties.pas
index 8deb9fd..cb0bcb3 100644
--- a/component/uOCVIOProperties.pas
+++ b/component/uOCVIOProperties.pas
@@ -39,32 +39,28 @@ Type
procedure SetValue(const Value: string); override;
end;
- TVideoSourceProperty = class(TInterfaceProperty)
- private
- FGetValuesStrProc: TGetStrProc;
- protected
- procedure ReceiveComponentNames(const S: string);
- public
- function GetAttributes: TPropertyAttributes; override;
- procedure GetValues(Proc: TGetStrProc); override;
- procedure SetValue(const Value: string); override;
- function GetValue: string; override;
- end;
+ // TVideoSourceProperty = class(TInterfaceProperty)
+ // private
+ // FGetValuesStrProc: TGetStrProc;
+ // protected
+ // procedure ReceiveComponentNames(const S: string);
+ // public
+ // function GetAttributes: TPropertyAttributes; override;
+ // procedure GetValues(Proc: TGetStrProc); override;
+ // procedure SetValue(const Value: string); override;
+ // function GetValue: string; override;
+ // end;
implementation
Uses
-
- VCL.Dialogs,
-
System.SysUtils,
System.TypInfo,
System.RTLConsts,
uOCVImageOperation,
- uOCVSplitter,
uOCVTypes;
-{ TImageOperationProperty }
+{TImageOperationProperty}
function TImageOperationProperty.GetAttributes: TPropertyAttributes;
begin
@@ -79,12 +75,12 @@ end;
procedure TImageOperationProperty.GetValues(Proc: TGetStrProc);
var
- i: Integer;
+ I: Integer;
rIO: TRegisteredImageOperations;
begin
rIO := GetRegisteredImageOperations;
- for i := 0 to rIO.Count - 1 do
- Proc(rIO[i]);
+ for I := 0 to rIO.Count - 1 do
+ Proc(rIO[I]);
end;
procedure TImageOperationProperty.SetValue(const Value: string);
@@ -93,102 +89,25 @@ Var
i: Integer;
AIntf: IocvEditorPropertiesContainer;
begin
- APropertiesClass := GetRegisteredImageOperations.FindByClassName(Value);
+ APropertiesClass := GetRegisteredImageOperations.FindByName(Value);
if APropertiesClass = nil then
APropertiesClass := TocvImageOperationClass(GetRegisteredImageOperations.Objects[0]);
+
for i := 0 to PropCount - 1 do
if Supports(GetComponent(i), IocvEditorPropertiesContainer, AIntf) then
AIntf.SetPropertiesClass(APropertiesClass);
+
Modified;
end;
-{ TVideoSourceProperty }
-
-function TVideoSourceProperty.GetAttributes: TPropertyAttributes;
-begin
- Result := inherited GetAttributes;
- Result := Result - [paReadOnly] + [paValueList, paSortList, paRevertable];
-end;
-
-function TVideoSourceProperty.GetValue: string;
-Var
- AInterface: IInterface;
- ICR: IocvDataSource;
-begin
- AInterface := GetIntfValue;
- if (AInterface <> nil) and Supports(AInterface, IocvDataSource, ICR) then
- Result := ICR.GetName
- else
- Result := '';
-end;
-
-procedure TVideoSourceProperty.GetValues(Proc: TGetStrProc);
-begin
- FGetValuesStrProc := Proc;
- try
- Designer.GetComponentNames(GetTypeData(TypeInfo(TComponent)), ReceiveComponentNames);
- finally
- FGetValuesStrProc := nil;
- end;
-end;
-
-procedure TVideoSourceProperty.ReceiveComponentNames(const S: string);
-var
- Temp: TComponent;
- Intf: IInterface;
- i: Integer;
-begin
- Temp := Designer.GetComponent(S);
- if Assigned(FGetValuesStrProc) and Assigned(Temp) then
- begin
- if Supports(TObject(Temp), GetTypeData(GetPropType)^.Guid, Intf) then
- FGetValuesStrProc(S);
- if not HasInstance(Temp) then
- if Temp is TocvSplitter then
- for i := 0 to (Temp as TocvSplitter).Channels.Count - 1 do
- FGetValuesStrProc(S + '[' + i.ToString + ']');
- end;
-end;
-
-procedure TVideoSourceProperty.SetValue(const Value: string);
-var
- Intf: IInterface;
- Component: TComponent;
- CompName: string;
- n1, n2, ChanIndex: Integer;
- SpComp: TocvSplitter;
-begin
- if Value = '' then
- Intf := nil
- else
- begin
- if Pos('[', Value) <> 0 then
- begin
- CompName := Copy(Value, 1, Pos('[', Value) - 1);
- n1 := Pos('[', Value);
- n2 := Pos(']', Value);
- ChanIndex := Copy(Value, n1 + 1, n2 - n1 - 1).ToInteger;
- SpComp := Designer.GetComponent(CompName) as TocvSplitter;
- if Assigned(SpComp) and (ChanIndex < SpComp.Channels.Count) then
- Intf := SpComp.Channels[ChanIndex]
- else
- raise EDesignPropertyError.CreateRes(@SInvalidPropertyValue);
- end
- else
- begin
- Component := Designer.GetComponent(Value);
- if (Component = nil) or (not Supports(TObject(Component), GetTypeData(GetPropType)^.Guid, Intf)) then
- raise EDesignPropertyError.CreateRes(@SInvalidPropertyValue);
- end;
- end;
- SetIntfValue(Intf);
-end;
-
initialization
-RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvImageOperation, 'Properties', TImageOperationProperty);
-RegisterPropertyEditor(TypeInfo(string), TocvImageOperation, 'PropertiesClassName', nil);
+//RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), nil, 'Operation', TImageOperationProperty);
+//UnlistPublishedProperty(nil, 'OperationClassName');
-RegisterPropertyEditor(TypeInfo(IocvDataSource), nil, 'VideoSource', TVideoSourceProperty);
+RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvImageOperation, 'Operation', TImageOperationProperty);
+RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvImageOperationCollectionItem, 'Operation', TImageOperationProperty);
+UnlistPublishedProperty(TocvImageOperation, 'OperationClassName');
+UnlistPublishedProperty(TocvImageOperationCollectionItem, 'OperationClassName');
end.
diff --git a/component/uOCVImageOperation.pas b/component/uOCVImageOperation.pas
index 33469b6..11d1cdb 100644
--- a/component/uOCVImageOperation.pas
+++ b/component/uOCVImageOperation.pas
@@ -39,7 +39,7 @@ type
CS: TCriticalSection;
FOwner: TComponent;
protected
- procedure LockTransform;
+ function LockTransform: Boolean;
procedure UnlockTransform;
public
constructor Create(AOwner: TComponent); virtual;
@@ -79,6 +79,70 @@ type
property ApertureSize: Integer Read FApertureSize write SetApertureSize default 100;
end;
+ TocvErodeDilateMode = (SHAPE_RECT, SHAPE_CROSS, SHAPE_ELLIPSE, SHAPE_CUSTOM);
+
+ TovcCustomErodeDilate = class(TocvCustomImageOperation)
+ protected
+ procedure AssignTo(Dest: TPersistent); override;
+ private
+ FRadius: Integer;
+ FIterations: Integer;
+ FMorphOp: TocvErodeDilateMode;
+ procedure SetRadius(const Value: Integer);
+ procedure SetIterations(const Value: Integer);
+ procedure SetMorphOp(const Value: TocvErodeDilateMode);
+ protected
+ public
+ constructor Create(AOwner: TComponent); override;
+ published
+ property Radius: Integer Read FRadius write SetRadius default 5;
+ property Iterations: Integer Read FIterations write SetIterations default 5;
+ property MorphOp: TocvErodeDilateMode read FMorphOp write SetMorphOp default SHAPE_RECT;
+ end;
+
+ TovcErode = class(TovcCustomErodeDilate)
+ public
+ function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; override;
+ end;
+
+ TovcDilate = class(TovcCustomErodeDilate)
+ public
+ function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; override;
+ end;
+
+ TocvLaplace = class(TocvCustomImageOperation)
+ protected
+ procedure AssignTo(Dest: TPersistent); override;
+ private
+ FAperture: Integer;
+ procedure SetAperture(const Value: Integer);
+ public
+ constructor Create(AOwner: TComponent); override;
+ function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; override;
+ published
+ property Aperture: Integer read FAperture write SetAperture default 3;
+ end;
+
+ TovcSobel = class(TocvCustomImageOperation)
+ protected
+ procedure AssignTo(Dest: TPersistent); override;
+ private
+ FXOrder: Integer;
+ FYOrder: Integer;
+ FAperture: Integer;
+ procedure SetAperture(const Value: Integer);
+ procedure SetXOrder(const Value: Integer);
+ procedure SetYOrder(const Value: Integer);
+ protected
+ public
+ constructor Create(AOwner: TComponent); override;
+ function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; override;
+ published
+ property XOrder: Integer read FXOrder write SetXOrder default 1;
+ property YOrder: Integer read FYOrder write SetYOrder default 1;
+ property Aperture: Integer read FAperture write SetAperture default 3;
+ end;
+
TocvSmoothOperations = (BLUR_NO_SCALE, BLUR, GAUSSIAN, MEDIAN, BILATERAL);
TovcImageOperation_Smooth = class(TocvCustomImageOperation)
@@ -113,12 +177,49 @@ type
procedure SetPropertiesClass(Value: TocvImageOperationClass);
end;
+ TocvImageOperationCollectionItem = class(TCollectionItem, IocvEditorPropertiesContainer)
+ private
+ CS: TCriticalSection;
+ FOperation: TocvCustomImageOperation;
+ FOperationClass: TocvImageOperationClass;
+ 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
+ function GetProperties: TocvCustomImageOperation;
+ function GetPropertiesClass: TocvImageOperationClass;
+ // function GetOwner: TComponent;
+ function GetDisplayName: string; override;
+ {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;
+ function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
+ procedure Assign(Source: TPersistent); override;
+ property OperationClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
+ published
+ property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
+ property Operation: TocvCustomImageOperation read GetProperties write SetProperties;
+ end;
+
+ TocvImageOperationCollection = class(TOwnedCollection);
+
TocvImageOperation = class(TocvDataSourceAndReceiver, IocvEditorPropertiesContainer)
private
CS: TCriticalSection;
- FProperties: TocvCustomImageOperation;
- FPropertiesClass: TocvImageOperationClass;
- procedure LockTransform;
+ FOperation: TocvCustomImageOperation;
+ FOperationClass: TocvImageOperationClass;
+ FOperations: TocvImageOperationCollection;
+ function LockTransform: Boolean;
procedure UnlockTransform;
procedure CreateProperties;
procedure DestroyProperties;
@@ -134,15 +235,17 @@ type
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
- property PropertiesClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
+ property OperationClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
published
- property PropertiesClassName: string read GetPropertiesClassName write SetPropertiesClassName;
- property Properties: TocvCustomImageOperation read GetProperties write SetProperties;
+ property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
+ property Operation: TocvCustomImageOperation read GetProperties write SetProperties;
+ property Operations: TocvImageOperationCollection Read FOperations write FOperations;
end;
TRegisteredImageOperations = class(TStringList)
public
function FindByClassName(const ClassName: String): TocvImageOperationClass;
+ function FindByName(const Name: String): TocvImageOperationClass;
function GetNameByClass(const IOClass: TClass): String;
procedure RegisterIOClass(const IOClass: TClass; const ClassName: String);
end;
@@ -166,32 +269,32 @@ begin
Result := _RegisteredImageOperations;
end;
-{ TocvImageOperation }
+{TocvImageOperation}
procedure TocvImageOperation.SetProperties(const Value: TocvCustomImageOperation);
begin
- if (FProperties <> nil) and (Value <> nil) then
- FProperties.Assign(Value);
+ if (FOperation <> nil) and (Value <> nil) then
+ FOperation.Assign(Value);
end;
procedure TocvImageOperation.SetPropertiesClass(Value: TocvImageOperationClass);
begin
- if FPropertiesClass <> Value then
+ if FOperationClass <> Value then
begin
- FPropertiesClass := Value;
+ FOperationClass := Value;
RecreateProperties;
end;
end;
procedure TocvImageOperation.CreateProperties;
begin
- if FPropertiesClass <> nil then
- FProperties := FPropertiesClass.Create(Self);
+ if FOperationClass <> nil then
+ FOperation := FOperationClass.Create(Self);
end;
procedure TocvImageOperation.DestroyProperties;
begin
- FreeAndNil(FProperties);
+ FreeAndNil(FOperation);
end;
procedure TocvImageOperation.RecreateProperties;
@@ -202,59 +305,74 @@ end;
procedure TocvImageOperation.SetPropertiesClassName(const Value: string);
begin
- PropertiesClass := TocvImageOperationClass(GetRegisteredImageOperations.FindByClassName(Value));
+ OperationClass := TocvImageOperationClass(GetRegisteredImageOperations.FindByClassName(Value));
end;
constructor TocvImageOperation.Create(AOwner: TComponent);
begin
inherited;
CS := TCriticalSection.Create;
+ FOperations := TocvImageOperationCollection.Create(Self, TocvImageOperationCollectionItem);
end;
destructor TocvImageOperation.Destroy;
begin
- LockTransform;
- if Assigned(FProperties) then
- FreeAndNil(FProperties);
+ if LockTransform then
+ if Assigned(FOperation) then
+ FreeAndNil(FOperation);
+ FOperations.Free;
CS.Free;
inherited;
end;
function TocvImageOperation.GetProperties: TocvCustomImageOperation;
begin
- if not Assigned(FProperties) then
- FProperties := TocvImageOperation_None.Create(Self);
- Result := FProperties;
+ if not Assigned(FOperation) then
+ FOperation := TocvImageOperation_None.Create(Self);
+ Result := FOperation;
end;
function TocvImageOperation.GetPropertiesClass: TocvImageOperationClass;
begin
- Result := TocvImageOperationClass(Properties.ClassType);
+ Result := TocvImageOperationClass(Operation.ClassType);
end;
function TocvImageOperation.GetPropertiesClassName: string;
begin
- Result := Properties.ClassName;
+ Result := Operation.ClassName;
end;
-procedure TocvImageOperation.LockTransform;
+function TocvImageOperation.LockTransform: Boolean;
begin
- CS.Enter;
+ Result := CS.TryEnter;
end;
procedure TocvImageOperation.TakeImage(const IplImage: pIplImage);
var
Destanation: pIplImage;
+ SourceDestanation: pIplImage;
+ i: Integer;
begin
- if Assigned(FProperties) and FProperties.Transform(IplImage, Destanation) then
- begin
- LockTransform;
+ if LockTransform then
try
- NotifyReceiver(Destanation);
+ if FOperations.Count > 0 then
+ begin
+ SourceDestanation := IplImage;
+ for i := 0 to FOperations.Count - 1 do
+ begin
+ if not(FOperations.Items[i] as TocvImageOperationCollectionItem).Transform(SourceDestanation, Destanation) then
+ Exit;
+ if SourceDestanation <> IplImage then
+ cvReleaseImage(SourceDestanation);
+ SourceDestanation := Destanation;
+ end;
+ NotifyReceiver(SourceDestanation);
+ end
+ else if Assigned(FOperation) and FOperation.Transform(IplImage, Destanation) then
+ NotifyReceiver(Destanation);
finally
UnlockTransform;
end;
- end;
end;
procedure TocvImageOperation.UnlockTransform;
@@ -262,7 +380,7 @@ begin
CS.Leave;
end;
-{ TovcImageOperationCanny }
+{TovcImageOperationCanny}
procedure TovcImageOperation_Canny.AssignTo(Dest: TPersistent);
begin
@@ -276,7 +394,7 @@ begin
inherited;
end;
-constructor TovcImageOperation_Canny.Create { (AOwner: TPersistent) };
+constructor TovcImageOperation_Canny.Create {(AOwner: TPersistent)};
begin
inherited;
FThreshold1 := 10;
@@ -286,73 +404,86 @@ end;
procedure TovcImageOperation_Canny.SetApertureSize(const Value: Integer);
begin
- LockTransform;
- try
- FApertureSize := Value;
- finally
- UnlockTransform;
- end;
+ if LockTransform then
+ try
+ FApertureSize := Value;
+ finally
+ UnlockTransform;
+ end;
end;
procedure TovcImageOperation_Canny.SetThreshold1(const Value: double);
begin
- LockTransform;
- try
- FThreshold1 := Value;
- finally
- UnlockTransform;
- end;
+ if LockTransform then
+ try
+ FThreshold1 := Value;
+ finally
+ UnlockTransform;
+ end;
end;
procedure TovcImageOperation_Canny.SetThreshold2(const Value: double);
begin
- LockTransform;
- try
- FThreshold2 := Value;
- finally
- UnlockTransform;
- end;
+ if LockTransform then
+ 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оздаём одноканальные картинки
- gray := cvCreateImage(cvGetSize(Source), IPL_DEPTH_8U, 1);
- Destanation := cvCreateImage(cvGetSize(Source), IPL_DEPTH_8U, 1);
- // преобразуем в градации cерого
- cvCvtColor(Source, gray, CV_RGB2GRAY);
- // получаем границы
- cvCanny(gray, Destanation, Threshold1, Threshold2, ApertureSize);
- cvReleaseImage(gray);
- Result := true;
- finally
- UnlockTransform;
- end;
+ Result := False;
+ if LockTransform then
+ try
+ // cоздаём одноканальные картинки
+ gray := cvCreateImage(cvGetSize(Source), IPL_DEPTH_8U, 1);
+ Destanation := cvCreateImage(cvGetSize(Source), IPL_DEPTH_8U, 1);
+ // преобразуем в градации cерого
+ cvCvtColor(Source, gray, CV_RGB2GRAY);
+ // получаем границы
+ cvCanny(gray, Destanation, Threshold1, Threshold2, ApertureSize);
+ cvReleaseImage(gray);
+ Result := true;
+ finally
+ UnlockTransform;
+ end;
end;
-{ TocvImageOperationGrayScale }
+{TocvImageOperationGrayScale}
function TocvImageOperation_GrayScale.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
begin
- Destanation := cvCreateImage(cvGetSize(Source), IPL_DEPTH_8U, 1);
- // преобразуем в градации cерого
- cvCvtColor(Source, Destanation, CV_RGB2GRAY);
- Result := true;
+ Result := False;
+ if LockTransform then
+ try
+ Destanation := cvCreateImage(cvGetSize(Source), IPL_DEPTH_8U, 1);
+ // преобразуем в градации cерого
+ cvCvtColor(Source, Destanation, CV_RGB2GRAY);
+ Result := true;
+ finally
+ UnlockTransform;
+ end;
end;
-{ TocvImageOperationNone }
+{TocvImageOperationNone}
function TocvImageOperation_None.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
begin
- Destanation := cvCloneImage(Source);
- Result := true;
+ Result := False;
+ if LockTransform then
+ try
+ Destanation := cvCloneImage(Source);
+ Result := true;
+ finally
+ UnlockTransform;
+ end;
end;
-{ TCustomOpenCVImgOperation }
+{TCustomOpenCVImgOperation}
constructor TocvCustomImageOperation.Create(AOwner: TComponent);
begin
@@ -367,9 +498,9 @@ begin
inherited;
end;
-procedure TocvCustomImageOperation.LockTransform;
+function TocvCustomImageOperation.LockTransform: Boolean;
begin
- CS.Enter;
+ Result := CS.TryEnter;
end;
procedure TocvCustomImageOperation.UnlockTransform;
@@ -377,9 +508,10 @@ begin
CS.Leave;
end;
-{ TovcImageOperationSmooth }
+{TovcImageOperationSmooth}
Const
- ocvSmoothOperations: array [TocvSmoothOperations] of Integer = (CV_BLUR_NO_SCALE, CV_BLUR, CV_GAUSSIAN, CV_MEDIAN, CV_BILATERAL);
+ ocvSmoothOperations: array [TocvSmoothOperations] of Integer = (CV_BLUR_NO_SCALE, CV_BLUR, CV_GAUSSIAN, CV_MEDIAN,
+ CV_BILATERAL);
procedure TovcImageOperation_Smooth.AssignTo(Dest: TPersistent);
begin
@@ -395,7 +527,7 @@ begin
inherited;
end;
-constructor TovcImageOperation_Smooth.Create { (AOwner: TPersistent) };
+constructor TovcImageOperation_Smooth.Create {(AOwner: TPersistent)};
begin
inherited;
FSmoothOperation := GAUSSIAN;
@@ -407,76 +539,86 @@ end;
procedure TovcImageOperation_Smooth.SetSigma1(const Value: double);
begin
- LockTransform;
- try
- FSigma1 := Value;
- finally
- UnlockTransform;
- end;
+ if LockTransform then
+ try
+ FSigma1 := Value;
+ finally
+ UnlockTransform;
+ end;
end;
//
procedure TovcImageOperation_Smooth.Setsigma2(const Value: double);
begin
- LockTransform;
- try
- FSigma2 := Value;
- finally
- UnlockTransform;
- end;
+ if LockTransform then
+ try
+ FSigma2 := Value;
+ finally
+ UnlockTransform;
+ end;
end;
//
procedure TovcImageOperation_Smooth.SetSize1(const Value: Integer);
begin
- LockTransform;
- try
- FSize1 := Value;
- finally
- UnlockTransform;
- end;
+ if LockTransform then
+ try
+ FSize1 := Value;
+ finally
+ UnlockTransform;
+ end;
end;
//
procedure TovcImageOperation_Smooth.SetSize2(const Value: Integer);
begin
- LockTransform;
- try
- FSize2 := Value;
- finally
- UnlockTransform;
- end;
+ if LockTransform then
+ try
+ FSize2 := Value;
+ finally
+ UnlockTransform;
+ end;
end;
procedure TovcImageOperation_Smooth.SetSmoothOperation(const Value: TocvSmoothOperations);
begin
- LockTransform;
- try
- FSmoothOperation := Value;
- finally
- UnlockTransform;
- end;
+ if LockTransform then
+ try
+ FSmoothOperation := Value;
+ finally
+ UnlockTransform;
+ end;
end;
function TovcImageOperation_Smooth.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
begin
- LockTransform;
- try
- Destanation := cvCloneImage(Source);
- cvSmooth(Source, Destanation, ocvSmoothOperations[SmoothOperation], size1, size2, sigma1, sigma2);
- Result := true;
- finally
- UnlockTransform;
- end;
+ Result := False;
+ if LockTransform then
+ try
+ Destanation := cvCloneImage(Source);
+ cvSmooth(Source, Destanation, ocvSmoothOperations[SmoothOperation], size1, size2, sigma1, sigma2);
+ Result := true;
+ finally
+ UnlockTransform;
+ end;
end;
-{ TRegisteredImageOperations }
+{TRegisteredImageOperations}
function TRegisteredImageOperations.FindByClassName(const ClassName: String): TocvImageOperationClass;
Var
i: Integer;
begin
- i := IndexOf(ClassName);
+ 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);
if i <> -1 then
Result := TocvImageOperationClass(Objects[i])
else
@@ -502,12 +644,350 @@ begin
RegisterClass(TPersistentClass(IOClass));
end;
+{TovcCustomErodeDilate}
+
+procedure TovcCustomErodeDilate.AssignTo(Dest: TPersistent);
+begin
+ if Dest is TovcCustomErodeDilate then
+ begin
+ FRadius := (Dest as TovcCustomErodeDilate).Radius;
+ FIterations := (Dest as TovcCustomErodeDilate).Iterations;
+ FMorphOp := (Dest as TovcCustomErodeDilate).MorphOp;
+ end
+ else
+ inherited;
+end;
+
+constructor TovcCustomErodeDilate.Create(AOwner: TComponent);
+begin
+ inherited;
+ FRadius := 5;
+ FIterations := 5;
+end;
+
+procedure TovcCustomErodeDilate.SetIterations(const Value: Integer);
+begin
+ if LockTransform then
+ try
+ FIterations := Value;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+procedure TovcCustomErodeDilate.SetMorphOp(const Value: TocvErodeDilateMode);
+begin
+ if LockTransform then
+ try
+ FMorphOp := Value;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+procedure TovcCustomErodeDilate.SetRadius(const Value: Integer);
+begin
+ if LockTransform then
+ try
+ FRadius := Value;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+const
+ EDMorpgOp: array [TocvErodeDilateMode] of Integer = (CV_SHAPE_RECT, CV_SHAPE_CROSS, CV_SHAPE_ELLIPSE, CV_SHAPE_CUSTOM);
+
+ {TovcErode}
+
+function TovcErode.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
+Var
+ Kern: pIplConvKernel;
+begin
+ Result := False;
+ if LockTransform then
+ try
+ Destanation := cvCloneImage(Source);
+ Kern := cvCreateStructuringElementEx(Radius * 2 + 1, Radius * 2 + 1, Radius, Radius, EDMorpgOp[FMorphOp]);
+ cvErode(Source, Destanation, Kern, Iterations);
+ cvReleaseStructuringElement(Kern);
+ Result := true;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+{TovcDilate}
+
+function TovcDilate.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
+Var
+ Kern: pIplConvKernel;
+begin
+ Result := False;
+ if LockTransform then
+ try
+ Destanation := cvCloneImage(Source);
+ Kern := cvCreateStructuringElementEx(Radius * 2 + 1, Radius * 2 + 1, Radius, Radius, EDMorpgOp[FMorphOp]);
+ cvDilate(Source, Destanation, Kern, Iterations);
+ cvReleaseStructuringElement(Kern);
+ Result := true;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+{TocvLaplace}
+
+procedure TocvLaplace.AssignTo(Dest: TPersistent);
+begin
+ if Dest is TocvLaplace then
+ begin
+ FAperture := (Dest as TocvLaplace).Aperture;
+ end
+ else
+ inherited;
+end;
+
+constructor TocvLaplace.Create(AOwner: TComponent);
+begin
+ inherited;
+ FAperture := 3;
+end;
+
+procedure TocvLaplace.SetAperture(const Value: Integer);
+begin
+ if LockTransform then
+ try
+ FAperture := Value;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+function TocvLaplace.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
+Var
+ D: pIplImage;
+begin
+ Result := False;
+ if LockTransform then
+ try
+ D := cvCreateImage(cvGetSize(Source), IPL_DEPTH_16S, Source^.nChannels);
+ Destanation := cvCreateImage(cvGetSize(Source), Source^.depth, Source^.nChannels);
+ cvLaplace(Source, D, Aperture);
+ cvConvertScale(D, Destanation);
+ cvReleaseImage(D);
+ Result := true;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+{TovcSobel}
+
+procedure TovcSobel.AssignTo(Dest: TPersistent);
+begin
+ if Dest is TovcSobel then
+ begin
+ FXOrder := (Dest as TovcSobel).XOrder;
+ FYOrder := (Dest as TovcSobel).YOrder;
+ FAperture := (Dest as TovcSobel).Aperture;
+ end
+ else
+ inherited;
+end;
+
+constructor TovcSobel.Create(AOwner: TComponent);
+begin
+ inherited;
+ FXOrder := 1;
+ FYOrder := 1;
+ FAperture := 3;
+end;
+
+procedure TovcSobel.SetAperture(const Value: Integer);
+begin
+ if LockTransform then
+ try
+ FAperture := Value;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+procedure TovcSobel.SetXOrder(const Value: Integer);
+begin
+ if LockTransform then
+ try
+ if (YOrder <> 0) and (Value <> 0) then
+ FXOrder := Value;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+procedure TovcSobel.SetYOrder(const Value: Integer);
+begin
+ if LockTransform then
+ try
+ if (XOrder <> 0) and (Value <> 0) then
+ FYOrder := Value;
+ finally
+ UnlockTransform;
+ end;
+end;
+
+function TovcSobel.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
+Var
+ D: pIplImage;
+begin
+ Result := False;
+ if LockTransform then
+ try
+ D := cvCreateImage(cvGetSize(Source), IPL_DEPTH_16S, Source^.nChannels);
+ Destanation := cvCreateImage(cvGetSize(Source), Source^.depth, Source^.nChannels);
+ cvSobel(Source, D, XOrder, YOrder, Aperture);
+ cvConvertScale(D, Destanation);
+ cvReleaseImage(D);
+ Result := true;
+ finally
+ UnlockTransform;
+ end;
+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;
+ CS := TCriticalSection.Create;
+end;
+
+procedure TocvImageOperationCollectionItem.CreateProperties;
+begin
+ if FOperationClass <> nil then
+ FOperation := FOperationClass.Create(nil);
+end;
+
+destructor TocvImageOperationCollectionItem.Destroy;
+begin
+ CS.Free;
+ inherited;
+end;
+
+procedure TocvImageOperationCollectionItem.DestroyProperties;
+begin
+ FreeAndNil(FOperation);
+end;
+
+function TocvImageOperationCollectionItem.GetDisplayName: string;
+begin
+ Result := GetRegisteredImageOperations.GetNameByClass(FOperation.ClassType);
+end;
+
+// function TocvImageOperationCollectionItem.GetOwner: TComponent;
+// begin
+// Result := (Collection as TOwnedCollection).Owner as TComponent;
+// end;
+
+function TocvImageOperationCollectionItem.GetProperties: TocvCustomImageOperation;
+begin
+ if not Assigned(FOperation) then
+ FOperation := TocvImageOperation_None.Create(nil);
+ 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;
+
+function TocvImageOperationCollectionItem.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
+begin
+ if LockTransform then
+ try
+ Result := Assigned(FOperation) and FOperation.Transform(Source, Destanation)
+ 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;
+
initialization
GetRegisteredImageOperations.RegisterIOClass(TocvImageOperation_None, 'None');
GetRegisteredImageOperations.RegisterIOClass(TocvImageOperation_GrayScale, 'GrayScale');
GetRegisteredImageOperations.RegisterIOClass(TovcImageOperation_Canny, 'Canny');
GetRegisteredImageOperations.RegisterIOClass(TovcImageOperation_Smooth, 'Smooth');
+GetRegisteredImageOperations.RegisterIOClass(TovcErode, 'Erode');
+GetRegisteredImageOperations.RegisterIOClass(TovcDilate, 'Dilate');
+GetRegisteredImageOperations.RegisterIOClass(TocvLaplace, 'Laplace');
+GetRegisteredImageOperations.RegisterIOClass(TovcSobel, 'Sobel');
finalization
diff --git a/component/uOCVRegister.pas b/component/uOCVRegister.pas
index 7d08fbe..959f9ac 100644
--- a/component/uOCVRegister.pas
+++ b/component/uOCVRegister.pas
@@ -33,8 +33,7 @@ Uses
System.Classes,
uOCVCamera,
uOCVView,
- uOCVImageOperation,
- uOCVSplitter;
+ uOCVImageOperation;
procedure Register;
begin
@@ -42,9 +41,7 @@ begin
RegisterComponents('OpenCV', [TocvCamera]);
RegisterComponents('OpenCV', [TocvCamera]);
RegisterComponents('OpenCV', [TocvView]);
- RegisterComponents('OpenCV', [TocvSplitter]);
- RegisterClasses([TocvImageOperation_None, TocvImageOperation_GrayScale, TovcImageOperation_Canny, TovcImageOperation_Smooth,
- TocvChannel]);
+ RegisterClasses([TocvImageOperation_None, TocvImageOperation_GrayScale, TovcImageOperation_Canny, TovcImageOperation_Smooth]);
end;
end.
diff --git a/component/uOCVSplitter.pas b/component/uOCVSplitter.pas
deleted file mode 100644
index 8371265..0000000
--- a/component/uOCVSplitter.pas
+++ /dev/null
@@ -1,188 +0,0 @@
-// *****************************************************************
-// 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 uOCVSplitter;
-
-interface
-
-Uses
- System.Classes,
- core.types_c,
- uOCVTypes;
-
-Type
- TocvChannel = class(TCollectionItem, IocvDataSource)
- private
- FOpenCVVideoReceiver: IocvDataReceiver;
- FVCLComObject: Pointer;
- FDataReceiver: TocvDataReceiver;
- FName: String;
- protected
- procedure SetReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
- procedure NotifyReceiver(const IplImage: pIplImage);
- { IInterface }
- function QueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
- function _AddRef: Integer; stdcall;
- function _Release: Integer; stdcall;
- function GetName: string;
- published
- constructor Create(Collection: TCollection); override;
- property Name: String read GetName write FName;
- end;
-
- TocvChannelCollection = class(TCollection)
- private
- FOwner: TComponent;
- function GetOCVItem(Index: Integer): IocvDataSource;
- public
- constructor Create(const AOwner: TComponent; const ItemClass: TCollectionItemClass);
- property OCVChannel[Index: Integer]: IocvDataSource read GetOCVItem; default;
- end;
-
- TocvSplitter = class(TocvDataReceiver)
- private
- FChannels: TocvChannelCollection;
- FocvVideoSource: IocvDataSource;
- procedure SetOpenCVVideoSource(const Value: IocvDataSource);
- procedure SetChannels(const Value: TocvChannelCollection);
- protected
- procedure TakeImage(const IplImage: pIplImage); override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property VideoSource: IocvDataSource Read FocvVideoSource write SetOpenCVVideoSource;
- property Channels: TocvChannelCollection read FChannels write SetChannels;
- end;
-
-implementation
-
-Uses System.SysUtils;
-
-{ TocvSplitter }
-
-constructor TocvSplitter.Create(AOwner: TComponent);
-begin
- inherited;
- FChannels := TocvChannelCollection.Create(Self, TocvChannel);
-end;
-
-destructor TocvSplitter.Destroy;
-begin
- FChannels.Free;
- inherited;
-end;
-
-procedure TocvSplitter.SetChannels(const Value: TocvChannelCollection);
-begin
- FChannels.Assign(Value);
-end;
-
-procedure TocvSplitter.SetOpenCVVideoSource(const Value: IocvDataSource);
-begin
- if FocvVideoSource <> Value then
- begin
- if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(nil);
- FocvVideoSource := Value;
- if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(Self);
- end;
-end;
-
-procedure TocvSplitter.TakeImage(const IplImage: pIplImage);
-var
- OCVChannel: TCollectionItem;
-begin
- for OCVChannel in FChannels do
- (OCVChannel as TocvChannel).NotifyReceiver(IplImage);
-end;
-
-{ TocvChannel }
-
-constructor TocvChannel.Create(Collection: TCollection);
-begin
- inherited;
- Name;
-end;
-
-function TocvChannel.GetName: string;
-begin
- if Length(Trim(FName)) = 0 then
- FName := (Collection as TocvChannelCollection).FOwner.Name + '[' + ID.ToString + ']';
- Result := FName;
-end;
-
-procedure TocvChannel.NotifyReceiver(const IplImage: pIplImage);
-begin
- if Assigned(FOpenCVVideoReceiver) then
- FOpenCVVideoReceiver.TakeImage(IplImage);
-end;
-
-function TocvChannel.QueryInterface(const IID: TGUID; out Obj): HResult;
-begin
- if FVCLComObject = nil then
- begin
- if GetInterface(IID, Obj) then
- Result := S_OK
- else
- Result := E_NOINTERFACE
- end
- else
- Result := IVCLComObject(FVCLComObject).QueryInterface(IID, Obj);
-end;
-
-procedure TocvChannel.SetReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
-begin
- FOpenCVVideoReceiver := OpenCVVideoReceiver;
-end;
-
-function TocvChannel._AddRef: Integer;
-begin
- if FVCLComObject = nil then
- Result := -1 // -1 indicates no reference counting is taking place
- else
- Result := IVCLComObject(FVCLComObject)._AddRef;
-end;
-
-function TocvChannel._Release: Integer;
-begin
- if FVCLComObject = nil then
- Result := -1 // -1 indicates no reference counting is taking place
- else
- Result := IVCLComObject(FVCLComObject)._Release;
-end;
-
-{ TocvChannelCollection }
-
-constructor TocvChannelCollection.Create(const AOwner: TComponent; const ItemClass: TCollectionItemClass);
-begin
- inherited Create(ItemClass);
- FOwner := AOwner;
-end;
-
-function TocvChannelCollection.GetOCVItem(Index: Integer): IocvDataSource;
-begin
- Result := TocvChannel(inherited GetItem(Index));
-end;
-
-end.
diff --git a/component/uOCVTypes.pas b/component/uOCVTypes.pas
index 67f5d7e..5db4ff6 100644
--- a/component/uOCVTypes.pas
+++ b/component/uOCVTypes.pas
@@ -28,7 +28,7 @@ interface
Uses
System.SysUtils,
System.Classes,
- System.SyncObjs,
+ // System.SyncObjs,
System.Generics.Collections,
core.types_c;
@@ -41,23 +41,25 @@ Type
IocvDataSource = interface
['{80640C0A-6828-42F8-83E7-DA5FD9036DFF}']
- procedure SetReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
+ procedure AddReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
+ procedure RemoveReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
function GetName: string;
end;
- TocvReceiverList = TList;
+ TocvReceiverList = TThreadList;
TocvDataSource = class(TComponent, IocvDataSource)
private
- ReceiverCS: TCriticalSection;
+ // FReceiverCS: TCriticalSection;
protected
- FOpenCVVideoReceiver: IocvDataReceiver;
- procedure NotifyReceiver(const IplImage: pIplImage); virtual;
+ FOpenCVVideoReceivers: TocvReceiverList;
function GetName: string; virtual;
+ procedure NotifyReceiver(const IplImage: pIplImage); virtual;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
- procedure SetReceiver(const OpenCVVideoReceiver: IocvDataReceiver); virtual;
+ procedure AddReceiver(const OpenCVVideoReceiver: IocvDataReceiver); virtual;
+ procedure RemoveReceiver(const OpenCVVideoReceiver: IocvDataReceiver); virtual;
end;
TocvDataReceiver = class(TComponent, IocvDataReceiver)
@@ -88,27 +90,22 @@ Type
implementation
-{ TOpenCVDataSource }
+{TOpenCVDataSource}
-procedure TocvDataSource.SetReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
+procedure TocvDataSource.AddReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
begin
- ReceiverCS.Enter;
- try
- FOpenCVVideoReceiver := OpenCVVideoReceiver;
- finally
- ReceiverCS.Leave;
- end;
+ FOpenCVVideoReceivers.Add(OpenCVVideoReceiver);
end;
constructor TocvDataSource.Create(AOwner: TComponent);
begin
inherited;
- ReceiverCS := TCriticalSection.Create;
+ FOpenCVVideoReceivers := TocvReceiverList.Create;
end;
destructor TocvDataSource.Destroy;
begin
- ReceiverCS.Free;
+ FOpenCVVideoReceivers.Free;
inherited;
end;
@@ -118,17 +115,30 @@ begin
end;
procedure TocvDataSource.NotifyReceiver(const IplImage: pIplImage);
+Var
+ R: IocvDataReceiver;
+ LockList: TList;
begin
- if Assigned(FOpenCVVideoReceiver) then
- FOpenCVVideoReceiver.TakeImage(IplImage);
+ LockList := FOpenCVVideoReceivers.LockList;
+ try
+ for R in LockList do
+ R.TakeImage(IplImage);
+ finally
+ FOpenCVVideoReceivers.UnlockList;
+ end;
end;
-{ TOpenCVDataSourceAndReceiver }
+procedure TocvDataSource.RemoveReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
+begin
+ FOpenCVVideoReceivers.Remove(OpenCVVideoReceiver);
+end;
+
+{TOpenCVDataSourceAndReceiver}
destructor TocvDataSourceAndReceiver.Destroy;
begin
if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(nil);
+ FocvVideoSource.RemoveReceiver(Self);
inherited;
end;
@@ -137,10 +147,10 @@ begin
if (FocvVideoSource <> Value) then
begin
if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(nil);
+ FocvVideoSource.RemoveReceiver(Self);
FocvVideoSource := Value;
if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(Self);
+ FocvVideoSource.AddReceiver(Self);
end;
end;
@@ -154,12 +164,12 @@ begin
end;
-{ TocvDataReceiver }
+{TocvDataReceiver}
destructor TocvDataReceiver.Destroy;
begin
if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(nil);
+ FocvVideoSource.RemoveReceiver(Self);
inherited;
end;
@@ -168,16 +178,17 @@ begin
if (FocvVideoSource <> Value) then
begin
if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(nil);
+ FocvVideoSource.RemoveReceiver(Self);
FocvVideoSource := Value;
if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(Self);
+ FocvVideoSource.AddReceiver(Self);
end;
end;
procedure TocvDataReceiver.SetVideoSource(const Value: TObject);
begin
- VideoSource := Value as TocvDataSource;
+ if (Value <> Self) then
+ VideoSource := Value as TocvDataSource;
end;
procedure TocvDataReceiver.TakeImage(const IplImage: pIplImage);
diff --git a/component/uOCVView.pas b/component/uOCVView.pas
index 319e7ef..85e6d12 100644
--- a/component/uOCVView.pas
+++ b/component/uOCVView.pas
@@ -35,9 +35,14 @@ uses
core.types_c;
type
+
+ TOnOcvPaint = procedure(Sender: TObject; const IplImage: pIplImage) of object;
+
TocvView = class(TWinControl, IocvDataReceiver)
private
FocvVideoSource: IocvDataSource;
+ FOnAfterPaint: TOnOcvPaint;
+ FOnBeforePaint: TOnOcvPaint;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure SetOpenCVVideoSource(const Value: IocvDataSource);
@@ -49,6 +54,8 @@ type
published
property VideoSource: IocvDataSource Read FocvVideoSource write SetOpenCVVideoSource;
property Align;
+ property OnAfterPaint: TOnOcvPaint read FOnAfterPaint write FOnAfterPaint;
+ property OnBeforePaint: TOnOcvPaint read FOnBeforePaint write FOnBeforePaint;
end;
implementation
@@ -56,12 +63,12 @@ implementation
Uses
cvUtils;
-{ TOpenCVView }
+{TOpenCVView}
destructor TocvView.Destroy;
begin
if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(nil);
+ FocvVideoSource.RemoveReceiver(Self);
inherited;
end;
@@ -70,10 +77,10 @@ begin
if FocvVideoSource <> Value then
begin
if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(nil);
+ FocvVideoSource.RemoveReceiver(Self);
FocvVideoSource := Value;
if Assigned(FocvVideoSource) then
- FocvVideoSource.SetReceiver(Self);
+ FocvVideoSource.AddReceiver(Self);
end;
end;
@@ -85,10 +92,13 @@ end;
procedure TocvView.TakeImage(const IplImage: pIplImage);
begin
if not(csDestroying in ComponentState) then
- ipDraw(
- GetDC(Handle),
- IplImage,
- ClientRect);
+ begin
+ if Assigned(OnBeforePaint) then
+ OnBeforePaint(Self, IplImage);
+ ipDraw(GetDC(Handle), IplImage, ClientRect);
+ if Assigned(OnAfterPaint) then
+ OnAfterPaint(Self, IplImage);
+ end;
end;
procedure TocvView.WMEraseBkgnd(var Message: TWMEraseBkgnd);
diff --git a/samples/Components/cCameraCapture/cCameraCapture.dproj b/samples/Components/cCameraCapture/cCameraCapture.dproj
index a90e87c..ff9c4b7 100644
--- a/samples/Components/cCameraCapture/cCameraCapture.dproj
+++ b/samples/Components/cCameraCapture/cCameraCapture.dproj
@@ -1,7 +1,7 @@
п»ї
{32F0B620-F9A6-4081-8E87-C89FF09CAD04}
- 15.3
+ 15.4
VCL
cCameraCapture.dpr
True
@@ -46,6 +46,7 @@
true
+ cCameraCapture
1049
$(BDS)\bin\delphi_PROJECTICON.ico
System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace)
@@ -79,7 +80,6 @@
..\..\..\component\Win32\Debug\;$(DCC_UnitSearchPath)
- CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;LastCompiledTime=13.06.2013 17:56:41
$(BDS)\bin\default_app.manifest
1033
true
diff --git a/samples/Components/cCameraCapture/uMainForm.dfm b/samples/Components/cCameraCapture/uMainForm.dfm
index 782961c..5223525 100644
--- a/samples/Components/cCameraCapture/uMainForm.dfm
+++ b/samples/Components/cCameraCapture/uMainForm.dfm
@@ -30,13 +30,17 @@ object MainForm: TMainForm
Width = 145
Height = 21
Style = csDropDownList
- TabOrder = 1
+ TabOrder = 0
OnChange = cbb1Change
Items.Strings = (
'None'
'Convert to grayscale'
'Canny'
- 'Smooth')
+ 'Smooth'
+ 'Erode'
+ 'Dilate'
+ 'Laplace'
+ 'Sobel')
end
object chk1: TCheckBox
Left = 308
@@ -54,6 +58,7 @@ object MainForm: TMainForm
Top = 4
Width = 294
Height = 269
+ VideoSource = ocvcmr1
end
object ocvw2: TocvView
Left = 8
@@ -63,26 +68,24 @@ object MainForm: TMainForm
VideoSource = ocvmgprtn1
end
object ocvcmr1: TocvCamera
- Enabled = True
- Resolution = r1280x720
+ Resolution = r640x360
Left = 368
- Top = 132
+ Top = 192
end
object ocvmgprtn1: TocvImageOperation
- PropertiesClassName = 'TocvImageOperation_None'
+ VideoSource = ocvcmr1
+ OperationClassName = 'TocvLaplace'
+ Operations = <
+ item
+ OperationClassName = 'TovcErode'
+ end
+ item
+ OperationClassName = 'TovcImageOperation_Canny'
+ Operation.Threshold1 = 10.000000000000000000
+ Operation.Threshold2 = 100.000000000000000000
+ Operation.ApertureSize = 3
+ end>
Left = 368
Top = 228
end
- object ocvspltr1: TocvSplitter
- VideoSource = ocvcmr1
- Channels = <
- item
- Name = 'ocvspltr1[0]'
- end
- item
- Name = 'ocvspltr1[1]'
- end>
- Left = 368
- Top = 180
- end
end
diff --git a/samples/Components/cCameraCapture/uMainForm.pas b/samples/Components/cCameraCapture/uMainForm.pas
index 0abc7b5..f47cdac 100644
--- a/samples/Components/cCameraCapture/uMainForm.pas
+++ b/samples/Components/cCameraCapture/uMainForm.pas
@@ -28,7 +28,7 @@ interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uOCVTypes, uOCVImageOperation,
- uOCVCamera, uOCVView, Vcl.StdCtrls, uOCVSplitter;
+ core.types_c, uOCVCamera, uOCVView, Vcl.StdCtrls;
type
TMainForm = class(TForm)
@@ -39,7 +39,6 @@ type
ocvw1: TocvView;
ocvmgprtn1: TocvImageOperation;
ocvw2: TocvView;
- ocvspltr1: TocvSplitter;
procedure FormCreate(Sender: TObject);
procedure cbb1Change(Sender: TObject);
procedure chk1Click(Sender: TObject);
@@ -55,13 +54,14 @@ implementation
{$R *.dfm}
Const
- IOClass: array [0 .. 3] of TocvImageOperationClass = (
- { } TocvImageOperation_None, TocvImageOperation_GrayScale,
- { } TovcImageOperation_Canny, TovcImageOperation_Smooth);
+ IOClass: array [0 .. 7] of TocvImageOperationClass = (
+ {} TocvImageOperation_None, TocvImageOperation_GrayScale,
+ {} TovcImageOperation_Canny, TovcImageOperation_Smooth,
+ {} TovcErode, TovcDilate, TocvLaplace, TovcSobel);
procedure TMainForm.cbb1Change(Sender: TObject);
begin
- ocvmgprtn1.PropertiesClass := IOClass[cbb1.ItemIndex];
+ ocvmgprtn1.OperationClass := IOClass[cbb1.ItemIndex];
end;
procedure TMainForm.chk1Click(Sender: TObject);
@@ -71,12 +71,9 @@ end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
- ocvw1.VideoSource := ocvspltr1.Channels[0];
- ocvmgprtn1.VideoSource := ocvspltr1.Channels[1];
- ocvw2.VideoSource := ocvmgprtn1;
cbb1.ItemIndex := 0;
- chk1.Checked := ocvcmr1.Enabled;
- ocvmgprtn1.PropertiesClass := IOClass[cbb1.ItemIndex];
+ ocvmgprtn1.OperationClass := IOClass[cbb1.ItemIndex];
+ ocvcmr1.Enabled := True;
end;
end.
diff --git a/samples/LibDemo/LibDemo.groupproj b/samples/LibDemo/LibDemo.groupproj
index 6954a41..e84e684 100644
--- a/samples/LibDemo/LibDemo.groupproj
+++ b/samples/LibDemo/LibDemo.groupproj
@@ -3,15 +3,15 @@
{8D6AD714-8F0C-4676-BF52-9CBAF8714460}
+
+
+
-
-
-
@@ -200,6 +200,15 @@
+
+
+
+
+
+
+
+
+
@@ -218,15 +227,6 @@
-
-
-
-
-
-
-
-
-
@@ -768,13 +768,13 @@
-
+
-
+
-
+
diff --git a/samples/LibDemo/cvCreateStructuringElementEx/cv_CreateStructuringElementEx.dpr b/samples/LibDemo/cvCreateStructuringElementEx/cv_CreateStructuringElementEx.dpr
index ffaa204..56a6617 100644
--- a/samples/LibDemo/cvCreateStructuringElementEx/cv_CreateStructuringElementEx.dpr
+++ b/samples/LibDemo/cvCreateStructuringElementEx/cv_CreateStructuringElementEx.dpr
@@ -3,7 +3,7 @@
// Copyright (C) 2013 Project Delphi-OpenCV
// ****************************************************************
// Contributor:
- // laentir Valetov
+ // Laentir Valetov
// email:laex@bk.ru
// ****************************************************************
// You may retrieve the latest version of this file at the GitHub,
diff --git a/samples/LibDemo/cvLaplace/cv_Laplace.dpr b/samples/LibDemo/cvLaplace/cv_Laplace.dpr
index b583a00..12865e8 100644
--- a/samples/LibDemo/cvLaplace/cv_Laplace.dpr
+++ b/samples/LibDemo/cvLaplace/cv_Laplace.dpr
@@ -55,7 +55,7 @@ begin
// окно для отображения картинки
cvNamedWindow('original', CV_WINDOW_AUTOSIZE);
- cvNamedWindow('cvLaplace', CV_WINDOW_AUTOSIZE);
+ cvNamedWindow('cvLaplace8b', CV_WINDOW_AUTOSIZE);
// применяем оператор Лаплccа
cvLaplace(image, dst, aperture);
@@ -65,7 +65,7 @@ begin
// показываем картинку
cvShowImage('original', image);
- cvShowImage('cvLaplace', dst2);
+ cvShowImage('cvLaplace8b', dst2);
cvWaitKey(0);