diff --git a/samples/LibDemo/cvAdaptiveSkinDetector/cv_AdaptiveSkinDetector.dpr b/samples/LibDemo/cvAdaptiveSkinDetector/cv_AdaptiveSkinDetector.dpr index a55b45b..a365432 100644 --- a/samples/LibDemo/cvAdaptiveSkinDetector/cv_AdaptiveSkinDetector.dpr +++ b/samples/LibDemo/cvAdaptiveSkinDetector/cv_AdaptiveSkinDetector.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, @@ -33,14 +33,13 @@ program cv_AdaptiveSkinDetector; uses System.SysUtils, WinApi.Windows, - lib, - highgui_c, - core_c, - Core.types_c, - imgproc_c, - imgproc.types_c - // ,contrib - ; + ocv.lib, + ocv.highgui_c, + ocv.core_c, + ocv.Core.types_c, + ocv.imgproc_c, + ocv.imgproc.types_c, + ocv.contrib; const CLOCKS_PER_SEC = 1000; diff --git a/source/component/Delphi20/OpenCV200.dproj b/source/component/Delphi20/OpenCV200.dproj index 9ebebfe..322e613 100644 --- a/source/component/Delphi20/OpenCV200.dproj +++ b/source/component/Delphi20/OpenCV200.dproj @@ -3,7 +3,7 @@ {37486FE1-CC21-40FA-8006-F946D2DCCC3E} OpenCV200.dpk True - Release + Debug 91 Package None @@ -190,7 +190,7 @@ ..;$(DCC_UnitSearchPath) true 1033 - CompanyName=;FileDescription=OpenCV Component;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=OpenCV Component;ProductVersion=1.0.0.0;Comments=;LastCompiledTime=28.05.2014 22:11:47 + CompanyName=;FileDescription=OpenCV Component;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=OpenCV Component;ProductVersion=1.0.0.0;Comments=;LastCompiledTime=30.05.2014 11:33:52 .\$(Platform)\$(Config) @@ -230,7 +230,7 @@ ..;$(DCC_UnitSearchPath) true 1033 - CompanyName=;FileDescription=OpenCV Component;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=OpenCV Component;ProductVersion=1.0.0.0;Comments= + CompanyName=;FileDescription=OpenCV Component;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=OpenCV Component;ProductVersion=1.0.0.0;Comments=;LastCompiledTime=30.05.2014 19:19:54 true diff --git a/source/component/Delphi20/OpenCV200.res b/source/component/Delphi20/OpenCV200.res index bd78e49..475292c 100644 Binary files a/source/component/Delphi20/OpenCV200.res and b/source/component/Delphi20/OpenCV200.res differ diff --git a/source/component/Delphi20/dclOpenCV200.dpk b/source/component/Delphi20/dclOpenCV200.dpk index c3367cb..6bca406 100644 --- a/source/component/Delphi20/dclOpenCV200.dpk +++ b/source/component/Delphi20/dclOpenCV200.dpk @@ -1,35 +1,5 @@ package dclOpenCV200; -{$R *.res} -{$R '..\OpenCV.dcr'} -{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users} -{$ALIGN 8} -{$ASSERTIONS ON} -{$BOOLEVAL OFF} -{$DEBUGINFO OFF} -{$EXTENDEDSYNTAX ON} -{$IMPORTEDDATA ON} -{$IOCHECKS ON} -{$LOCALSYMBOLS OFF} -{$LONGSTRINGS ON} -{$OPENSTRINGS ON} -{$OPTIMIZATION ON} -{$OVERFLOWCHECKS OFF} -{$RANGECHECKS OFF} -{$REFERENCEINFO OFF} -{$SAFEDIVIDE OFF} -{$STACKFRAMES OFF} -{$TYPEDADDRESS OFF} -{$VARSTRINGCHECKS ON} -{$WRITEABLECONST OFF} -{$MINENUMSIZE 1} -{$IMAGEBASE $400000} -{$DEFINE RELEASE} -{$ENDIF IMPLICITBUILDING} -{$DESCRIPTION 'OpenCV Component'} -{$DESIGNONLY} -{$IMPLICITBUILD OFF} - requires OpenCV200, rtl, diff --git a/source/component/Delphi20/dclOpenCV200.dproj b/source/component/Delphi20/dclOpenCV200.dproj index 1661ea9..73d03f5 100644 --- a/source/component/Delphi20/dclOpenCV200.dproj +++ b/source/component/Delphi20/dclOpenCV200.dproj @@ -3,7 +3,7 @@ {29A87BFF-B0BF-4A7F-BC7D-E36D34A7E4B5} dclOpenCV200.dpk True - Release + Debug 1 Package VCL @@ -123,7 +123,7 @@ true 1033 - CompanyName=;FileDescription=OpenCV Component;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=OpenCV Component;ProductVersion=1.0.0.0;Comments=;LastCompiledTime=28.05.2014 22:11:50 + CompanyName=;FileDescription=OpenCV Component;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=OpenCV Component;ProductVersion=1.0.0.0;Comments=;LastCompiledTime=30.05.2014 11:33:56 .\$(Platform)\$(Config) @@ -141,7 +141,7 @@ . true 1033 - CompanyName=;FileDescription=OpenCV Component;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=OpenCV Component;ProductVersion=1.0.0.0;Comments= + CompanyName=;FileDescription=OpenCV Component;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=OpenCV Component;ProductVersion=1.0.0.0;Comments=;LastCompiledTime=30.05.2014 19:19:57 .\$(Platform)\$(Config) @@ -153,7 +153,6 @@ MainSource - diff --git a/source/component/Delphi20/dclOpenCV200.res b/source/component/Delphi20/dclOpenCV200.res index 3bd66df..ba59918 100644 Binary files a/source/component/Delphi20/dclOpenCV200.res and b/source/component/Delphi20/dclOpenCV200.res differ diff --git a/source/component/uOCVImageOperation.pas b/source/component/uOCVImageOperation.pas index 1993c02..84922d0 100644 --- a/source/component/uOCVImageOperation.pas +++ b/source/component/uOCVImageOperation.pas @@ -248,7 +248,7 @@ type 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; - property SmoothOperation: TocvSmoothOperations read FSmoothOperation write SetSmoothOperation default GAUSSIAN; + property SmoothType: TocvSmoothOperations read FSmoothOperation write SetSmoothOperation default GAUSSIAN; end; TocvThresholdType = (THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV, THRESH_MASK, @@ -434,8 +434,6 @@ type function DoTransform(const Source: IocvImage; out Destanation: IocvImage): Boolean; override; end; - TocvLineType = (LT_FILLED, LT_8, LT_AA); - TocvDraw = class(TPersistent) protected FColor: TColor; @@ -448,11 +446,15 @@ type FThickness: Integer; FLineType: TocvLineType; FShift: Integer; + function GetCvLineType: Integer; + function GetCvColor: TCvScalar; public constructor Create(AOwner: TPersistent); destructor Destroy; override; property Color: TColor read FColor write FColor default clGreen; property Shift: Integer read FShift write FShift default 0; + property cvLineType: Integer read GetCvLineType; + property cvColor: TCvScalar read GetCvColor; published property Enabled: Boolean read FEnabled write FEnabled default True; property Thickness: Integer read FThickness write FThickness default 2; @@ -460,6 +462,11 @@ type property Offset: TocvPoint2D32i read FOffset write FOffset; end; + TocvDrawColor = class(TocvDraw) + published + property Color; + end; + TocvMatchTemplateMethod = (TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED); TocvMatchTemplate = class(TocvCustomImageOperation) @@ -491,10 +498,7 @@ type TocvContourApproximationMethods = (CHAIN_CODE, CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS, LINK_RUNS); - TocvDrawMotionRect = class(TocvDraw) - published - property Color; - end; + TocvDrawMotionRect = TocvDrawColor; TocvMotionDetect = class(TocvCustomImageOperationWithNestedOperation) protected @@ -523,6 +527,99 @@ type property NotifyOnlyWhenFound: Boolean index 1 Read GetBoolParam write SetBoolParam; end; + TocvHoughTransform = (HOUGH_STANDARD, HOUGH_PROBABILISTIC, HOUGH_MULTI_SCALE, HOUGH_GRADIENT); + + TocvDrawHoughCircles = TocvDrawColor; + + TovcHoughCirclesSmooth = class(TPersistent) + protected + procedure AssignTo(Dest: TPersistent); override; + private + FSmoothOperation: TocvSmoothOperations; + Fsigma1: Double; + Fsigma2: Double; + Fsize1: Integer; + Fsize2: Integer; + FEnabled: Boolean; + public + constructor Create; + published + property sigma1: Double Read Fsigma1 write Fsigma1; + property sigma2: Double Read Fsigma2 write Fsigma2; + property size1: Integer Read Fsize1 write Fsize1 default 0; + property size2: Integer Read Fsize2 write Fsize2 default 0; + property SmoothType: TocvSmoothOperations read FSmoothOperation write FSmoothOperation default GAUSSIAN; + property Enabled: Boolean read FEnabled write FEnabled default True; + end; + + TocvHoughCircles = class(TocvCustomImageOperation) + protected + procedure AssignTo(Dest: TPersistent); override; + private + FHoughTransform: TocvHoughTransform; + FDrawCircle: TocvDrawHoughCircles; + FOnCircles: TOnOcvCircles; + FSmooth: TovcHoughCirclesSmooth; + public + constructor Create(AOwner: TPersistent); override; + destructor Destroy; override; + function DoTransform(const Source: IocvImage; out Destanation: IocvImage): Boolean; override; + published + property Method: TocvHoughTransform read FHoughTransform write FHoughTransform default HOUGH_GRADIENT; + property InverseRatio: Double index 0 Read GetFloatParam write SetFloatParam; + property MinDist: Double index 1 Read GetFloatParam write SetFloatParam; + property Param1: Double index 2 Read GetFloatParam write SetFloatParam; + property Param2: Double index 3 Read GetFloatParam write SetFloatParam; + property MinRadius: Integer index 0 Read GetIntParam write SetIntParam; + property MaxRadius: Integer index 1 Read GetIntParam write SetIntParam; + property DrawCircle: TocvDrawHoughCircles read FDrawCircle write FDrawCircle; + property OnCircles: TOnOcvCircles read FOnCircles write FOnCircles; + property NotifyOnlyWhenFound: Boolean index 0 Read GetBoolParam write SetBoolParam; + property Smooth: TovcHoughCirclesSmooth read FSmooth write FSmooth; + end; + + TocvHoughLinesCanny = class(TPersistent) + protected + procedure AssignTo(Dest: TPersistent); override; + private + FThreshold1: Double; + FThreshold2: Double; + FApertureSize: Integer; + public + constructor Create; + published + property Threshold1: Double read FThreshold1 write FThreshold1; + property Threshold2: Double read FThreshold2 write FThreshold2; + property ApertureSize: Integer read FApertureSize write FApertureSize default 3; + end; + + TocvDrawHoughLines = TocvDrawColor; + + TocvHoughLines = class(TocvCustomImageOperation) + protected + procedure AssignTo(Dest: TPersistent); override; + private + FHoughTransform: TocvHoughTransform; + FCanny: TocvHoughLinesCanny; + FOnLines: TOnOcvLines; + FDrawLines: TocvDrawHoughLines; + public + constructor Create(AOwner: TPersistent); override; + destructor Destroy; override; + function DoTransform(const Source: IocvImage; out Destanation: IocvImage): Boolean; override; + published + property Method: TocvHoughTransform read FHoughTransform write FHoughTransform default HOUGH_PROBABILISTIC; + property Rho: Double index 0 Read GetFloatParam write SetFloatParam; + property Theta: Double index 1 Read GetFloatParam write SetFloatParam; + property Param1: Double index 2 Read GetFloatParam write SetFloatParam; + property Param2: Double index 3 Read GetFloatParam write SetFloatParam; + property Threshold: Integer index 0 Read GetIntParam write SetIntParam; + property Canny: TocvHoughLinesCanny Read FCanny write FCanny; + property OnLines: TOnOcvLines read FOnLines write FOnLines; + property DrawLines: TocvDrawHoughLines read FDrawLines write FDrawLines; + property NotifyOnlyWhenFound: Boolean index 0 Read GetBoolParam write SetBoolParam; + end; + TocvHaarCascadeDraw = class(TocvDraw) published property Color; @@ -744,7 +841,8 @@ uses ocv.core_c, ocv.imgproc_c, ocv.imgproc.types_c, - ocv.cvutils, System.Math; + ocv.cvutils, + System.Math; type TPersistentAccessProtected = class(TPersistent); @@ -770,27 +868,6 @@ begin Result := _RegisteredImageOperations; end; -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; - -function ColorToCvRGB(const Color: TColor): TCvScalar; -var - r, g, b: byte; -begin - GetRGBValue(Color, r, g, b); - Result := CV_RGB(r, g, b); -end; - {TocvImageOperation} procedure TocvImageOperation.SetOnAfterEachOperation(const Value: TOnOcvNotifyCollectionItem); @@ -1158,7 +1235,7 @@ Var Image: pIplImage; begin Image := cvCloneImage(Source.IpImage); - cvSmooth(Source.IpImage, Image, ocvSmoothOperations[SmoothOperation], size1, size2, sigma1, sigma2); + cvSmooth(Source.IpImage, Image, ocvSmoothOperations[SmoothType], size1, size2, sigma1, sigma2); Destanation := TocvImage.Create(Image); Result := True; end; @@ -1708,6 +1785,16 @@ begin inherited; end; +function TocvDraw.GetCvColor: TCvScalar; +begin + Result := ColorToCvRGB(Color); +end; + +function TocvDraw.GetCvLineType: Integer; +begin + Result := cLineType[LineType]; +end; + function TocvDraw.GetOwner: TPersistent; begin Result := FOwner; @@ -2070,6 +2157,7 @@ begin Threshold := 25; MaxValue := 255; end; + NotifyOnlyWhenFound := False; end; destructor TocvMotionDetect.Destroy; @@ -2672,6 +2760,221 @@ begin FY := AY; end; +{TocvHoughCircles} + +procedure TocvHoughCircles.AssignTo(Dest: TPersistent); +begin + inherited; + if Dest is TocvHoughCircles then + begin + FHoughTransform := (Dest as TocvHoughCircles).FHoughTransform; + end; +end; + +constructor TocvHoughCircles.Create(AOwner: TPersistent); +begin + inherited; + FHoughTransform := HOUGH_GRADIENT; + InverseRatio := 1; + MinDist := 100; + Param1 := 100; + Param2 := 100; + MinRadius := 0; + MaxRadius := 0; + FDrawCircle := TocvDrawHoughCircles.Create(Self); + NotifyOnlyWhenFound := False; + FSmooth := TovcHoughCirclesSmooth.Create; + FSmooth.SmoothType := GAUSSIAN; + FSmooth.size1 := 5; + FSmooth.size2 := 5; + FSmooth.sigma1 := 0; + FSmooth.sigma2 := 0; +end; + +destructor TocvHoughCircles.Destroy; +begin + FDrawCircle.Free; + FSmooth.Free; + inherited; +end; + +function TocvHoughCircles.DoTransform(const Source: IocvImage; out Destanation: IocvImage): Boolean; +type + TFloatArray = array [0 .. 10] of Single; + pFloatArray = ^TFloatArray; + +Var + results: pCvSeq; + storage: pCvMemStorage; + Circles: TocvCircles; + i: Integer; + p: pFloatArray; + D: IocvImage; +begin + SetLength(Circles, 0); + Destanation := Source; + try + storage := cvCreateMemStorage(0); + results := nil; + try + + if Smooth.Enabled then + begin + D := Source.Same; + cvSmooth(Source.IpImage, D.IpImage, ocvSmoothOperations[Smooth.SmoothType], Smooth.size1, Smooth.size2, Smooth.sigma1, + Smooth.sigma2); + end + else + D := Source; + + results := cvHoughCircles(D.GrayImage.IpImage, storage, Integer(Method), InverseRatio, MinDist, Param1, Param2, MinRadius, + MaxRadius); + if Assigned(results) then + begin + SetLength(Circles, results^.total); + for i := 0 to results^.total - 1 do + begin + p := pFloatArray(cvGetSeqElem(results, i)); + Circles[i].cX := cvRound(p^[0]); + Circles[i].cY := cvRound(p^[1]); + Circles[i].Radius := cvRound(p^[2]); + if DrawCircle.Enabled then + cvCircle(Destanation.IpImage, cvPoint(Circles[i].cX, Circles[i].cY), Circles[i].Radius, DrawCircle.cvColor, + DrawCircle.Thickness, DrawCircle.cvLineType, DrawCircle.Shift); + end; + end; + finally + cvReleaseMemStorage(storage); + end; + except + end; + if Assigned(OnCircles) and ((Length(Circles) > 0) or (not NotifyOnlyWhenFound)) then + OnCircles(Self, Destanation, Circles); +end; + +{TocvHoughLines} + +procedure TocvHoughLines.AssignTo(Dest: TPersistent); +begin + inherited; + if Dest is TocvHoughLines then + begin + FHoughTransform := (Dest as TocvHoughLines).FHoughTransform + end; +end; + +constructor TocvHoughLines.Create(AOwner: TPersistent); +begin + inherited; + FHoughTransform := HOUGH_PROBABILISTIC; + Rho := 1; + Theta := CV_PI / 180; + Param1 := 50; + Param2 := 10; + Threshold := 50; + FCanny := TocvHoughLinesCanny.Create; + FDrawLines := TocvDrawHoughLines.Create(Self); + NotifyOnlyWhenFound := True; +end; + +destructor TocvHoughLines.Destroy; +begin + FCanny.Free; + FDrawLines.Free; + inherited; +end; + +function TocvHoughLines.DoTransform(const Source: IocvImage; out Destanation: IocvImage): Boolean; +Var + lines: pCvSeq; + line: pCvPointArray; + storage: pCvMemStorage; + SG, D: IocvImage; + i: Integer; + ocvlines: TocvLines; +begin + lines := nil; + SetLength(ocvlines, 0); + Destanation := Source; + try + storage := cvCreateMemStorage(0); + try + SG := Source.GrayImage; + D := SG.Same; + cvCanny(SG.IpImage, D.IpImage, Canny.Threshold1, Canny.Threshold2, Canny.ApertureSize); + lines := cvHoughLines2(D.IpImage, storage, Integer(Method), Rho, Theta, Threshold, Param1, Param2); + if Assigned(lines) then + begin + SetLength(ocvlines, lines^.total); + for i := 0 to lines^.total - 1 do + begin + line := pCvPointArray(cvGetSeqElem(lines, i)); + ocvlines[i].S := line^[0]; + ocvlines[i].E := line^[1]; + if DrawLines.Enabled then + cvLine(Destanation.IpImage, line^[0], line^[1], DrawLines.cvColor, DrawLines.Thickness, DrawLines.cvLineType, + DrawLines.Shift); + end; + end; + + if Assigned(OnLines) and ((Length(ocvlines) > 0) or (not NotifyOnlyWhenFound)) then + OnLines(Self, Destanation, ocvlines); + finally + cvReleaseMemStorage(storage); + end; + except + + end; +end; + +{TovcHoughCirclesSmooth} + +procedure TovcHoughCirclesSmooth.AssignTo(Dest: TPersistent); +begin + inherited; + if Dest is TovcHoughCirclesSmooth then + begin + FSmoothOperation := (Dest as TovcHoughCirclesSmooth).FSmoothOperation; + Fsigma1 := (Dest as TovcHoughCirclesSmooth).Fsigma1; + Fsigma2 := (Dest as TovcHoughCirclesSmooth).Fsigma2; + Fsize1 := (Dest as TovcHoughCirclesSmooth).Fsize1; + Fsize2 := (Dest as TovcHoughCirclesSmooth).Fsize2; + FEnabled := (Dest as TovcHoughCirclesSmooth).FEnabled; + end; +end; + +constructor TovcHoughCirclesSmooth.Create; +begin + inherited; + FSmoothOperation := GAUSSIAN; + Fsigma1 := 0; + Fsigma2 := 0; + Fsize1 := 5; + Fsize2 := 5; + FEnabled := True; +end; + +{TocvHoughLinesCanny} + +procedure TocvHoughLinesCanny.AssignTo(Dest: TPersistent); +begin + inherited; + if Dest is TocvHoughLinesCanny then + begin + FThreshold1 := (Dest as TocvHoughLinesCanny).FThreshold1; + FThreshold2 := (Dest as TocvHoughLinesCanny).FThreshold2; + FApertureSize := (Dest as TocvHoughLinesCanny).FApertureSize; + end; +end; + +constructor TocvHoughLinesCanny.Create; +begin + inherited; + FThreshold1 := 50; + FThreshold2 := 200; + FApertureSize := 3; +end; + initialization GetRegisteredImageOperations.RegisterIOClass(TocvNoneOperation, 'None'); @@ -2693,6 +2996,8 @@ GetRegisteredImageOperations.RegisterIOClass(TocvMotionDetect, 'MotionDetect'); GetRegisteredImageOperations.RegisterIOClass(TovcCropOperation, 'Crop'); GetRegisteredImageOperations.RegisterIOClass(TovcAddWeightedOperation, 'AddWeighted'); GetRegisteredImageOperations.RegisterIOClass(TocvWarpPerspective, 'WarpPerspective'); +GetRegisteredImageOperations.RegisterIOClass(TocvHoughCircles, 'HoughCircles'); +GetRegisteredImageOperations.RegisterIOClass(TocvHoughLines, 'HoughLines'); finalization diff --git a/source/component/uOCVRegister.pas b/source/component/uOCVRegister.pas index 1a91fd3..52b36cc 100644 --- a/source/component/uOCVRegister.pas +++ b/source/component/uOCVRegister.pas @@ -70,7 +70,9 @@ begin {} TocvMotionDetect, {} TovcCropOperation, {} TovcAddWeightedOperation, - {} TocvWarpPerspective]); + {} TocvWarpPerspective, + {} TocvHoughCircles, + {} TocvHoughLines]); end; {$IFDEF FPC} diff --git a/source/component/uOCVTypes.pas b/source/component/uOCVTypes.pas index 4c9fa3f..edaf928 100644 --- a/source/component/uOCVTypes.pas +++ b/source/component/uOCVTypes.pas @@ -30,20 +30,89 @@ interface uses {$IFDEF VER15P} + WinApi.Windows, System.SysUtils, System.Classes, System.Generics.Collections, System.Types, Vcl.Graphics, {$ELSE} + Windows, SysUtils, Classes, Graphics, {$IFNDEF VER5}Types, {$ENDIF VER5} {$ENDIF VER15P} + ocv.core_c, ocv.core.types_c; Type + + TocvRect = Type TRect; + TocvLine = record + S, E: TCvPoint; + end; + + TocvCircle = record + cX, cY: Integer; + Radius: Integer; + end; + +{$IFDEF VER17P} + + TocvRects = TArray; + TocvCircles = TArray; + TocvLines = TArray; +{$ELSE} + TocvRects = Array of TocvRect; + TocvCircles = Array of TocvCircle; + TocvLines = array of TocvLine; +{$ENDIF} + TocvLineType = (LT_FILLED, LT_8, LT_AA); + + IocvFont = interface + ['{3EAFF1CE-7C65-4138-829F-329C81DDED8F}'] + function GetFontName: string; + procedure SetFontName(const Value: string); + function GetFontColor: TColor; + procedure SetFontColor(const Value: TColor); + function GetFontThickness: Integer; + procedure SetFontThickness(const Value: Integer); + function GetFontLineType: TocvLineType; + procedure SetFontLineType(const Value: TocvLineType); + function GetFontHScale: Single; + procedure SetFontHScale(const Value: Single); + function GetFontVScale: Single; + procedure SetFontVScale(const Value: Single); + function GetCvFont: TCvFont; + property Name: string read GetFontName write SetFontName; + property Color: TColor read GetFontColor write SetFontColor; + property Thickness: Integer read GetFontThickness write SetFontThickness; + property LineType: TocvLineType read GetFontLineType write SetFontLineType; + property HScale: Single read GetFontHScale write SetFontHScale; + property VScale: Single read GetFontVScale write SetFontVScale; + property cvFont: TCvFont Read GetCvFont; + end; + + IocvCanvas = interface + ['{D5BCBC44-8139-42A7-A97A-0A5AD33C6526}'] + function GetOcvFont: IocvFont; + property ocvFont: IocvFont read GetOcvFont; + + procedure Rectangle(const x1, y1, x2, y2: Integer; const Color: TColor = clRed; const Thickness: Integer = 1; + const LineType: TocvLineType = LT_8; const Shift: Integer = 0); + procedure Circle(const x, y, r: Integer; const Color: TColor = clRed; const Thickness: Integer = 1; + const LineType: TocvLineType = LT_8; const Shift: Integer = 0); + procedure Ellipse(const CenterX, CenterY: Integer; const Axes: TocvRect; const Angle: double; const start_angle: double; + const nd_angle: double; const Color: TColor = clRed; const Thickness: Integer = 1; const LineType: TocvLineType = LT_8; + const Shift: Integer = 0); + procedure EllipseBox(const Box: TocvRect; const Angle: Single; const Color: TColor = clRed; const Thickness: Integer = 1; + Const LineType: TocvLineType = LT_8; const Shift: Integer = 0); overload; + procedure EllipseBox(const Box: TCvBox2D; const Color: TColor = clRed; const Thickness: Integer = 1; + Const LineType: TocvLineType = LT_8; const Shift: Integer = 0); overload; + procedure TextOut(const x, y: Integer; const Text: String; const Shadow: Boolean = False); + end; + IocvImage = interface ['{84567F57-A399-4179-AA0F-6F8A2788F89B}'] function GetIplImage: pIplImage; @@ -55,21 +124,84 @@ Type function Crop(const roi: TCvRect): IocvImage; function GetWidth: Integer; function GetHeight: Integer; + function GetCanvas: IocvCanvas; + // ------------------------------------------- property IpImage: pIplImage Read GetIplImage; - property isGray: Boolean read GetisGray; - property Width: Integer read GetWidth; - property Height: Integer read GetHeight; + property isGray: Boolean Read GetisGray; + property Width: Integer Read GetWidth; + property Height: Integer Read GetHeight; + property Canvas: IocvCanvas Read GetCanvas; + end; + + TocvFont = class(TInterfacedObject, IocvFont) + private + FCvFont: TCvFont; + FFontColor: TColor; + FFontLineType: TocvLineType; + procedure CreateOcvFont; + protected + function GetFontName: string; + procedure SetFontName(const Value: string); + function GetFontColor: TColor; + procedure SetFontColor(const Value: TColor); + function GetFontThickness: Integer; + procedure SetFontThickness(const Value: Integer); + function GetFontLineType: TocvLineType; + procedure SetFontLineType(const Value: TocvLineType); + function GetFontHScale: Single; + procedure SetFontHScale(const Value: Single); + function GetFontVScale: Single; + procedure SetFontVScale(const Value: Single); + function GetCvFont: TCvFont; + public + constructor Create; + property Name: string read GetFontName write SetFontName; + property Color: TColor read GetFontColor write SetFontColor; + property Thickness: Integer read GetFontThickness write SetFontThickness; + property LineType: TocvLineType read GetFontLineType write SetFontLineType; + property HScale: Single read GetFontHScale write SetFontHScale; + property VScale: Single read GetFontVScale write SetFontVScale; + property cvFont: TCvFont Read GetCvFont; + end; + + TocvImage = class; + + TocvCanvas = class(TInterfacedObject, IocvCanvas) + private + FOwner: TocvImage; + FocvFont: IocvFont; + protected + function GetOcvFont: IocvFont; + public + constructor Create(AOwner: TocvImage); + destructor Destroy; override; + procedure Rectangle(const x1, y1, x2, y2: Integer; const Color: TColor = clRed; const Thickness: Integer = 1; + const LineType: TocvLineType = LT_AA; const Shift: Integer = 0); + procedure Circle(const CenterX, CenterY, Radius: Integer; const Color: TColor = clRed; const Thickness: Integer = 1; + const LineType: TocvLineType = LT_8; const Shift: Integer = 0); + procedure Ellipse(const CenterX, CenterY: Integer; const Axes: TocvRect; const Angle: double; const start_angle: double; + const nd_angle: double; const Color: TColor = clRed; const Thickness: Integer = 1; const LineType: TocvLineType = LT_8; + const Shift: Integer = 0); + procedure EllipseBox(const Box: TocvRect; const Angle: Single; const Color: TColor = clRed; const Thickness: Integer = 1; + Const LineType: TocvLineType = LT_8; const Shift: Integer = 0); overload; + procedure EllipseBox(const Box: TCvBox2D; const Color: TColor = clRed; const Thickness: Integer = 1; + Const LineType: TocvLineType = LT_8; const Shift: Integer = 0); overload; + procedure TextOut(const x, y: Integer; const Text: String; const Shadow: Boolean = False); + property ocvFont: IocvFont read GetOcvFont; end; TocvImage = class(TInterfacedObject, IocvImage) private FImage: pIplImage; + FocvCanvas: IocvCanvas; protected function GetIplImage: pIplImage; function GetisGray: Boolean; function GetWidth: Integer; function GetHeight: Integer; + function GetCanvas: IocvCanvas; public + constructor Create; overload; constructor Create(const AImage: pIplImage); overload; constructor Create(const Bitmap: TBitmap); overload; constructor CreateClone(const AImage: pIplImage); @@ -81,7 +213,7 @@ Type function AsBitmap: TBitmap; function Crop(const roi: TCvRect): IocvImage; property IplImage: pIplImage Read GetIplImage; - property isGray: Boolean read GetisGray; + property isGray: Boolean Read GetisGray; end; TOnOcvNotifyCollectionItem = procedure(PrevOperation, Operation, NextOperation: TObject; const IplImage: IocvImage; @@ -92,16 +224,11 @@ Type TOnOcvBeforeTransform = procedure(Sender: TObject; const IplImage: IocvImage; Var ContinueTransform: Boolean) of object; TOnOcvContour = procedure(Sender: TObject; const IplImage: IocvImage; const ContourCount: Integer; const Contours: pCvSeq) of object; - - TocvRect = Type TRect; -{$IFDEF VER17P} - TocvRects = TArray; -{$ELSE} - TocvRects = Array of TocvRect; -{$ENDIF} TOnOcvHaarCascade = procedure(Sender: TObject; const IplImage: IocvImage; const HaarRects: TocvRects) of object; TOnOcvRect = procedure(Sender: TObject; const IplImage: IocvImage; const Rect: TocvRect) of object; TOnOcvRects = procedure(Sender: TObject; const IplImage: IocvImage; const Rects: TocvRects) of object; + TOnOcvCircles = procedure(Sender: TObject; const IplImage: IocvImage; const Circles: TocvCircles) of object; + TOnOcvLines = procedure(Sender: TObject; const IplImage: IocvImage; const Lines: TocvLines) of object; IocvDataReceiver = interface ['{F67DEC9E-CCE0-49D2-AB9B-AD7E1020C5DC}'] @@ -116,7 +243,7 @@ Type function GetName: string; function GetImage: IocvImage; function GetEnabled: Boolean; - property Enabled: Boolean read GetEnabled; + property Enabled: Boolean Read GetEnabled; end; TocvReceiverList = class(TThreadList) // ; @@ -138,17 +265,17 @@ Type destructor Destroy; override; procedure AddReceiver(const OpenCVVideoReceiver: IocvDataReceiver); virtual; procedure RemoveReceiver(const OpenCVVideoReceiver: IocvDataReceiver); virtual; - property Image: IocvImage read GetImage; + property Image: IocvImage Read GetImage; end; TocvDataReceiver = class(TComponent, IocvDataReceiver) private FocvVideoSource: IocvDataSource; protected - procedure TakeImage(const IplImage: IocvImage); virtual; procedure SetVideoSource(const Value: TObject); virtual; procedure SetOpenCVVideoSource(const Value: IocvDataSource); virtual; public + procedure TakeImage(const IplImage: IocvImage); virtual; destructor Destroy; override; published property VideoSource: IocvDataSource Read FocvVideoSource write SetOpenCVVideoSource; @@ -170,13 +297,15 @@ Type function ocvRect(Left, Top, Right, Bottom: Integer): TocvRect; function ocvRectCenter(cX, cY, Width, Height: Integer): TocvRect; +procedure GetRGBValue(const AColor: TColor; var r, g, b: byte); +function ColorToCvRGB(const Color: TColor): TCvScalar; + +const + cLineType: array [TocvLineType] of Integer = (CV_FILLED, 8, CV_AA); + implementation -uses - ocv.core_c, - ocv.imgproc_c, - ocv.imgproc.types_c, - ocv.highgui_c; +uses ocv.imgproc_c, ocv.imgproc.types_c, ocv.highgui_c; function ocvRect(Left, Top, Right, Bottom: Integer): TocvRect; begin @@ -231,13 +360,13 @@ end; procedure TocvDataSource.NotifyReceiver(const IplImage: IocvImage); Var - R: Pointer; // IocvDataReceiver; + r: Pointer; // IocvDataReceiver; LockList: TList; // ; begin LockList := FOpenCVVideoReceivers.LockList; try - for R in LockList do - IocvDataReceiver(R).TakeImage(IplImage); + for r in LockList do + IocvDataReceiver(r).TakeImage(IplImage); finally FOpenCVVideoReceivers.UnlockList; end; @@ -361,6 +490,7 @@ end; constructor TocvImage.Create(const AImage: pIplImage); begin + Create; FImage := AImage; end; @@ -368,6 +498,7 @@ constructor TocvImage.Create(const Bitmap: TBitmap); Var bitmapData: PByte; begin + Create; Assert(Bitmap.PixelFormat = pf24bit, 'only 24bit'); // Пока только такой формат - IPL_DEPTH_8U, 3 bitmapData := Bitmap.Scanline[0]; FImage := cvCreateImage(cvSize(Bitmap.Width, Bitmap.Height), IPL_DEPTH_8U, 3); @@ -378,8 +509,14 @@ begin FImage^.roi := nil; end; +constructor TocvImage.Create; +begin + FocvCanvas := TocvCanvas.Create(Self); +end; + constructor TocvImage.CreateClone(const AImage: pIplImage); begin + Create; FImage := cvCloneImage(AImage); end; @@ -396,10 +533,16 @@ end; destructor TocvImage.Destroy; begin + // FocvCanvas.Free; cvReleaseImage(FImage); inherited; end; +function TocvImage.GetCanvas: IocvCanvas; +begin + Result := FocvCanvas as IocvCanvas; +end; + function TocvImage.GetHeight: Integer; begin if Assigned(FImage) then @@ -462,4 +605,182 @@ begin inherited Remove(Pointer(Item)); end; +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; + +function ColorToCvRGB(const Color: TColor): TCvScalar; +var + r, g, b: byte; +begin + GetRGBValue(Color, r, g, b); + Result := CV_RGB(r, g, b); +end; + +{TocvCanvas} + +procedure TocvCanvas.Circle(const CenterX, CenterY, Radius: Integer; const Color: TColor; const Thickness: Integer; + const LineType: TocvLineType; const Shift: Integer); +begin + if Assigned(FOwner) and Assigned(FOwner.FImage) then + cvCircle(FOwner.FImage, cvPoint(CenterX, CenterY), Radius, ColorToCvRGB(Color), Thickness, cLineType[LineType], Shift); +end; + +constructor TocvCanvas.Create(AOwner: TocvImage); +begin + FOwner := AOwner; + FocvFont := TocvFont.Create; +end; + +destructor TocvCanvas.Destroy; +begin + // FocvFont.Free; + inherited; +end; + +procedure TocvCanvas.Ellipse(const CenterX, CenterY: Integer; const Axes: TocvRect; const Angle, start_angle, nd_angle: double; + const Color: TColor; const Thickness: Integer; const LineType: TocvLineType; const Shift: Integer); +begin + if Assigned(FOwner) and Assigned(FOwner.FImage) then + cvEllipse(FOwner.FImage, cvPoint(CenterX, CenterY), cvSize(Axes.Width, Axes.Height), Angle, start_angle, nd_angle, + ColorToCvRGB(Color), Thickness, cLineType[LineType], Shift); +end; + +procedure TocvCanvas.EllipseBox(const Box: TCvBox2D; const Color: TColor; const Thickness: Integer; const LineType: TocvLineType; + const Shift: Integer); +begin + if Assigned(FOwner) and Assigned(FOwner.FImage) then + cvEllipseBox(FOwner.FImage, Box, ColorToCvRGB(Color), Thickness, cLineType[LineType], Shift); +end; + +function TocvCanvas.GetOcvFont: IocvFont; +begin + Result := FocvFont as IocvFont; +end; + +procedure TocvCanvas.EllipseBox(const Box: TocvRect; const Angle: Single; const Color: TColor; const Thickness: Integer; + const LineType: TocvLineType; const Shift: Integer); +begin + EllipseBox(CvBox2D(Box.Left, Box.Top, Box.Width, Box.Height, Angle), Color, Thickness, LineType, Shift); +end; + +procedure TocvCanvas.Rectangle(const x1, y1, x2, y2: Integer; const Color: TColor; const Thickness: Integer; + const LineType: TocvLineType; const Shift: Integer); +begin + if Assigned(FOwner) and Assigned(FOwner.FImage) then + cvRectangle(FOwner.FImage, cvPoint(x1, y1), cvPoint(x2, y2), ColorToCvRGB(Color), Thickness, cLineType[LineType], Shift); +end; + +procedure TocvCanvas.TextOut(const x, y: Integer; const Text: String; const Shadow: Boolean); +Var + str: pCVChar; + Font: TCvFont; +begin + if Assigned(FOwner) and Assigned(FOwner.FImage) then + begin + str := @(AnsiString(Text)[1]); + Font := ocvFont.cvFont; + if Shadow then + cvPutText(FOwner.FImage, str, cvPoint(x - 1, y - 1), @Font, CV_RGB(0, 0, 0)); + cvPutText(FOwner.FImage, str, cvPoint(x, y), @Font, ColorToCvRGB(ocvFont.Color)); + end; +end; + +{TocvFont} + +constructor TocvFont.Create; +begin + inherited; + FillChar(FCvFont, SizeOf(FCvFont), 0); + FCvFont.HScale := 0.5; + FCvFont.VScale := 0.5; + FCvFont.Thickness := 1; + FFontLineType := LT_8; + FFontColor := clRed; + CreateOcvFont; +end; + +procedure TocvFont.CreateOcvFont; +begin + cvInitFont(@FCvFont, CV_FONT_VECTOR0, HScale, VScale, 0, Thickness, cLineType[LineType]); +end; + +function TocvFont.GetCvFont: TCvFont; +begin + Result := FCvFont; +end; + +function TocvFont.GetFontColor: TColor; +begin + Result := FFontColor; +end; + +function TocvFont.GetFontHScale: Single; +begin + Result := FCvFont.HScale; +end; + +function TocvFont.GetFontLineType: TocvLineType; +begin + Result := FFontLineType; +end; + +function TocvFont.GetFontName: string; +begin + Result := FCvFont.nameFont; +end; + +function TocvFont.GetFontThickness: Integer; +begin + Result := FCvFont.Thickness; +end; + +function TocvFont.GetFontVScale: Single; +begin + Result := FCvFont.VScale; +end; + +procedure TocvFont.SetFontColor(const Value: TColor); +begin + FFontColor := Value; + FCvFont.Color := ColorToCvRGB(Value); + CreateOcvFont; +end; + +procedure TocvFont.SetFontHScale(const Value: Single); +begin + FCvFont.HScale := Value; + CreateOcvFont; +end; + +procedure TocvFont.SetFontLineType(const Value: TocvLineType); +begin + FFontLineType := Value; + CreateOcvFont; +end; + +procedure TocvFont.SetFontName(const Value: string); +begin + FCvFont.nameFont := pCVChar(AnsiString(Value)); + CreateOcvFont; +end; + +procedure TocvFont.SetFontThickness(const Value: Integer); +begin + FCvFont.Thickness := Value; + CreateOcvFont; +end; + +procedure TocvFont.SetFontVScale(const Value: Single); +begin + FCvFont.VScale := Value; + CreateOcvFont; +end; + end. diff --git a/source/ocv.contrib.pas b/source/ocv.contrib.pas new file mode 100644 index 0000000..75781ba --- /dev/null +++ b/source/ocv.contrib.pas @@ -0,0 +1,1305 @@ +// --------------------------------- OpenCV license.txt --------------------------- +(* // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. + // + // By downloading, copying, installing or using the software you agree to this license. + // If you do not agree to this license, do not download, install, + // copy or use the software. + // + // + // License Agreement + // For Open Source Computer Vision Library + // + // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. + // Copyright (C) 2009, Willow Garage Inc., all rights reserved. + // Third party copyrights are property of their respective owners. + // + // Redistribution and use in source and binary forms, with or without modification, + // are permitted provided that the following conditions are met: + // + // * Redistribution's of source code must retain the above copyright notice, + // this list of conditions and the following disclaimer. + // + // * Redistribution's in binary form must reproduce the above copyright notice, + // this list of conditions and the following disclaimer in the documentation + // and/or other materials provided with the distribution. + // + // * The name of the copyright holders may not be used to endorse or promote products + // derived from this software without specific prior written permission. + // + // This software is provided by the copyright holders and contributors "as is" and + // any express or implied warranties, including, but not limited to, the implied + // warranties of merchantability and fitness for a particular purpose are disclaimed. + // In no event shall the Intel Corporation or contributors be liable for any direct, + // indirect, incidental, special, exemplary, or consequential damages + // (including, but not limited to, procurement of substitute goods or services; + // loss of use, data, or profits; or business interruption) however caused + // and on any theory of liability, whether in contract, strict liability, + // or tort (including negligence or otherwise) arising in any way out of + // the use of this software, even if advised of the possibility of such damage. *) + +(* / ************************************************************************************************** + // 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 + // ************************************************************************************************** + // License: + // The contents of this file are 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/ + // + // 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. + // + // Alternatively, the contents of this file may be used under the terms of the + // GNU Lesser General Public License (the "LGPL License"), in which case the + // provisions of the LGPL License are applicable instead of those above. + // If you wish to allow use of your version of this file only under the terms + // of the LGPL License and not to allow others to use your version of this file + // under the MPL, indicate your decision by deleting the provisions above and + // replace them with the notice and other provisions required by the LGPL + // License. If you do not delete the provisions above, a recipient may use + // your version of this file under either the MPL or the LGPL License. + // + // For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html + // ************************************************************************************************** + // Warning: Using Delphi XE3 syntax! + // ************************************************************************************************** + // The Initial Developer of the Original Code: + // OpenCV: open source computer vision library + // Homepage: http://opencv.org + // Online docs: http://docs.opencv.org + // Q&A forum: http://answers.opencv.org + // Dev zone: http://code.opencv.org + // ************************************************************************************************** + // Original file: + // opencv\modules\contrib\include\opencv2\contrib.hpp + // ************************************************************************************************* *) + +{$IFDEF DEBUG} +{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q+,R+,S-,T-,U-,V+,W+,X+,Y+,Z1} +{$ELSE} +{$A8,B-,C-,D-,E-,F-,G+,H+,I+,J-,K-,L-,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y-,Z1} +{$ENDIF} +{$WARN SYMBOL_DEPRECATED OFF} +{$WARN SYMBOL_PLATFORM OFF} +{$WARN UNIT_PLATFORM OFF} +{$WARN UNSAFE_TYPE OFF} +{$WARN UNSAFE_CODE OFF} +{$WARN UNSAFE_CAST OFF} +unit ocv.contrib; + +interface + +uses + ocv.core.types_c; + +/// ****************************************************************************************\ +// * Adaptive Skin Detector * +// \****************************************************************************************/ + +Type + TCvAdaptiveSkinDetector = class + private const + GSD_HUE_LT = 3; + GSD_HUE_UT = 33; + GSD_INTENSITY_LT = 15; + GSD_INTENSITY_UT = 250; + + type + THistogram = class + private const + HistogramSize = (GSD_HUE_UT - GSD_HUE_LT + 1); + protected + function findCoverageIndex(surfaceToCover: double; defaultValue: Integer = 0): Integer; + public + fHistogram: pCvHistogram; + constructor create; + destructor Destroy; override; + procedure findCurveThresholds(Var x1, x2: Integer; percent: double = 0.05); + procedure mergeWith(source: THistogram; weight: double); + end; + private + nStartCounter, nFrameCount, nSkinHueLowerBound, nSkinHueUpperBound, nMorphingMethod, nSamplingDivider: Integer; + fHistogramMergeFactor, fHuePercentCovered: double; + histogramHueMotion, skinHueHistogram: THistogram; + imgHueFrame, imgSaturationFrame, imgLastGrayFrame, imgMotionFrame, imgFilteredFrame: pIplImage; + imgShrinked, imgTemp, imgGrayFrame, imgHSVFrame: pIplImage; + + protected + procedure initData(src: pIplImage; widthDivider, heightDivider: Integer); + procedure adaptiveFilter; + public + + const + MORPHING_METHOD_NONE = 0; + MORPHING_METHOD_ERODE = 1; + MORPHING_METHOD_ERODE_ERODE = 2; + MORPHING_METHOD_ERODE_DILATE = 3; + + constructor create(samplingDivider: Integer = 1; morphingMethod: Integer = MORPHING_METHOD_NONE); + destructor Destroy; override; + procedure process(inputBGRImage: pIplImage; outputHueMask: pIplImage); virtual; + end; + +procedure ASD_INTENSITY_SET_PIXEL(ptr: PByte; qq: uchar); inline; +{ (*pointer) = (unsigned char)qq; } + +function ASD_IS_IN_MOTION(ptr: PByte; v, threshold: uchar): Boolean; +// ((abs((*(pointer)) - (v)) > (threshold)) ? true : false) + +/// ****************************************************************************************\ +// * Fuzzy MeanShift Tracker * +// \****************************************************************************************/ +// +// class CV_EXPORTS CvFuzzyPoint { +// public: +// double x, y, value; +// +// CvFuzzyPoint(double _x, double _y); +// }; +// +// class CV_EXPORTS CvFuzzyCurve { +// private: +// std::vector points; +// double value, centre; +// +// bool between(double x, double x1, double x2); +// +// public: +// CvFuzzyCurve(); +// ~CvFuzzyCurve(); +// +// void setCentre(double _centre); +// double getCentre(); +// void clear(); +// void addPoint(double x, double y); +// double calcValue(double param); +// double getValue(); +// void setValue(double _value); +// }; +// +// class CV_EXPORTS CvFuzzyFunction { +// public: +// std::vector curves; +// +// CvFuzzyFunction(); +// ~CvFuzzyFunction(); +// void addCurve(CvFuzzyCurve *curve, double value = 0); +// void resetValues(); +// double calcValue(); +// CvFuzzyCurve *newCurve(); +// }; +// +// class CV_EXPORTS CvFuzzyRule { +// private: +// CvFuzzyCurve *fuzzyInput1, *fuzzyInput2; +// CvFuzzyCurve *fuzzyOutput; +// public: +// CvFuzzyRule(); +// ~CvFuzzyRule(); +// void setRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1); +// double calcValue(double param1, double param2); +// CvFuzzyCurve *getOutputCurve(); +// }; +// +// class CV_EXPORTS CvFuzzyController { +// private: +// std::vector rules; +// public: +// CvFuzzyController(); +// ~CvFuzzyController(); +// void addRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1); +// double calcOutput(double param1, double param2); +// }; +// +// class CV_EXPORTS CvFuzzyMeanShiftTracker +// { +// private: +// class FuzzyResizer +// { +// private: +// CvFuzzyFunction iInput, iOutput; +// CvFuzzyController fuzzyController; +// public: +// FuzzyResizer(); +// int calcOutput(double edgeDensity, double density); +// }; +// +// class SearchWindow +// { +// public: +// FuzzyResizer *fuzzyResizer; +// int x, y; +// int width, height, maxWidth, maxHeight, ellipseHeight, ellipseWidth; +// int ldx, ldy, ldw, ldh, numShifts, numIters; +// int xGc, yGc; +// long m00, m01, m10, m11, m02, m20; +// double ellipseAngle; +// double density; +// unsigned int depthLow, depthHigh; +// int verticalEdgeLeft, verticalEdgeRight, horizontalEdgeTop, horizontalEdgeBottom; +// +// SearchWindow(); +// ~SearchWindow(); +// void setSize(int _x, int _y, int _width, int _height); +// void initDepthValues(IplImage *maskImage, IplImage *depthMap); +// bool shift(); +// void extractInfo(IplImage *maskImage, IplImage *depthMap, bool initDepth); +// void getResizeAttribsEdgeDensityLinear(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh); +// void getResizeAttribsInnerDensity(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh); +// void getResizeAttribsEdgeDensityFuzzy(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh); +// bool meanShift(IplImage *maskImage, IplImage *depthMap, int maxIteration, bool initDepth); +// }; +// +// public: +// enum TrackingState +// { +// tsNone = 0, +// tsSearching = 1, +// tsTracking = 2, +// tsSetWindow = 3, +// tsDisabled = 10 +// }; +// +// enum ResizeMethod { +// rmEdgeDensityLinear = 0, +// rmEdgeDensityFuzzy = 1, +// rmInnerDensity = 2 +// }; +// +// enum { +// MinKernelMass = 1000 +// }; +// +// SearchWindow kernel; +// int searchMode; +// +// private: +// enum +// { +// MaxMeanShiftIteration = 5, +// MaxSetSizeIteration = 5 +// }; +// +// void findOptimumSearchWindow(SearchWindow &searchWindow, IplImage *maskImage, IplImage *depthMap, int maxIteration, int resizeMethod, bool initDepth); +// +// public: +// CvFuzzyMeanShiftTracker(); +// ~CvFuzzyMeanShiftTracker(); +// +// void track(IplImage *maskImage, IplImage *depthMap, int resizeMethod, bool resetSearch, int minKernelMass = MinKernelMass); +// }; +// +// +// namespace cv +// { +// +// class CV_EXPORTS Octree +// { +// public: +// struct Node +// { +// Node() {} +// int begin, end; +// float x_min, x_max, y_min, y_max, z_min, z_max; +// int maxLevels; +// bool isLeaf; +// int children[8]; +// }; +// +// Octree(); +// Octree( const std::vector& points, int maxLevels = 10, int minPoints = 20 ); +// virtual ~Octree(); +// +// virtual void buildTree( const std::vector& points, int maxLevels = 10, int minPoints = 20 ); +// virtual void getPointsWithinSphere( const Point3f& center, float radius, +// std::vector& points ) const; +// const std::vector& getNodes() const { return nodes; } +// private: +// int minPoints; +// std::vector points; +// std::vector nodes; +// +// virtual void buildNext(size_t node_ind); +// }; +// +// +// class CV_EXPORTS Mesh3D +// { +// public: +// struct EmptyMeshException {}; +// +// Mesh3D(); +// Mesh3D(const std::vector& vtx); +// ~Mesh3D(); +// +// void buildOctree(); +// void clearOctree(); +// float estimateResolution(float tryRatio = 0.1f); +// void computeNormals(float normalRadius, int minNeighbors = 20); +// void computeNormals(const std::vector& subset, float normalRadius, int minNeighbors = 20); +// +// void writeAsVrml(const String& file, const std::vector& colors = std::vector()) const; +// +// std::vector vtx; +// std::vector normals; +// float resolution; +// Octree octree; +// +// const static Point3f allzero; +// }; +// +// class CV_EXPORTS SpinImageModel +// { +// public: +// +// /* model parameters, leave unset for default or auto estimate */ +// float normalRadius; +// int minNeighbors; +// +// float binSize; +// int imageWidth; +// +// float lambda; +// float gamma; +// +// float T_GeometriccConsistency; +// float T_GroupingCorespondances; +// +// /* public interface */ +// SpinImageModel(); +// explicit SpinImageModel(const Mesh3D& mesh); +// ~SpinImageModel(); +// +// void setLogger(std::ostream* log); +// void selectRandomSubset(float ratio); +// void setSubset(const std::vector& subset); +// void compute(); +// +// void match(const SpinImageModel& scene, std::vector< std::vector >& result); +// +// Mat packRandomScaledSpins(bool separateScale = false, size_t xCount = 10, size_t yCount = 10) const; +// +// size_t getSpinCount() const { return spinImages.rows; } +// Mat getSpinImage(size_t index) const { return spinImages.row((int)index); } +// const Point3f& getSpinVertex(size_t index) const { return mesh.vtx[subset[index]]; } +// const Point3f& getSpinNormal(size_t index) const { return mesh.normals[subset[index]]; } +// +// const Mesh3D& getMesh() const { return mesh; } +// Mesh3D& getMesh() { return mesh; } +// +// /* static utility functions */ +// static bool spinCorrelation(const Mat& spin1, const Mat& spin2, float lambda, float& result); +// +// static Point2f calcSpinMapCoo(const Point3f& point, const Point3f& vertex, const Point3f& normal); +// +// static float geometricConsistency(const Point3f& pointScene1, const Point3f& normalScene1, +// const Point3f& pointModel1, const Point3f& normalModel1, +// const Point3f& pointScene2, const Point3f& normalScene2, +// const Point3f& pointModel2, const Point3f& normalModel2); +// +// static float groupingCreteria(const Point3f& pointScene1, const Point3f& normalScene1, +// const Point3f& pointModel1, const Point3f& normalModel1, +// const Point3f& pointScene2, const Point3f& normalScene2, +// const Point3f& pointModel2, const Point3f& normalModel2, +// float gamma); +// protected: +// void defaultParams(); +// +// void matchSpinToModel(const Mat& spin, std::vector& indeces, +// std::vector& corrCoeffs, bool useExtremeOutliers = true) const; +// +// void repackSpinImages(const std::vector& mask, Mat& spinImages, bool reAlloc = true) const; +// +// std::vector subset; +// Mesh3D mesh; +// Mat spinImages; +// std::ostream* out; +// }; +// +// class CV_EXPORTS TickMeter +// { +// public: +// TickMeter(); +// void start(); +// void stop(); +// +// int64 getTimeTicks() const; +// double getTimeMicro() const; +// double getTimeMilli() const; +// double getTimeSec() const; +// int64 getCounter() const; +// +// void reset(); +// private: +// int64 counter; +// int64 sumTime; +// int64 startTime; +// }; +// +// CV_EXPORTS std::ostream& operator<<(std::ostream& out, const TickMeter& tm); +// +// class CV_EXPORTS SelfSimDescriptor +// { +// public: +// SelfSimDescriptor(); +// SelfSimDescriptor(int _ssize, int _lsize, +// int _startDistanceBucket=DEFAULT_START_DISTANCE_BUCKET, +// int _numberOfDistanceBuckets=DEFAULT_NUM_DISTANCE_BUCKETS, +// int _nangles=DEFAULT_NUM_ANGLES); +// SelfSimDescriptor(const SelfSimDescriptor& ss); +// virtual ~SelfSimDescriptor(); +// SelfSimDescriptor& operator = (const SelfSimDescriptor& ss); +// +// size_t getDescriptorSize() const; +// Size getGridSize( Size imgsize, Size winStride ) const; +// +// virtual void compute(const Mat& img, std::vector& descriptors, Size winStride=Size(), +// const std::vector& locations=std::vector()) const; +// virtual void computeLogPolarMapping(Mat& mappingMask) const; +// virtual void SSD(const Mat& img, Point pt, Mat& ssd) const; +// +// int smallSize; +// int largeSize; +// int startDistanceBucket; +// int numberOfDistanceBuckets; +// int numberOfAngles; +// +// enum { DEFAULT_SMALL_SIZE = 5, DEFAULT_LARGE_SIZE = 41, +// DEFAULT_NUM_ANGLES = 20, DEFAULT_START_DISTANCE_BUCKET = 3, +// DEFAULT_NUM_DISTANCE_BUCKETS = 7 }; +// }; +// +// +// typedef bool (*BundleAdjustCallback)(int iteration, double norm_error, void* user_data); +// +// class CV_EXPORTS LevMarqSparse { +// public: +// LevMarqSparse(); +// LevMarqSparse(int npoints, // number of points +// int ncameras, // number of cameras +// int nPointParams, // number of params per one point (3 in case of 3D points) +// int nCameraParams, // number of parameters per one camera +// int nErrParams, // number of parameters in measurement vector +// // for 1 point at one camera (2 in case of 2D projections) +// Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras +// // 1 - point is visible for the camera, 0 - invisible +// Mat& P0, // starting vector of parameters, first cameras then points +// Mat& X, // measurements, in order of visibility. non visible cases are skipped +// TermCriteria criteria, // termination criteria +// +// // callback for estimation of Jacobian matrices +// void (CV_CDECL * fjac)(int i, int j, Mat& point_params, +// Mat& cam_params, Mat& A, Mat& B, void* data), +// // callback for estimation of backprojection errors +// void (CV_CDECL * func)(int i, int j, Mat& point_params, +// Mat& cam_params, Mat& estim, void* data), +// void* data, // user-specific data passed to the callbacks +// BundleAdjustCallback cb, void* user_data +// ); +// +// virtual ~LevMarqSparse(); +// +// virtual void run( int npoints, // number of points +// int ncameras, // number of cameras +// int nPointParams, // number of params per one point (3 in case of 3D points) +// int nCameraParams, // number of parameters per one camera +// int nErrParams, // number of parameters in measurement vector +// // for 1 point at one camera (2 in case of 2D projections) +// Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras +// // 1 - point is visible for the camera, 0 - invisible +// Mat& P0, // starting vector of parameters, first cameras then points +// Mat& X, // measurements, in order of visibility. non visible cases are skipped +// TermCriteria criteria, // termination criteria +// +// // callback for estimation of Jacobian matrices +// void (CV_CDECL * fjac)(int i, int j, Mat& point_params, +// Mat& cam_params, Mat& A, Mat& B, void* data), +// // callback for estimation of backprojection errors +// void (CV_CDECL * func)(int i, int j, Mat& point_params, +// Mat& cam_params, Mat& estim, void* data), +// void* data // user-specific data passed to the callbacks +// ); +// +// virtual void clear(); +// +// // useful function to do simple bundle adjustment tasks +// static void bundleAdjust(std::vector& points, // positions of points in global coordinate system (input and output) +// const std::vector >& imagePoints, // projections of 3d points for every camera +// const std::vector >& visibility, // visibility of 3d points for every camera +// std::vector& cameraMatrix, // intrinsic matrices of all cameras (input and output) +// std::vector& R, // rotation matrices of all cameras (input and output) +// std::vector& T, // translation vector of all cameras (input and output) +// std::vector& distCoeffs, // distortion coefficients of all cameras (input and output) +// const TermCriteria& criteria= +// TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON), +// BundleAdjustCallback cb = 0, void* user_data = 0); +// +// public: +// virtual void optimize(CvMat &_vis); //main function that runs minimization +// +// //iteratively asks for measurement for visible camera-point pairs +// void ask_for_proj(CvMat &_vis,bool once=false); +// //iteratively asks for Jacobians for every camera_point pair +// void ask_for_projac(CvMat &_vis); +// +// CvMat* err; //error X-hX +// double prevErrNorm, errNorm; +// double lambda; +// CvTermCriteria criteria; +// int iters; +// +// CvMat** U; //size of array is equal to number of cameras +// CvMat** V; //size of array is equal to number of points +// CvMat** inv_V_star; //inverse of V* +// +// CvMat** A; +// CvMat** B; +// CvMat** W; +// +// CvMat* X; //measurement +// CvMat* hX; //current measurement extimation given new parameter vector +// +// CvMat* prevP; //current already accepted parameter. +// CvMat* P; // parameters used to evaluate function with new params +// // this parameters may be rejected +// +// CvMat* deltaP; //computed increase of parameters (result of normal system solution ) +// +// CvMat** ea; // sum_i AijT * e_ij , used as right part of normal equation +// // length of array is j = number of cameras +// CvMat** eb; // sum_j BijT * e_ij , used as right part of normal equation +// // length of array is i = number of points +// +// CvMat** Yj; //length of array is i = num_points +// +// CvMat* S; //big matrix of block Sjk , each block has size num_cam_params x num_cam_params +// +// CvMat* JtJ_diag; //diagonal of JtJ, used to backup diagonal elements before augmentation +// +// CvMat* Vis_index; // matrix which element is index of measurement for point i and camera j +// +// int num_cams; +// int num_points; +// int num_err_param; +// int num_cam_param; +// int num_point_param; +// +// //target function and jacobian pointers, which needs to be initialized +// void (*fjac)(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data); +// void (*func)(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data); +// +// void* data; +// +// BundleAdjustCallback cb; +// void* user_data; +// }; +// +// CV_EXPORTS_W int chamerMatching( Mat& img, Mat& templ, +// CV_OUT std::vector >& results, CV_OUT std::vector& cost, +// double templScale=1, int maxMatches = 20, +// double minMatchDistance = 1.0, int padX = 3, +// int padY = 3, int scales = 5, double minScale = 0.6, double maxScale = 1.6, +// double orientationWeight = 0.5, double truncate = 20); +// +// +// class CV_EXPORTS_W StereoVar +// { +// public: +// // Flags +// enum {USE_INITIAL_DISPARITY = 1, USE_EQUALIZE_HIST = 2, USE_SMART_ID = 4, USE_AUTO_PARAMS = 8, USE_MEDIAN_FILTERING = 16}; +// enum {CYCLE_O, CYCLE_V}; +// enum {PENALIZATION_TICHONOV, PENALIZATION_CHARBONNIER, PENALIZATION_PERONA_MALIK}; +// +// //! the default constructor +// CV_WRAP StereoVar(); +// +// //! the full constructor taking all the necessary algorithm parameters +// CV_WRAP StereoVar(int levels, double pyrScale, int nIt, int minDisp, int maxDisp, int poly_n, double poly_sigma, float fi, float lambda, int penalization, int cycle, int flags); +// +// //! the destructor +// virtual ~StereoVar(); +// +// //! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair +// CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, CV_OUT Mat& disp); +// +// CV_PROP_RW int levels; +// CV_PROP_RW double pyrScale; +// CV_PROP_RW int nIt; +// CV_PROP_RW int minDisp; +// CV_PROP_RW int maxDisp; +// CV_PROP_RW int poly_n; +// CV_PROP_RW double poly_sigma; +// CV_PROP_RW float fi; +// CV_PROP_RW float lambda; +// CV_PROP_RW int penalization; +// CV_PROP_RW int cycle; +// CV_PROP_RW int flags; +// +// private: +// void autoParams(); +// void FMG(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level); +// void VCycle_MyFAS(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level); +// void VariationalSolver(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level); +// }; +// +// CV_EXPORTS void polyfit(const Mat& srcx, const Mat& srcy, Mat& dst, int order); +// +// class CV_EXPORTS Directory +// { +// public: +// static std::vector GetListFiles ( const String& path, const String & exten = "*", bool addPath = true ); +// static std::vector GetListFilesR ( const String& path, const String & exten = "*", bool addPath = true ); +// static std::vector GetListFolders( const String& path, const String & exten = "*", bool addPath = true ); +// }; +// +// /* +// * Generation of a set of different colors by the following way: +// * 1) generate more then need colors (in "factor" times) in RGB, +// * 2) convert them to Lab, +// * 3) choose the needed count of colors from the set that are more different from +// * each other, +// * 4) convert the colors back to RGB +// */ +// CV_EXPORTS void generateColors( std::vector& colors, size_t count, size_t factor=100 ); +// +// +// /* +// * Estimate the rigid body motion from frame0 to frame1. The method is based on the paper +// * "Real-Time Visual Odometry from Dense RGB-D Images", F. Steinbucker, J. Strum, D. Cremers, ICCV, 2011. +// */ +// enum { ROTATION = 1, +// TRANSLATION = 2, +// RIGID_BODY_MOTION = 4 +// }; +// CV_EXPORTS bool RGBDOdometry( Mat& Rt, const Mat& initRt, +// const Mat& image0, const Mat& depth0, const Mat& mask0, +// const Mat& image1, const Mat& depth1, const Mat& mask1, +// const Mat& cameraMatrix, float minDepth=0.f, float maxDepth=4.f, float maxDepthDiff=0.07f, +// const std::vector& iterCounts=std::vector(), +// const std::vector& minGradientMagnitudes=std::vector(), +// int transformType=RIGID_BODY_MOTION ); +// +// /** +// *Bilinear interpolation technique. +// * +// *The value of a desired cortical pixel is obtained through a bilinear interpolation of the values +// *of the four nearest neighbouring Cartesian pixels to the center of the RF. +// *The same principle is applied to the inverse transformation. +// * +// *More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5 +// */ +// class CV_EXPORTS LogPolar_Interp +// { +// public: +// +// LogPolar_Interp() {} +// +// /** +// *Constructor +// *\param w the width of the input image +// *\param h the height of the input image +// *\param center the transformation center: where the output precision is maximal +// *\param R the number of rings of the cortical image (default value 70 pixel) +// *\param ro0 the radius of the blind spot (default value 3 pixel) +// *\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle. +// * \a 0 means that the retinal image is computed within the inscribed circle. +// *\param S the number of sectors of the cortical image (default value 70 pixel). +// * Its value is usually internally computed to obtain a pixel aspect ratio equals to 1. +// *\param sp \a 1 (default value) means that the parameter \a S is internally computed. +// * \a 0 means that the parameter \a S is provided by the user. +// */ +// LogPolar_Interp(int w, int h, Point2i center, int R=70, double ro0=3.0, +// int interp=INTER_LINEAR, int full=1, int S=117, int sp=1); +// /** +// *Transformation from Cartesian image to cortical (log-polar) image. +// *\param source the Cartesian image +// *\return the transformed image (cortical image) +// */ +// const Mat to_cortical(const Mat &source); +// /** +// *Transformation from cortical image to retinal (inverse log-polar) image. +// *\param source the cortical image +// *\return the transformed image (retinal image) +// */ +// const Mat to_cartesian(const Mat &source); +// /** +// *Destructor +// */ +// ~LogPolar_Interp(); +// +// protected: +// +// Mat Rsri; +// Mat Csri; +// +// int S, R, M, N; +// int top, bottom,left,right; +// double ro0, romax, a, q; +// int interp; +// +// Mat ETAyx; +// Mat CSIyx; +// +// void create_map(int M, int N, int R, int S, double ro0); +// }; +// +// /** +// *Overlapping circular receptive fields technique +// * +// *The Cartesian plane is divided in two regions: the fovea and the periphery. +// *The fovea (oversampling) is handled by using the bilinear interpolation technique described above, whereas in +// *the periphery we use the overlapping Gaussian circular RFs. +// * +// *More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5 +// */ +// class CV_EXPORTS LogPolar_Overlapping +// { +// public: +// LogPolar_Overlapping() {} +// +// /** +// *Constructor +// *\param w the width of the input image +// *\param h the height of the input image +// *\param center the transformation center: where the output precision is maximal +// *\param R the number of rings of the cortical image (default value 70 pixel) +// *\param ro0 the radius of the blind spot (default value 3 pixel) +// *\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle. +// * \a 0 means that the retinal image is computed within the inscribed circle. +// *\param S the number of sectors of the cortical image (default value 70 pixel). +// * Its value is usually internally computed to obtain a pixel aspect ratio equals to 1. +// *\param sp \a 1 (default value) means that the parameter \a S is internally computed. +// * \a 0 means that the parameter \a S is provided by the user. +// */ +// LogPolar_Overlapping(int w, int h, Point2i center, int R=70, +// double ro0=3.0, int full=1, int S=117, int sp=1); +// /** +// *Transformation from Cartesian image to cortical (log-polar) image. +// *\param source the Cartesian image +// *\return the transformed image (cortical image) +// */ +// const Mat to_cortical(const Mat &source); +// /** +// *Transformation from cortical image to retinal (inverse log-polar) image. +// *\param source the cortical image +// *\return the transformed image (retinal image) +// */ +// const Mat to_cartesian(const Mat &source); +// /** +// *Destructor +// */ +// ~LogPolar_Overlapping(); +// +// protected: +// +// Mat Rsri; +// Mat Csri; +// std::vector Rsr; +// std::vector Csr; +// std::vector Wsr; +// +// int S, R, M, N, ind1; +// int top, bottom,left,right; +// double ro0, romax, a, q; +// +// struct kernel +// { +// kernel() { w = 0; } +// std::vector weights; +// int w; +// }; +// +// Mat ETAyx; +// Mat CSIyx; +// std::vector w_ker_2D; +// +// void create_map(int M, int N, int R, int S, double ro0); +// }; +// +// /** +// * Adjacent receptive fields technique +// * +// *All the Cartesian pixels, whose coordinates in the cortical domain share the same integer part, are assigned to the same RF. +// *The precision of the boundaries of the RF can be improved by breaking each pixel into subpixels and assigning each of them to the correct RF. +// *This technique is implemented from: Traver, V., Pla, F.: Log-polar mapping template design: From task-level requirements +// *to geometry parameters. Image Vision Comput. 26(10) (2008) 1354-1370 +// * +// *More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5 +// */ +// class CV_EXPORTS LogPolar_Adjacent +// { +// public: +// LogPolar_Adjacent() {} +// +// /** +// *Constructor +// *\param w the width of the input image +// *\param h the height of the input image +// *\param center the transformation center: where the output precision is maximal +// *\param R the number of rings of the cortical image (default value 70 pixel) +// *\param ro0 the radius of the blind spot (default value 3 pixel) +// *\param smin the size of the subpixel (default value 0.25 pixel) +// *\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle. +// * \a 0 means that the retinal image is computed within the inscribed circle. +// *\param S the number of sectors of the cortical image (default value 70 pixel). +// * Its value is usually internally computed to obtain a pixel aspect ratio equals to 1. +// *\param sp \a 1 (default value) means that the parameter \a S is internally computed. +// * \a 0 means that the parameter \a S is provided by the user. +// */ +// LogPolar_Adjacent(int w, int h, Point2i center, int R=70, double ro0=3.0, double smin=0.25, int full=1, int S=117, int sp=1); +// /** +// *Transformation from Cartesian image to cortical (log-polar) image. +// *\param source the Cartesian image +// *\return the transformed image (cortical image) +// */ +// const Mat to_cortical(const Mat &source); +// /** +// *Transformation from cortical image to retinal (inverse log-polar) image. +// *\param source the cortical image +// *\return the transformed image (retinal image) +// */ +// const Mat to_cartesian(const Mat &source); +// /** +// *Destructor +// */ +// ~LogPolar_Adjacent(); +// +// protected: +// struct pixel +// { +// pixel() { u = v = 0; a = 0.; } +// int u; +// int v; +// double a; +// }; +// int S, R, M, N; +// int top, bottom,left,right; +// double ro0, romax, a, q; +// std::vector > L; +// std::vector A; +// +// void subdivide_recursively(double x, double y, int i, int j, double length, double smin); +// bool get_uv(double x, double y, int&u, int&v); +// void create_map(int M, int N, int R, int S, double ro0, double smin); +// }; +// +// CV_EXPORTS Mat subspaceProject(InputArray W, InputArray mean, InputArray src); +// CV_EXPORTS Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src); +// +// class CV_EXPORTS LDA +// { +// public: +// // Initializes a LDA with num_components (default 0) and specifies how +// // samples are aligned (default dataAsRow=true). +// LDA(int num_components = 0) : +// _num_components(num_components) {}; +// +// // Initializes and performs a Discriminant Analysis with Fisher's +// // Optimization Criterion on given data in src and corresponding labels +// // in labels. If 0 (or less) number of components are given, they are +// // automatically determined for given data in computation. +// LDA(InputArrayOfArrays src, InputArray labels, +// int num_components = 0) : +// _num_components(num_components) +// { +// this->compute(src, labels); //! compute eigenvectors and eigenvalues +// } +// +// // Serializes this object to a given filename. +// void save(const String& filename) const; +// +// // Deserializes this object from a given filename. +// void load(const String& filename); +// +// // Serializes this object to a given cv::FileStorage. +// void save(FileStorage& fs) const; +// +// // Deserializes this object from a given cv::FileStorage. +// void load(const FileStorage& node); +// +// // Destructor. +// ~LDA() {} +// +// //! Compute the discriminants for data in src and labels. +// void compute(InputArrayOfArrays src, InputArray labels); +// +// // Projects samples into the LDA subspace. +// Mat project(InputArray src); +// +// // Reconstructs projections from the LDA subspace. +// Mat reconstruct(InputArray src); +// +// // Returns the eigenvectors of this LDA. +// Mat eigenvectors() const { return _eigenvectors; }; +// +// // Returns the eigenvalues of this LDA. +// Mat eigenvalues() const { return _eigenvalues; } +// +// protected: +// bool _dataAsRow; +// int _num_components; +// Mat _eigenvectors; +// Mat _eigenvalues; +// +// void lda(InputArrayOfArrays src, InputArray labels); +// }; +// +// class CV_EXPORTS_W FaceRecognizer : public Algorithm +// { +// public: +// //! virtual destructor +// virtual ~FaceRecognizer() {} +// +// // Trains a FaceRecognizer. +// CV_WRAP virtual void train(InputArrayOfArrays src, InputArray labels) = 0; +// +// // Updates a FaceRecognizer. +// CV_WRAP virtual void update(InputArrayOfArrays src, InputArray labels); +// +// // Gets a prediction from a FaceRecognizer. +// virtual int predict(InputArray src) const = 0; +// +// // Predicts the label and confidence for a given sample. +// CV_WRAP virtual void predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) const = 0; +// +// // Serializes this object to a given filename. +// CV_WRAP virtual void save(const String& filename) const; +// +// // Deserializes this object from a given filename. +// CV_WRAP virtual void load(const String& filename); +// +// // Serializes this object to a given cv::FileStorage. +// virtual void save(FileStorage& fs) const = 0; +// +// // Deserializes this object from a given cv::FileStorage. +// virtual void load(const FileStorage& fs) = 0; +// +// }; +// +// CV_EXPORTS_W Ptr createEigenFaceRecognizer(int num_components = 0, double threshold = DBL_MAX); +// CV_EXPORTS_W Ptr createFisherFaceRecognizer(int num_components = 0, double threshold = DBL_MAX); +// CV_EXPORTS_W Ptr createLBPHFaceRecognizer(int radius=1, int neighbors=8, +// int grid_x=8, int grid_y=8, double threshold = DBL_MAX); +// +// enum +// { +// COLORMAP_AUTUMN = 0, +// COLORMAP_BONE = 1, +// COLORMAP_JET = 2, +// COLORMAP_WINTER = 3, +// COLORMAP_RAINBOW = 4, +// COLORMAP_OCEAN = 5, +// COLORMAP_SUMMER = 6, +// COLORMAP_SPRING = 7, +// COLORMAP_COOL = 8, +// COLORMAP_HSV = 9, +// COLORMAP_PINK = 10, +// COLORMAP_HOT = 11 +// }; +// +// CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap); +// +// CV_EXPORTS bool initModule_contrib(); +// } + +implementation + +Uses + ocv.core_c, + ocv.imgproc_c, + ocv.imgproc.types_c; + +{ TCvAdaptiveSkinDetector.THistogram } + +constructor TCvAdaptiveSkinDetector.THistogram.create; +Var + _histogramSize: Integer; + range: TSingleArray1D; + ranges: TSingleArray2D; +begin + _histogramSize := HistogramSize; + range[0] := GSD_HUE_LT; + range[1] := GSD_HUE_UT; + ranges[0] := @range; + fHistogram := cvCreateHist(1, @_histogramSize, CV_HIST_ARRAY, @ranges, 1); + cvClearHist(fHistogram); +end; + +destructor TCvAdaptiveSkinDetector.THistogram.Destroy; +begin + cvReleaseHist(fHistogram); + inherited; +end; + +function TCvAdaptiveSkinDetector.THistogram.findCoverageIndex(surfaceToCover: double; defaultValue: Integer): Integer; +Var + s: double; + i: Integer; +begin + s := 0; + for i := 0 to HistogramSize - 1 do + begin + s := s + cvGetReal1D(fHistogram^.bins, i); + if (s >= surfaceToCover) then + Exit(i); + end; + Result := defaultValue; +end; + +procedure TCvAdaptiveSkinDetector.THistogram.findCurveThresholds(var x1, x2: Integer; percent: double); +Var + sum: double; + i: Integer; +begin + sum := 0; + + for i := 0 to HistogramSize - 1 do + sum := sum + cvGetReal1D(fHistogram^.bins, i); + + x1 := findCoverageIndex(sum * percent, -1); + x2 := findCoverageIndex(sum * (1 - percent), -1); + + if (x1 = -1) then + x1 := GSD_HUE_LT + else + x1 := x1 + GSD_HUE_LT; + + if (x2 = -1) then + x2 := GSD_HUE_UT + else + x2 := x2 + GSD_HUE_LT; +end; + +procedure TCvAdaptiveSkinDetector.THistogram.mergeWith(source: THistogram; weight: double); +Var + myweight, maxVal1, maxVal2, ff1, ff2: Single; + f1, f2: PSingle; + i: Integer; +begin + myweight := 1 - weight; + maxVal1 := 0; + maxVal2 := 0; + cvGetMinMaxHistValue(source.fHistogram, nil, @maxVal2); + if (maxVal2 > 0) then + begin + cvGetMinMaxHistValue(fHistogram, nil, @maxVal1); + if (maxVal1 <= 0) then + begin + for i := 0 to HistogramSize - 1 do + begin + f1 := cvPtr1D(fHistogram^.bins, i); + f2 := cvPtr1D(source.fHistogram^.bins, i); + f1^ := f2^; + end; + end + else + begin + for i := 0 to HistogramSize - 1 do + begin + f1 := cvPtr1D(fHistogram^.bins, i); + f2 := cvPtr1D(source.fHistogram^.bins, i); + + ff1 := (f1^ / maxVal1) * myweight; + if (ff1 < 0) then + ff1 := -ff1; + + ff2 := (f2^ / maxVal2) * weight; + if (ff2 < 0) then + ff2 := -ff2; + f1^ := (ff1 + ff2); + end; + end; + end; +end; + +{ TCvAdaptiveSkinDetector } + +procedure TCvAdaptiveSkinDetector.adaptiveFilter; +begin + +end; + +constructor TCvAdaptiveSkinDetector.create(samplingDivider, morphingMethod: Integer); +begin + nSkinHueLowerBound := GSD_HUE_LT; + nSkinHueUpperBound := GSD_HUE_UT; + + fHistogramMergeFactor := 0.05; // empirical result + fHuePercentCovered := 0.95; // empirical result + + nMorphingMethod := morphingMethod; + nSamplingDivider := samplingDivider; + + nFrameCount := 0; + nStartCounter := 0; + + imgHueFrame := nil; + imgMotionFrame := nil; + imgTemp := nil; + imgFilteredFrame := nil; + imgShrinked := nil; + imgGrayFrame := nil; + imgLastGrayFrame := nil; + imgSaturationFrame := nil; + imgHSVFrame := nil; + + histogramHueMotion := THistogram.create; + skinHueHistogram := THistogram.create; + +end; + +destructor TCvAdaptiveSkinDetector.Destroy; +begin + cvReleaseImage(imgHueFrame); + cvReleaseImage(imgSaturationFrame); + cvReleaseImage(imgMotionFrame); + cvReleaseImage(imgTemp); + cvReleaseImage(imgFilteredFrame); + cvReleaseImage(imgShrinked); + cvReleaseImage(imgGrayFrame); + cvReleaseImage(imgLastGrayFrame); + cvReleaseImage(imgHSVFrame); + histogramHueMotion.Free; + skinHueHistogram.Free; + inherited; +end; + +procedure TCvAdaptiveSkinDetector.initData(src: pIplImage; widthDivider, heightDivider: Integer); +Var + imageSize: TCvSize; +begin + imageSize := cvSize(src^.width div widthDivider, src^.height div heightDivider); + + imgHueFrame := cvCreateImage(imageSize, IPL_DEPTH_8U, 1); + imgShrinked := cvCreateImage(imageSize, IPL_DEPTH_8U, src^.nChannels); + imgSaturationFrame := cvCreateImage(imageSize, IPL_DEPTH_8U, 1); + imgMotionFrame := cvCreateImage(imageSize, IPL_DEPTH_8U, 1); + imgTemp := cvCreateImage(imageSize, IPL_DEPTH_8U, 1); + imgFilteredFrame := cvCreateImage(imageSize, IPL_DEPTH_8U, 1); + imgGrayFrame := cvCreateImage(imageSize, IPL_DEPTH_8U, 1); + imgLastGrayFrame := cvCreateImage(imageSize, IPL_DEPTH_8U, 1); + imgHSVFrame := cvCreateImage(imageSize, IPL_DEPTH_8U, 3); +end; + +procedure TCvAdaptiveSkinDetector.process(inputBGRImage, outputHueMask: pIplImage); +Var + src: pIplImage; + h, v, i, l: Integer; + isInit: Boolean; + pShrinked, pHueFrame, pMotionFrame, pLastGrayFrame, pFilteredFrame, pGrayFrame: PByte; +begin + src := inputBGRImage; + + isInit := false; + + Inc(nFrameCount); + + if (imgHueFrame = nil) then + begin + isInit := true; + initData(src, nSamplingDivider, nSamplingDivider); + end; + + pShrinked := imgShrinked^.imageData; + pHueFrame := imgHueFrame^.imageData; + pMotionFrame := imgMotionFrame^.imageData; + pLastGrayFrame := imgLastGrayFrame^.imageData; + pFilteredFrame := imgFilteredFrame^.imageData; + pGrayFrame := imgGrayFrame^.imageData; + + if (src^.width <> imgHueFrame^.width) or (src^.height <> imgHueFrame^.height) then + begin + cvResize(src, imgShrinked); + cvCvtColor(imgShrinked, imgHSVFrame, CV_BGR2HSV); + end + else + begin + cvCvtColor(src, imgHSVFrame, CV_BGR2HSV); + end; + + cvSplit(imgHSVFrame, imgHueFrame, imgSaturationFrame, imgGrayFrame, 0); + + cvSetZero(imgMotionFrame); + cvSetZero(imgFilteredFrame); + + l := imgHueFrame^.height * imgHueFrame^.width; + + for i := 0 to l - 1 do + begin + v := pGrayFrame^; + if (v >= GSD_INTENSITY_LT) and (v <= GSD_INTENSITY_UT) then + begin + h := pHueFrame^; + if (h >= GSD_HUE_LT) and (h <= GSD_HUE_UT) then + begin + if (h >= nSkinHueLowerBound) and (h <= nSkinHueUpperBound) then + ASD_INTENSITY_SET_PIXEL(pFilteredFrame, h); + + if ASD_IS_IN_MOTION(pLastGrayFrame, v, 7) then + ASD_INTENSITY_SET_PIXEL(pMotionFrame, h); + end; + end; + pShrinked := pShrinked + 3; + Inc(pGrayFrame); + Inc(pLastGrayFrame); + Inc(pMotionFrame); + Inc(pHueFrame); + Inc(pFilteredFrame); + end; + + if (isInit) then + cvCalcHist(imgHueFrame, skinHueHistogram.fHistogram); + + cvCopy(imgGrayFrame, imgLastGrayFrame); + + cvErode(imgMotionFrame, imgTemp); // eliminate disperse pixels, which occur because of the camera noise + cvDilate(imgTemp, imgMotionFrame); + + cvCalcHist(&imgMotionFrame, histogramHueMotion.fHistogram); + + skinHueHistogram.mergeWith(&histogramHueMotion, fHistogramMergeFactor); + + skinHueHistogram.findCurveThresholds(nSkinHueLowerBound, nSkinHueUpperBound, 1 - fHuePercentCovered); + + case nMorphingMethod of + MORPHING_METHOD_ERODE: + begin + cvErode(imgFilteredFrame, imgTemp); + cvCopy(imgTemp, imgFilteredFrame); + end; + MORPHING_METHOD_ERODE_ERODE: + begin + cvErode(imgFilteredFrame, imgTemp); + cvErode(imgTemp, imgFilteredFrame); + end; + MORPHING_METHOD_ERODE_DILATE: + begin + cvErode(imgFilteredFrame, imgTemp); + cvDilate(imgTemp, imgFilteredFrame); + end; + end; + + if (outputHueMask <> nil) then + cvCopy(imgFilteredFrame, outputHueMask); +end; + +procedure ASD_INTENSITY_SET_PIXEL(ptr: PByte; qq: uchar); inline; +begin + // (*pointer) = (unsigned char)qq; + ptr[0] := qq; +end; + +function ASD_IS_IN_MOTION(ptr: PByte; v, threshold: uchar): Boolean; +begin + // ((abs((*(pointer)) - (v)) > (threshold)) ? true : false) + Result := Abs(ptr[0] - v) > threshold; +end; + +end. diff --git a/source/ocv.core.types_c.pas b/source/ocv.core.types_c.pas index bee4d44..1dc904c 100644 --- a/source/ocv.core.types_c.pas +++ b/source/ocv.core.types_c.pas @@ -84,7 +84,6 @@ // ************************************************************************************************* {$I OpenCV.inc} - {$IFDEF DEBUG} {$A8,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O-,P+,Q+,R+,S-,T-,U-,V+,W+,X+,Y+,Z1} {$ELSE} @@ -99,7 +98,6 @@ {$IFDEF VER12P} {$POINTERMATH ON} {$ENDIF} - unit ocv.core.types_c; interface @@ -131,24 +129,23 @@ type CVChar = AnsiChar; {$IFNDEF VER16P} {$IFDEF CLR} - {$IFDEF VER11P} +{$IFDEF VER11P} NativeInt = size_t; NativeUInt = size_t; - {$ELSE} +{$ELSE} NativeInt = Integer; NativeUInt = Cardinal; - {$ENDIF} +{$ENDIF} {$ELSE} - {$IFDEF FPC} +{$IFDEF FPC} NativeInt = SizeInt; NativeUInt = SizeUInt; - {$ELSE} +{$ELSE} NativeInt = Integer; NativeUInt = Cardinal; - {$ENDIF} {$ENDIF} {$ENDIF} - +{$ENDIF} function strdup(const str: pCVChar): pCVChar; function cv_stricmp(const str1, str2: pCVChar): Integer; procedure strcpy(var str1: pCVChar; const str2: pCVChar); overload; @@ -287,8 +284,7 @@ const // CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1; // return rng; // } -function cvRNG(seed: int64 = -1): TCvRNG; {$IFDEF VER9P}inline;{$ENDIF} - +function cvRNG(seed: int64 = -1): TCvRNG; {$IFDEF VER9P}inline; {$ENDIF} (****************************************************************************************\ * Image cType (IplImage) * ****************************************************************************************) @@ -477,14 +473,13 @@ const {$EXTERNALSYM CV_USRTYPE1} CV_MAT_DEPTH_MASK = (CV_DEPTH_MAX - 1); {$EXTERNALSYM CV_MAT_DEPTH_MASK} -function CV_8UC1: Integer; {$IFDEF VER9P}inline;{$ENDIF} - +function CV_8UC1: Integer; {$IFDEF VER9P}inline; {$ENDIF} {$EXTERNALSYM CV_8UC1} (* CV_8UC2 = CV_MAKETYPE(CV_8U, 2); {$EXTERNALSYM CV_8UC2} *) -function CV_8UC3: Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_8UC3: Integer; {$IFDEF VER9P}inline; {$ENDIF} {$EXTERNALSYM CV_8UC3} (* CV_8UC4 = CV_MAKETYPE(CV_8U, 4); @@ -527,8 +522,7 @@ function CV_8UC3: Integer; {$IFDEF VER9P}inline;{$ENDIF} // const // CV_32SC2 = CV_MAKETYPE(CV_32S, 2); {$EXTERNALSYM CV_32SC2} -function CV_32SC2: Integer; {$IFDEF VER9P}inline;{$ENDIF} - +function CV_32SC2: Integer; {$IFDEF VER9P}inline; {$ENDIF} (* const CV_32SC3 = CV_MAKETYPE(CV_32S, 3); @@ -546,9 +540,9 @@ function CV_32SC2: Integer; {$IFDEF VER9P}inline;{$ENDIF} CV_32FC1 = CV_MAKETYPE(CV_32F, 1); {$EXTERNALSYM CV_32FC1} *) -function CV_32FC2: Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_32FC2: Integer; {$IFDEF VER9P}inline; {$ENDIF} {$EXTERNALSYM CV_32FC2} -function CV_32FC3: Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_32FC3: Integer; {$IFDEF VER9P}inline; {$ENDIF} {$EXTERNALSYM CV_32FC3} (* const @@ -560,11 +554,11 @@ function CV_32FC3: Integer; {$IFDEF VER9P}inline;{$ENDIF} CV_32FC(n)CV_MAKETYPE(CV_32F, (n)); *) -function CV_64FC1: Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_64FC1: Integer; {$IFDEF VER9P}inline; {$ENDIF} {$EXTERNALSYM CV_64FC1} -function CV_64FC2: Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_64FC2: Integer; {$IFDEF VER9P}inline; {$ENDIF} {$EXTERNALSYM CV_64FC2} -function CV_64FC3: Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_64FC3: Integer; {$IFDEF VER9P}inline; {$ENDIF} {$EXTERNALSYM CV_64FC3} (* const @@ -578,7 +572,7 @@ function CV_64FC3: Integer; {$IFDEF VER9P}inline;{$ENDIF} // * get reference to pixel at (col,row), // for multi-channel images (col) should be multiplied by number of channels */ -function CV_IMAGE_ELEM(image: pIplImage; size_elemtype, row, col: Integer): Pointer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_IMAGE_ELEM(image: pIplImage; size_elemtype, row, col: Integer): Pointer; {$IFDEF VER9P}inline; {$ENDIF} // (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)]) const @@ -780,7 +774,7 @@ type z: Single; end; -function cvPoint3D32f(const x, y, z: Double): TCvPoint3D32f; {$IFDEF VER9P}inline;{$ENDIF} +function cvPoint3D32f(const x, y, z: Single): TCvPoint3D32f; {$IFDEF VER9P}inline; {$ENDIF} Type TCvPoint2D64f = record @@ -1277,16 +1271,14 @@ const /// / >> Following declaration is a macro definition! // CV_IS_SEQ_CLOSED(seq)(((seq)^.flags and CV_SEQ_FLAG_CLOSED) <> 0); -function CV_IS_SEQ_CLOSED(const Seq: pCvSeq): Boolean; {$IFDEF VER9P}inline;{$ENDIF} - +function CV_IS_SEQ_CLOSED(const Seq: pCvSeq): Boolean; {$IFDEF VER9P}inline; {$ENDIF} /// / >> Following declaration is a macro definition! // const // CV_IS_SEQ_CONVEX(seq)0; // Following declaration is a macro definition! // CV_IS_SEQ_HOLE(seq)(((seq)^.flags and CV_SEQ_FLAG_HOLE) <> 0); -function CV_IS_SEQ_HOLE(const Seq: pCvSeq): Boolean; {$IFDEF VER9P}inline;{$ENDIF} - +function CV_IS_SEQ_HOLE(const Seq: pCvSeq): Boolean; {$IFDEF VER9P}inline; {$ENDIF} /// / >> Following declaration is a macro definition! // const // CV_IS_SEQ_SIMPLE(seq)1; @@ -1370,11 +1362,11 @@ type cvGetSeqElem( (CvSeq*)(seq), (index) ))) } {$IFDEF VER15P} -function CV_SEQ_ELEM(Seq: pCvSeq; const size_of_elem: Integer; index: Integer): Pointer; {$IFDEF VER9P}inline;{$ENDIF} -{#define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )} -function CV_GET_SEQ_ELEM(const size_of_elem: Integer; Seq: pCvSeq; index: Integer): Pointer; {$IFDEF VER9P}inline;{$ENDIF} -{$ENDIF VER15P} +function CV_SEQ_ELEM(Seq: pCvSeq; const size_of_elem: Integer; index: Integer): Pointer; {$IFDEF VER9P}inline; {$ENDIF} +{#define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )} +function CV_GET_SEQ_ELEM(const size_of_elem: Integer; Seq: pCvSeq; index: Integer): Pointer; {$IFDEF VER9P}inline; {$ENDIF} +{$ENDIF VER15P} // (* Add element to sequence: *) // // >> Following declaration is a macro definition! // const CV_WRITE_SEQ_ELEM_VAR(elem_ptr, writer); @@ -1388,8 +1380,7 @@ function CV_GET_SEQ_ELEM(const size_of_elem: Integer; Seq: pCvSeq; index: Intege // Assert((writer).ptr <= (writer).block_max - SizeOf(elem)); // memcpy((writer).ptr, and (elem), SizeOf(elem)); (writer).ptr := mod +SizeOf(elem) then; end; -function CV_CAST_8U(t: Integer): uchar; {$IFDEF VER9P}inline;{$ENDIF} - +function CV_CAST_8U(t: Integer): uchar; {$IFDEF VER9P}inline; {$ENDIF} (* /* Move reader position forward: */ #define CV_NEXT_SEQ_ELEM( elem_size, reader ) \ @@ -1418,7 +1409,8 @@ procedure CV_NEXT_SEQ_ELEM(const elem_size: Integer; const Reader: TCvSeqReader) CV_NEXT_SEQ_ELEM( sizeof(elem), reader ) \ } *) -procedure CV_READ_SEQ_ELEM(const Elem: Pointer; const Reader: TCvSeqReader; const SizeOfElem: Integer); // {$IFDEF VER9P}inline;{$ENDIF} +procedure CV_READ_SEQ_ELEM(const Elem: Pointer; const Reader: TCvSeqReader; const SizeOfElem: Integer); +// {$IFDEF VER9P}inline;{$ENDIF} // (* Read element and move read position backward: *) @@ -1607,7 +1599,7 @@ const {$EXTERNALSYM CV_NODE_TYPE_MASK} // >> Following declaration is a macro definition! // CV_NODE_TYPE(flags)((flags) and CV_NODE_TYPE_MASK); -function CV_NODE_TYPE(const flags: Integer): Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_NODE_TYPE(const flags: Integer): Integer; {$IFDEF VER9P}inline; {$ENDIF} const (*file node flags*) @@ -1620,13 +1612,12 @@ const CV_NODE_NAMED = 64; {$EXTERNALSYM CV_NODE_NAMED} // CV_NODE_IS_INT(flags) (CV_NODE_TYPE(flags) == CV_NODE_INT) -function CV_NODE_IS_INT(const flags: Integer): Boolean; {$IFDEF VER9P}inline;{$ENDIF} +function CV_NODE_IS_INT(const flags: Integer): Boolean; {$IFDEF VER9P}inline; {$ENDIF} // CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) == CV_NODE_REAL) -function CV_NODE_IS_REAL(const flags: Integer): Boolean; {$IFDEF VER9P}inline;{$ENDIF} - +function CV_NODE_IS_REAL(const flags: Integer): Boolean; {$IFDEF VER9P}inline; {$ENDIF} // const CV_NODE_IS_INT(flags)(CV_NODE_TYPE(flags) = CV_NODE_INT) // const CV_NODE_IS_REAL(flags) (CV_NODE_TYPE(flags) = CV_NODE_REAL) -function CV_NODE_IS_STRING(const flags: Integer): Boolean; {$IFDEF VER9P}inline;{$ENDIF} +function CV_NODE_IS_STRING(const flags: Integer): Boolean; {$IFDEF VER9P}inline; {$ENDIF} // (CV_NODE_TYPE(flags) = CV_NODE_STRING) // const CV_NODE_IS_SEQ(flags) (CV_NODE_TYPE(flags) = CV_NODE_SEQ) // const CV_NODE_IS_MAP(flags) (CV_NODE_TYPE(flags) = CV_NODE_MAP) @@ -1725,10 +1716,10 @@ type (* End of file.*) // #define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t)) -procedure CV_SWAP(var a, b, t: pIplImage); {$IFDEF VER9P}inline;{$ENDIF} overload; -procedure CV_SWAP(var a, b, t: pCvPoint2D32f); {$IFDEF VER9P}inline;{$ENDIF} overload; -procedure CV_SWAP(var a, b, t: pCvMat); {$IFDEF VER9P}inline;{$ENDIF} overload; -procedure CV_SWAP(var a, b, t: Pointer); {$IFDEF VER9P}inline;{$ENDIF} overload; +procedure CV_SWAP(var a, b, t: pIplImage); {$IFDEF VER9P}inline; {$ENDIF} overload; +procedure CV_SWAP(var a, b, t: pCvPoint2D32f); {$IFDEF VER9P}inline; {$ENDIF} overload; +procedure CV_SWAP(var a, b, t: pCvMat); {$IFDEF VER9P}inline; {$ENDIF} overload; +procedure CV_SWAP(var a, b, t: Pointer); {$IFDEF VER9P}inline; {$ENDIF} overload; // {$IFNDEF MIN} // {$HPPEMIT '# define MIN(a,b) ((a) > (b) ? (b) : (a))'} @@ -1930,8 +1921,7 @@ procedure CV_SWAP(var a, b, t: Pointer); {$IFDEF VER9P}inline;{$ENDIF} overload; // // const CV_IS_MASK_ARR(mat)(((mat)^.cType and (CV_MAT_TYPE_MASK and ~ CV_8SC1)) = 0) -function CV_ARE_TYPES_EQ(const mat1, mat2: pCvMat): Boolean; {$IFDEF VER9P}inline;{$ENDIF} - +function CV_ARE_TYPES_EQ(const mat1, mat2: pCvMat): Boolean; {$IFDEF VER9P}inline; {$ENDIF} // const CV_ARE_CNS_EQ(mat1, mat2)((((mat1)^.cType xor (mat2)^.cType) and CV_MAT_CN_MASK) = 0) // // const CV_ARE_DEPTHS_EQ(mat1, mat2)((((mat1)^.cType xor (mat2)^.cType) and CV_MAT_DEPTH_MASK) = 0) @@ -2034,12 +2024,9 @@ function cvIplDepth(_type: Integer): Integer; // {$IFDEF VER9P}inline;{$ENDIF} // (* ****************************** CvPoint and variants ********************************** *) -function CvPoint2D32f(x, y: Double): TCvPoint2D32f; {$IFDEF VER9P}inline;{$ENDIF} - -function cvPointTo32f(point: TCvPoint): TCvPoint2D32f; {$IFDEF VER9P}inline;{$ENDIF} - -function cvPointFrom32f(point: TCvPoint2D32f): TCvPoint; {$IFDEF VER9P}inline;{$ENDIF} - +function CvPoint2D32f(x, y: Single): TCvPoint2D32f; {$IFDEF VER9P}inline; {$ENDIF} +function cvPointTo32f(point: TCvPoint): TCvPoint2D32f; {$IFDEF VER9P}inline; {$ENDIF} +function cvPointFrom32f(point: TCvPoint2D32f): TCvPoint; {$IFDEF VER9P}inline; {$ENDIF} // CV_INLINE CvPoint3D32f CvPoint3D32f(Double x, Double y, Double z) // // begin @@ -2116,8 +2103,7 @@ function cvPointFrom32f(point: TCvPoint2D32f): TCvPoint; {$IFDEF VER9P}inline;{$ // return scalar; // } -function cvRealScalar(val0: Double): TCvScalar; {$IFDEF VER9P}inline;{$ENDIF} - +function cvRealScalar(val0: Double): TCvScalar; {$IFDEF VER9P}inline; {$ENDIF} // (*************************************************************************************** *) // (* Dynamic Data structures *) // (*************************************************************************************** *) @@ -2138,8 +2124,7 @@ function cvRealScalar(val0: Double): TCvScalar; {$IFDEF VER9P}inline;{$ENDIF} // (* ********************************** CvTermCriteria ************************************ *) // (* CV_INLINE CvTermCriteria CvTermCriteria(Integer cType, Integer max_iter, Double epsilon) -function CvTermCriteria(_type: Integer; max_iter: Integer; epsilon: Double): TCvTermCriteria; {$IFDEF VER9P}inline;{$ENDIF} - +function CvTermCriteria(_type: Integer; max_iter: Integer; epsilon: Double): TCvTermCriteria; {$IFDEF VER9P}inline; {$ENDIF} (* CV_INLINE int cvFloor( double value ) { @@ -2164,13 +2149,14 @@ function CvTermCriteria(_type: Integer; max_iter: Integer; epsilon: Double): TCv #endif } *) -function cvFloor(value: Double): Integer; {$IFDEF VER9P}inline;{$ENDIF} -function cvScalarAll(val0123: Double): TCvScalar; {$IFDEF VER9P}inline;{$ENDIF} -function CvPoint(const x, y: Integer): TCvPoint; {$IFDEF VER9P}inline;{$ENDIF} -function CvSize(const width, height: Integer): TCvSize; {$IFDEF VER9P}inline;{$ENDIF} -function CvScalar(const val0: Double; const val1: Double = 0; const val2: Double = 0; const val3: Double = 0): TCvScalar; {$IFDEF VER9P}inline;{$ENDIF} -function cvRandInt(Var rng: TCvRNG): Cardinal; {$IFDEF VER9P}inline;{$ENDIF} -function CvRect(Const x, y, width, height: Integer): TCvRect; {$IFDEF VER9P}inline;{$ENDIF} +function cvFloor(value: Double): Integer; {$IFDEF VER9P}inline; {$ENDIF} +function cvScalarAll(val0123: Double): TCvScalar; {$IFDEF VER9P}inline; {$ENDIF} +function CvPoint(const x, y: Integer): TCvPoint; {$IFDEF VER9P}inline; {$ENDIF} +function CvSize(const width, height: Integer): TCvSize; {$IFDEF VER9P}inline; {$ENDIF} +function CvScalar(const val0: Double; const val1: Double = 0; const val2: Double = 0; const val3: Double = 0): TCvScalar; +{$IFDEF VER9P}inline; {$ENDIF} +function cvRandInt(Var rng: TCvRNG): Cardinal; {$IFDEF VER9P}inline; {$ENDIF} +function CvRect(Const x, y, width, height: Integer): TCvRect; {$IFDEF VER9P}inline; {$ENDIF} function cvRound(value: Double): Integer; const @@ -2206,30 +2192,32 @@ function CV_MAT_TYPE(const flags: Integer): Integer; function CV_ELEM_SIZE1(const _type: Integer): Integer; function CV_ELEM_SIZE(const _type: Integer): Integer; function CV_MAT_CN(const flags: Integer): Integer; -function CV_32FC1: Integer; {$IFDEF VER9P}inline;{$ENDIF} -function CV_32SC1: Integer; {$IFDEF VER9P}inline;{$ENDIF} -function CV_MAKETYPE(depth, cn: Integer): Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_32FC1: Integer; {$IFDEF VER9P}inline; {$ENDIF} +function CV_32SC1: Integer; {$IFDEF VER9P}inline; {$ENDIF} +function CV_MAKETYPE(depth, cn: Integer): Integer; {$IFDEF VER9P}inline; {$ENDIF} // #define CV_MAT_ELEM( mat, elemtype, row, col ) // (*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype))) -function CV_MAT_ELEM(const mat: TCvMat; const elemsize: Integer; const row, col: Integer): Pointer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_MAT_ELEM(const mat: TCvMat; const elemsize: Integer; const row, col: Integer): Pointer; {$IFDEF VER9P}inline; {$ENDIF} // #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) // (assert( (unsigned)(row) < (unsigned)(mat).rows && // (unsigned)(col) < (unsigned)(mat).cols ), // (mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col)) -function CV_MAT_ELEM_PTR_FAST(const mat: TCvMat; const row, col, pix_size: Integer): Pointer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_MAT_ELEM_PTR_FAST(const mat: TCvMat; const row, col, pix_size: Integer): Pointer; {$IFDEF VER9P}inline; {$ENDIF} +function iif(const Conditional: Boolean; const ifTrue, ifFalse: Variant): Variant; {$IFDEF VER9P}inline; {$ENDIF} overload; +function iif(const Conditional: Boolean; const ifTrue, ifFalse: Pointer): Pointer; {$IFDEF VER9P}inline; {$ENDIF} overload; -function iif(const Conditional: Boolean; const ifTrue, ifFalse: Variant): Variant; {$IFDEF VER9P}inline;{$ENDIF} overload; -function iif(const Conditional: Boolean; const ifTrue, ifFalse: Pointer): Pointer; {$IFDEF VER9P}inline;{$ENDIF} overload; +function CvBox2D(const cX, cY, width, height, angle: Single): TCvBox2D; +function CvSize2D32f(const width, height: Single): TCvSize2D32f; implementation uses ocv.core_c, - {$IFDEF VER15P} +{$IFDEF VER15P} System.SysUtils; - {$ELSE} - SysUtils; - {$ENDIF VER15P} +{$ELSE} +SysUtils; +{$ENDIF VER15P} function strdup(const str: pCVChar): pCVChar; begin @@ -2383,7 +2371,7 @@ begin Result := Round(value); end; -function iif(const Conditional: Boolean; const ifTrue, ifFalse: Variant): Variant; {$IFDEF VER9P}inline;{$ENDIF} overload; +function iif(const Conditional: Boolean; const ifTrue, ifFalse: Variant): Variant; {$IFDEF VER9P}inline; {$ENDIF} overload; begin if Conditional then Result := ifTrue @@ -2391,7 +2379,7 @@ begin Result := ifFalse; end; -function iif(const Conditional: Boolean; const ifTrue, ifFalse: Pointer): Pointer; {$IFDEF VER9P}inline;{$ENDIF} overload; +function iif(const Conditional: Boolean; const ifTrue, ifFalse: Pointer): Pointer; {$IFDEF VER9P}inline; {$ENDIF} overload; begin if Conditional then Result := ifTrue @@ -2417,12 +2405,13 @@ begin Result := CV_NODE_TYPE(flags) = CV_NODE_REAL; end; -function CV_NODE_IS_STRING(const flags: Integer): Boolean; {$IFDEF VER9P}inline;{$ENDIF} +function CV_NODE_IS_STRING(const flags: Integer): Boolean; {$IFDEF VER9P}inline; {$ENDIF} begin Result := CV_NODE_TYPE(flags) = CV_NODE_STRING end; -procedure CV_READ_SEQ_ELEM(const Elem: Pointer; const Reader: TCvSeqReader; const SizeOfElem: Integer); // {$IFDEF VER9P}inline;{$ENDIF} +procedure CV_READ_SEQ_ELEM(const Elem: Pointer; const Reader: TCvSeqReader; const SizeOfElem: Integer); +// {$IFDEF VER9P}inline;{$ENDIF} begin // assert( (reader).seq->elem_size == sizeof(elem)); Assert(Reader.Seq^.elem_size = SizeOfElem); @@ -2480,7 +2469,7 @@ begin Result.y := y; end; -function cvPoint3D32f(const x, y, z: Double): TCvPoint3D32f; {$IFDEF VER9P}inline;{$ENDIF} +function cvPoint3D32f(const x, y, z: Single): TCvPoint3D32f; {$IFDEF VER9P}inline; {$ENDIF} begin Result.x := x; Result.y := y; @@ -2525,13 +2514,14 @@ begin end; {$IFDEF VER15P} + function CV_GET_SEQ_ELEM; begin {#define CV_GET_SEQ_ELEM( elem_type, seq, index ) CV_SEQ_ELEM( (seq), elem_type, (index) )} Result := CV_SEQ_ELEM(Seq, size_of_elem, index); end; -function CV_SEQ_ELEM(Seq: pCvSeq; const size_of_elem: Integer; index: Integer): Pointer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_SEQ_ELEM(Seq: pCvSeq; const size_of_elem: Integer; index: Integer): Pointer; {$IFDEF VER9P}inline; {$ENDIF} begin // assert(sizeof((seq)->first[0]) == sizeof(CvSeqBlock) && (seq)->elem_size == sizeof(elem_type)) Assert(Assigned(Seq^.first) and (SizeOf(Seq^.first[0]) = SizeOf(TCvSeqBlock)) and (Seq^.elem_size = size_of_elem)); @@ -2545,7 +2535,7 @@ begin end; {$ENDIF VER15P} -function CV_8UC1: Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_8UC1: Integer; {$IFDEF VER9P}inline; {$ENDIF} begin Result := CV_MAKETYPE(CV_8U, 1); end; @@ -2555,7 +2545,7 @@ begin Result := CV_MAKETYPE(CV_32F, 2); end; -function CV_32FC3: Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_32FC3: Integer; {$IFDEF VER9P}inline; {$ENDIF} begin Result := CV_MAKETYPE(CV_32F, 3); end; @@ -2570,7 +2560,7 @@ begin Result := CV_MAKETYPE(CV_64F, 2); end; -function CV_64FC3: Integer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_64FC3: Integer; {$IFDEF VER9P}inline; {$ENDIF} begin Result := CV_MAKETYPE(CV_64F, 3); end; @@ -2586,13 +2576,14 @@ begin Result := Assigned(ptr) and (pCvSetElem(ptr)^.flags >= 0); end; -function CV_IMAGE_ELEM(image: pIplImage; size_elemtype, row, col: Integer): Pointer; {$IFDEF VER9P}inline;{$ENDIF} +function CV_IMAGE_ELEM(image: pIplImage; size_elemtype, row, col: Integer): Pointer; {$IFDEF VER9P}inline; {$ENDIF} begin // (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)]) - Result := {$IFDEF D7}Pointer({$ENDIF D7}{$IFDEF VER9P}pByte{$ELSE}Integer{$ENDIF}(image^.imageData) + image^.widthStep * row + col * size_elemtype{$IFDEF D7}){$ENDIF D7}; + Result := {$IFDEF D7}Pointer({$ENDIF D7}{$IFDEF VER9P}pByte{$ELSE}Integer{$ENDIF}(image^.imageData) + image^.widthStep * row + + col * size_elemtype{$IFDEF D7}){$ENDIF D7}; end; -function cvRealScalar(val0: Double): TCvScalar; {$IFDEF VER9P}inline;{$ENDIF} +function cvRealScalar(val0: Double): TCvScalar; {$IFDEF VER9P}inline; {$ENDIF} begin Result.val[0] := val0; Result.val[1] := 0; @@ -2600,7 +2591,7 @@ begin Result.val[3] := 0; end; -function cvRNG(seed: int64 = -1): TCvRNG; {$IFDEF VER9P}inline;{$ENDIF} +function cvRNG(seed: int64 = -1): TCvRNG; {$IFDEF VER9P}inline; {$ENDIF} begin // CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1; Result := iif(seed > 0, seed, uint64(int64(-1))); @@ -2623,24 +2614,37 @@ begin depth := CV_MAT_DEPTH(_type); Result := CV_ELEM_SIZE1(depth) * 8; if (depth = CV_8S) or (depth = CV_16S) or (depth = CV_32S) then - Result := Result or IPL_DEPTH_SIGN; + Result := Result or Integer(IPL_DEPTH_SIGN); end; -function CV_ARE_TYPES_EQ(const mat1, mat2: pCvMat): Boolean; {$IFDEF VER9P}inline;{$ENDIF} +function CV_ARE_TYPES_EQ(const mat1, mat2: pCvMat): Boolean; {$IFDEF VER9P}inline; {$ENDIF} begin Result := ((((mat1)^._type xor (mat2)^._type) and CV_MAT_TYPE_MASK) = 0); end; -function CV_IS_SEQ_CLOSED(const Seq: pCvSeq): Boolean; {$IFDEF VER9P}inline;{$ENDIF} +function CV_IS_SEQ_CLOSED(const Seq: pCvSeq): Boolean; {$IFDEF VER9P}inline; {$ENDIF} begin Result := (Seq^.flags and CV_SEQ_FLAG_CLOSED) <> 0; end; -function CV_IS_SEQ_HOLE(const Seq: pCvSeq): Boolean; {$IFDEF VER9P}inline;{$ENDIF} +function CV_IS_SEQ_HOLE(const Seq: pCvSeq): Boolean; {$IFDEF VER9P}inline; {$ENDIF} begin Result := (Seq^.flags and CV_SEQ_FLAG_HOLE) <> 0; end; +function CvBox2D(const cX, cY, width, height, angle: Single): TCvBox2D; +begin + Result.center := CvPoint2D32f(cX, cY); + Result.size := CvSize2D32f(width, height); + Result.angle := angle; +end; + +function CvSize2D32f(const width, height: Single): TCvSize2D32f; +begin + Result.width := width; + Result.height := height; +end; + initialization CV_SEQ_ELTYPE_POINT := CV_32SC2;