mirror of
https://github.com/Laex/Delphi-OpenCV.git
synced 2024-11-15 15:55:53 +01:00
Add TocvRotateOperation
Signed-off-by: Mikhail Grigorev <sleuthhound@gmail.com>
This commit is contained in:
parent
310241ebc5
commit
43cbd0796b
@ -87,7 +87,7 @@ type
|
||||
FResolution: TocvResolution;
|
||||
procedure SetEnabled(const Value: Boolean);
|
||||
procedure SetCameraCaptureSource(const Value: TocvCameraCaptureSource);
|
||||
procedure setResolution(const Value: TocvResolution);
|
||||
procedure SetResolution(const Value: TocvResolution);
|
||||
procedure TerminateCameraThread;
|
||||
procedure ReleaseCamera;
|
||||
procedure SetCameraResolution;
|
||||
@ -101,7 +101,7 @@ type
|
||||
published
|
||||
property Enabled: Boolean Read FEnabled write SetEnabled default False;
|
||||
property CameraCaptureSource: TocvCameraCaptureSource read FCameraCaptureSource write SetCameraCaptureSource default CAP_ANY;
|
||||
property Resolution: TocvResolution read FResolution write setResolution;
|
||||
property Resolution: TocvResolution read FResolution write SetResolution;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -286,7 +286,7 @@ begin
|
||||
cvSetCaptureProperty(FCapture, CV_CAP_PROP_FRAME_HEIGHT, CameraResolution[FResolution].cHeight);
|
||||
end;
|
||||
|
||||
procedure TocvCamera.setResolution(const Value: TocvResolution);
|
||||
procedure TocvCamera.SetResolution(const Value: TocvResolution);
|
||||
begin
|
||||
if FResolution <> Value then
|
||||
begin
|
||||
|
@ -228,6 +228,19 @@ type
|
||||
property Param: Double index 1 Read GetFloatParam write SetFloatParam; // 5;
|
||||
end;
|
||||
|
||||
TocvRotateOperation = class(TocvCustomImageOperation)
|
||||
protected
|
||||
procedure AssignTo(Dest: TPersistent); override;
|
||||
private
|
||||
FAngle: Integer;
|
||||
procedure SetAngle(const Value: Integer);
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
function Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean; override;
|
||||
published
|
||||
property Angle: Integer Read FAngle write SetAngle default 90;
|
||||
end;
|
||||
|
||||
TocvPoint = class(TPersistent)
|
||||
protected
|
||||
procedure AssignTo(Dest: TPersistent); override;
|
||||
@ -1459,6 +1472,69 @@ begin
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
{TocvRotateOperation}
|
||||
|
||||
procedure TocvRotateOperation.AssignTo(Dest: TPersistent);
|
||||
begin
|
||||
if Dest is TocvRotateOperation then
|
||||
begin
|
||||
FAngle := (Dest as TocvRotateOperation).FAngle;
|
||||
end
|
||||
else
|
||||
inherited;
|
||||
end;
|
||||
|
||||
constructor TocvRotateOperation.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited;
|
||||
FAngle := 90;
|
||||
end;
|
||||
|
||||
procedure TocvRotateOperation.SetAngle(const Value: Integer);
|
||||
begin
|
||||
if LockTransform then
|
||||
try
|
||||
FAngle := Value;
|
||||
finally
|
||||
UnlockTransform;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TocvRotateOperation.Transform(const Source: pIplImage; var Destanation: pIplImage): Boolean;
|
||||
Var
|
||||
rot_mat: pCvMat;
|
||||
scale: Double;
|
||||
center: TcvPoint2D32f;
|
||||
D: pIplImage;
|
||||
begin
|
||||
Result := false;
|
||||
if LockTransform then
|
||||
try
|
||||
NotifyGetParams;
|
||||
// Ìàòðèöà òðàíñôîðìàöèè
|
||||
rot_mat := cvCreateMat(2, 3, CV_32FC1);
|
||||
// Âðàùåíèå îòíîñèòåëüíî öåíòðà èçîáðàæåíèÿ
|
||||
center.x := Source^.width div 2;
|
||||
center.y := Source^.height div 2;
|
||||
scale := 1;
|
||||
cv2DRotationMatrix(center, Angle, scale, rot_mat);
|
||||
// Ñîçäàåì èçîáðàæåíèå
|
||||
D := nil;
|
||||
D := cvCreateImage(cvGetSize(Source), Source^.depth, Source^.nChannels);
|
||||
Destanation := cvCreateImage(cvGetSize(Source), Source^.depth, Source^.nChannels);
|
||||
// Âûïîëíÿåì âðàùåíèå
|
||||
cvWarpAffine(Source, D, rot_mat, CV_INTER_LINEAR or CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
|
||||
// Êîïèðóåì èçîáðàæåíèå
|
||||
cvCopy(D, Destanation);
|
||||
// Îñâîáîæäàåì ðåñóðñû
|
||||
cvReleaseImage(D);
|
||||
cvReleaseMat(rot_mat);
|
||||
Result := true;
|
||||
finally
|
||||
UnlockTransform;
|
||||
end;
|
||||
end;
|
||||
|
||||
{TPersistentPoint}
|
||||
|
||||
procedure TocvPoint.AssignTo(Dest: TPersistent);
|
||||
@ -1526,6 +1602,7 @@ GetRegisteredImageOperations.RegisterIOClass(TovcSobelOperation, 'Sobel');
|
||||
GetRegisteredImageOperations.RegisterIOClass(TocvThresholdOperation, 'Threshold');
|
||||
GetRegisteredImageOperations.RegisterIOClass(TocvAdaptiveThresholdOperation, 'AdaptiveThreshold');
|
||||
GetRegisteredImageOperations.RegisterIOClass(TocvContoursOperation, 'Contours');
|
||||
GetRegisteredImageOperations.RegisterIOClass(TocvRotateOperation, 'Rotate');
|
||||
|
||||
finalization
|
||||
|
||||
|
@ -40,7 +40,7 @@ begin
|
||||
RegisterComponents('OpenCV', [TocvImageOperation]);
|
||||
RegisterComponents('OpenCV', [TocvCamera]);
|
||||
RegisterComponents('OpenCV', [TocvView]);
|
||||
RegisterClasses([TocvNoneOperation, TocvGrayScaleOperation, TovcCannyOperation, TovcSmoothOperation, TovcErodeOperation, TovcDilateOperation, TocvLaplaceOperation, TovcSobelOperation, TocvThresholdOperation, TocvAdaptiveThresholdOperation, TocvContoursOperation]);
|
||||
RegisterClasses([TocvNoneOperation, TocvGrayScaleOperation, TovcCannyOperation, TovcSmoothOperation, TovcErodeOperation, TovcDilateOperation, TocvLaplaceOperation, TovcSobelOperation, TocvThresholdOperation, TocvAdaptiveThresholdOperation, TocvContoursOperation, TocvRotateOperation]);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user