2013-09-16 13:49:10 +02:00
|
|
|
// ****************************************************************
|
|
|
|
// Delphi-OpenCV Demo
|
|
|
|
// Copyright (C) 2013 Project Delphi-OpenCV
|
|
|
|
// ****************************************************************
|
|
|
|
// Contributor:
|
2014-05-22 22:31:51 +02:00
|
|
|
// Laentir Valetov
|
2013-09-16 13:49:10 +02:00
|
|
|
// email:laex@bk.ru
|
|
|
|
// ****************************************************************
|
|
|
|
// You may retrieve the latest version of this file at the GitHub,
|
|
|
|
// located at git://github.com/Laex/Delphi-OpenCV.git
|
|
|
|
// ****************************************************************
|
|
|
|
// The contents of this file are used with permission, subject to
|
|
|
|
// the Mozilla Public License Version 1.1 (the "License"); you may
|
|
|
|
// not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/MPL-1_1Final.html
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an
|
|
|
|
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
// implied. See the License for the specific language governing
|
|
|
|
// rights and limitations under the License.
|
|
|
|
// ****************************************************************
|
2013-09-12 12:50:55 +02:00
|
|
|
|
2014-05-19 11:56:41 +02:00
|
|
|
{$IFNDEF CLR}
|
|
|
|
{$I OpenCV.inc}
|
2014-06-16 23:38:35 +02:00
|
|
|
unit ocv.comp.View;
|
2014-05-19 11:56:41 +02:00
|
|
|
{$ENDIF}
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2014-09-29 09:12:47 +02:00
|
|
|
{$IFDEF HAS_UNITSCOPE}
|
2014-12-07 23:07:49 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2014-09-29 09:12:47 +02:00
|
|
|
Winapi.Windows, Winapi.Messages,
|
2014-12-07 23:07:49 +01:00
|
|
|
{$ENDIF MSWINDOWS}
|
2013-09-12 12:50:55 +02:00
|
|
|
System.SysUtils,
|
|
|
|
System.Classes,
|
|
|
|
Vcl.Controls,
|
2014-05-19 13:05:37 +02:00
|
|
|
Vcl.Graphics,
|
2014-09-29 11:50:37 +02:00
|
|
|
System.SyncObjs,
|
2014-05-20 17:20:29 +02:00
|
|
|
{$ELSE}
|
2014-12-07 23:07:49 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2014-05-19 11:56:41 +02:00
|
|
|
Windows,
|
2014-12-07 23:07:49 +01:00
|
|
|
{$ENDIF MSWINDOWS}
|
|
|
|
{$IFNDEF FPC}Messages, {$ENDIF FPC}
|
2014-05-19 11:56:41 +02:00
|
|
|
SysUtils,
|
|
|
|
Classes,
|
|
|
|
Controls,
|
2014-05-19 13:05:37 +02:00
|
|
|
Graphics,
|
2014-09-29 11:50:37 +02:00
|
|
|
SyncObjs,
|
2014-09-29 09:12:47 +02:00
|
|
|
{$ENDIF}
|
2014-06-16 23:38:35 +02:00
|
|
|
ocv.comp.Types,
|
2014-09-29 11:50:37 +02:00
|
|
|
ocv.core.types_c;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
type
|
2014-05-06 21:13:57 +02:00
|
|
|
|
2014-05-23 20:12:39 +02:00
|
|
|
TocvViewFrames = class(TOwnedCollection)
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
TocvPersistentRect = class(TPersistent)
|
2014-05-23 20:12:39 +02:00
|
|
|
private
|
|
|
|
FRect: TRect;
|
|
|
|
FOnChange: TNotifyEvent;
|
|
|
|
function GetRect: TRect;
|
|
|
|
procedure SetRect(const Value: TRect);
|
|
|
|
procedure SetRectBottom(const Value: integer);
|
|
|
|
procedure SetRectLeft(const Value: integer);
|
|
|
|
procedure SetRectRight(const Value: integer);
|
|
|
|
procedure SetRectTop(const Value: integer);
|
|
|
|
protected
|
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
|
|
|
public
|
|
|
|
property AsRect: TRect read GetRect Write SetRect;
|
|
|
|
constructor Create; virtual;
|
|
|
|
published
|
|
|
|
property Left: integer read FRect.Left write SetRectLeft;
|
|
|
|
property Top: integer read FRect.Top write SetRectTop;
|
|
|
|
property Right: integer read FRect.Right write SetRectRight;
|
|
|
|
property Bottom: integer read FRect.Bottom write SetRectBottom;
|
|
|
|
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TocvViewFrame = class(TCollectionItem, IocvDataReceiver)
|
|
|
|
private
|
|
|
|
FocvVideoSource: IocvDataSource;
|
|
|
|
FImage: IocvImage;
|
|
|
|
FLock: TCriticalSection;
|
2014-06-16 23:38:35 +02:00
|
|
|
FDrawRect: TocvPersistentRect;
|
2014-05-23 20:12:39 +02:00
|
|
|
FEnabled: Boolean;
|
|
|
|
procedure SetOpenCVVideoSource(const Value: IocvDataSource);
|
|
|
|
function GetImage: IocvImage;
|
|
|
|
function Lock: Boolean;
|
|
|
|
procedure Unlock;
|
|
|
|
protected
|
2014-12-07 23:07:49 +01:00
|
|
|
{ IInterface }
|
2014-05-23 20:12:39 +02:00
|
|
|
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
|
|
|
|
function _AddRef: integer; stdcall;
|
|
|
|
function _Release: integer; stdcall;
|
|
|
|
procedure TakeImage(const IplImage: IocvImage);
|
|
|
|
procedure SetVideoSource(const Value: TObject);
|
|
|
|
public
|
|
|
|
constructor Create(Collection: TCollection); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
property Image: IocvImage read GetImage;
|
|
|
|
published
|
|
|
|
property VideoSource: IocvDataSource Read FocvVideoSource write SetOpenCVVideoSource;
|
2014-06-16 23:38:35 +02:00
|
|
|
property DrawRect: TocvPersistentRect read FDrawRect write FDrawRect;
|
2014-05-23 20:12:39 +02:00
|
|
|
property Enabled: Boolean read FEnabled Write FEnabled default false;
|
|
|
|
end;
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
TocvView = class(TWinControl, IocvDataReceiver)
|
|
|
|
private
|
2013-12-02 19:39:13 +01:00
|
|
|
FocvVideoSource: IocvDataSource;
|
2014-05-15 02:09:58 +02:00
|
|
|
FImage: IocvImage;
|
2014-06-16 23:38:35 +02:00
|
|
|
FOnAfterPaint: TOnOcvAfterViewPaint;
|
2014-05-08 22:52:42 +02:00
|
|
|
FOnBeforePaint: TOnOcvNotify;
|
2014-05-15 02:09:58 +02:00
|
|
|
FCanvas: TCanvas;
|
2014-05-21 19:09:22 +02:00
|
|
|
FStretch: Boolean;
|
|
|
|
FProportional: Boolean;
|
|
|
|
FCenter: Boolean;
|
2014-05-23 20:12:39 +02:00
|
|
|
FFrames: TocvViewFrames;
|
2013-09-12 12:50:55 +02:00
|
|
|
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
|
|
|
|
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
|
2013-12-02 19:39:13 +01:00
|
|
|
procedure SetOpenCVVideoSource(const Value: IocvDataSource);
|
2014-05-15 02:09:58 +02:00
|
|
|
function isSourceEnabled: Boolean;
|
2014-05-21 19:09:22 +02:00
|
|
|
function PaintRect: TRect;
|
2013-09-12 12:50:55 +02:00
|
|
|
protected
|
|
|
|
procedure SetVideoSource(const Value: TObject);
|
2014-05-31 10:45:56 +02:00
|
|
|
procedure TakeImage(const IplImage: IocvImage);
|
2013-09-12 12:50:55 +02:00
|
|
|
public
|
2014-05-15 02:09:58 +02:00
|
|
|
constructor Create(AOwner: TComponent); override;
|
2013-09-12 12:50:55 +02:00
|
|
|
destructor Destroy; override;
|
2014-05-15 02:09:58 +02:00
|
|
|
procedure DrawImage(const IplImage: IocvImage);
|
|
|
|
property Canvas: TCanvas read FCanvas;
|
2014-12-07 23:07:49 +01:00
|
|
|
property Image: IocvImage read FImage;
|
2013-09-12 12:50:55 +02:00
|
|
|
published
|
2013-12-02 19:39:13 +01:00
|
|
|
property VideoSource: IocvDataSource Read FocvVideoSource write SetOpenCVVideoSource;
|
2014-05-23 20:12:39 +02:00
|
|
|
property Proportional: Boolean read FProportional write FProportional default false;
|
2014-05-21 19:09:22 +02:00
|
|
|
property Stretch: Boolean read FStretch write FStretch default True;
|
2014-05-23 20:12:39 +02:00
|
|
|
property Center: Boolean read FCenter write FCenter default false;
|
|
|
|
property Frames: TocvViewFrames Read FFrames Write FFrames;
|
2013-09-12 12:50:55 +02:00
|
|
|
property Align;
|
2014-06-16 23:38:35 +02:00
|
|
|
property OnAfterPaint: TOnOcvAfterViewPaint read FOnAfterPaint write FOnAfterPaint;
|
2014-05-08 22:52:42 +02:00
|
|
|
property OnBeforePaint: TOnOcvNotify read FOnBeforePaint write FOnBeforePaint;
|
2014-05-15 02:09:58 +02:00
|
|
|
property OnEnter;
|
|
|
|
property OnExit;
|
|
|
|
property OnKeyDown;
|
|
|
|
property OnKeyPress;
|
|
|
|
property OnKeyUp;
|
|
|
|
property OnMouseDown;
|
|
|
|
property OnMouseUp;
|
|
|
|
property OnMouseMove;
|
|
|
|
property OnMouseEnter;
|
|
|
|
property OnMouseLeave;
|
|
|
|
property OnMouseWheel;
|
|
|
|
property OnMouseWheelUp;
|
|
|
|
property OnMouseWheelDown;
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2014-05-22 08:53:48 +02:00
|
|
|
uses
|
2015-09-19 21:49:45 +02:00
|
|
|
ocv.utils;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
2014-12-07 23:07:49 +01:00
|
|
|
{ TOpenCVView }
|
2013-09-12 12:50:55 +02:00
|
|
|
|
2014-05-15 02:09:58 +02:00
|
|
|
constructor TocvView.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
FCanvas := TControlCanvas.Create;
|
|
|
|
TControlCanvas(FCanvas).Control := Self;
|
2014-05-21 19:09:22 +02:00
|
|
|
Stretch := True;
|
2014-05-23 20:12:39 +02:00
|
|
|
Proportional := false;
|
|
|
|
Center := false;
|
|
|
|
FFrames := TocvViewFrames.Create(Self, TocvViewFrame);
|
2014-05-15 02:09:58 +02:00
|
|
|
end;
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
destructor TocvView.Destroy;
|
|
|
|
begin
|
|
|
|
if Assigned(FocvVideoSource) then
|
2014-05-06 21:13:57 +02:00
|
|
|
FocvVideoSource.RemoveReceiver(Self);
|
2014-05-15 02:09:58 +02:00
|
|
|
FCanvas.Free;
|
2014-05-23 20:12:39 +02:00
|
|
|
FFrames.Free;
|
2013-09-12 12:50:55 +02:00
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
procedure TocvView.SetOpenCVVideoSource(const Value: IocvDataSource);
|
2013-09-12 12:50:55 +02:00
|
|
|
begin
|
|
|
|
if FocvVideoSource <> Value then
|
|
|
|
begin
|
|
|
|
if Assigned(FocvVideoSource) then
|
2014-05-06 21:13:57 +02:00
|
|
|
FocvVideoSource.RemoveReceiver(Self);
|
2013-09-12 12:50:55 +02:00
|
|
|
FocvVideoSource := Value;
|
|
|
|
if Assigned(FocvVideoSource) then
|
2014-05-06 21:13:57 +02:00
|
|
|
FocvVideoSource.AddReceiver(Self);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvView.SetVideoSource(const Value: TObject);
|
|
|
|
begin
|
|
|
|
VideoSource := Value as TocvDataSource;
|
|
|
|
end;
|
|
|
|
|
2014-05-15 02:09:58 +02:00
|
|
|
procedure TocvView.DrawImage(const IplImage: IocvImage);
|
|
|
|
begin
|
|
|
|
FImage := IplImage;
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
procedure TocvView.TakeImage(const IplImage: IocvImage);
|
2013-09-12 12:50:55 +02:00
|
|
|
begin
|
|
|
|
if not(csDestroying in ComponentState) then
|
2014-05-15 02:09:58 +02:00
|
|
|
DrawImage(IplImage);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
2014-05-21 19:09:22 +02:00
|
|
|
function TocvView.PaintRect: TRect;
|
|
|
|
var
|
2014-05-23 20:12:39 +02:00
|
|
|
ViewWidth, ViewHeight, CliWidth, CliHeight: integer;
|
|
|
|
AspectRatio: Double;
|
|
|
|
begin
|
|
|
|
ViewWidth := FImage.IpImage^.Width;
|
|
|
|
ViewHeight := FImage.IpImage^.Height;
|
|
|
|
CliWidth := ClientWidth;
|
|
|
|
CliHeight := ClientHeight;
|
|
|
|
if (Proportional and ((ViewWidth > CliWidth) or (ViewHeight > CliHeight))) or Stretch then
|
2014-05-21 19:09:22 +02:00
|
|
|
begin
|
2014-05-23 20:12:39 +02:00
|
|
|
if Proportional and (ViewWidth > 0) and (ViewHeight > 0) then
|
2014-05-21 19:09:22 +02:00
|
|
|
begin
|
2014-05-23 20:12:39 +02:00
|
|
|
AspectRatio := ViewWidth / ViewHeight;
|
|
|
|
if ViewWidth > ViewHeight then
|
2014-05-21 19:09:22 +02:00
|
|
|
begin
|
2014-05-23 20:12:39 +02:00
|
|
|
ViewWidth := CliWidth;
|
|
|
|
ViewHeight := Trunc(CliWidth / AspectRatio);
|
|
|
|
if ViewHeight > CliHeight then
|
2014-05-21 19:09:22 +02:00
|
|
|
begin
|
2014-05-23 20:12:39 +02:00
|
|
|
ViewHeight := CliHeight;
|
|
|
|
ViewWidth := Trunc(CliHeight * AspectRatio);
|
2014-05-21 19:09:22 +02:00
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2014-05-23 20:12:39 +02:00
|
|
|
ViewHeight := CliHeight;
|
|
|
|
ViewWidth := Trunc(CliHeight * AspectRatio);
|
|
|
|
if ViewWidth > CliWidth then
|
2014-05-21 19:09:22 +02:00
|
|
|
begin
|
2014-05-23 20:12:39 +02:00
|
|
|
ViewWidth := CliWidth;
|
|
|
|
ViewHeight := Trunc(CliWidth / AspectRatio);
|
2014-05-21 19:09:22 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2014-05-23 20:12:39 +02:00
|
|
|
ViewWidth := CliWidth;
|
|
|
|
ViewHeight := CliHeight;
|
2014-05-21 19:09:22 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
with Result do
|
|
|
|
begin
|
|
|
|
Left := 0;
|
|
|
|
Top := 0;
|
2014-05-23 20:12:39 +02:00
|
|
|
Right := ViewWidth;
|
|
|
|
Bottom := ViewHeight;
|
2014-05-21 19:09:22 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
if Center then
|
2014-05-23 20:12:39 +02:00
|
|
|
OffsetRect(Result, (CliWidth - ViewWidth) div 2, (CliHeight - ViewHeight) div 2);
|
2014-05-21 19:09:22 +02:00
|
|
|
end;
|
|
|
|
|
2014-05-15 02:09:58 +02:00
|
|
|
function TocvView.isSourceEnabled: Boolean;
|
|
|
|
begin
|
|
|
|
Result := (Assigned(VideoSource) and (VideoSource.Enabled)) or Assigned(FImage);
|
|
|
|
end;
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
procedure TocvView.WMEraseBkgnd(var Message: TWMEraseBkgnd);
|
|
|
|
begin
|
2014-05-15 02:09:58 +02:00
|
|
|
if (csDesigning in ComponentState) or (not isSourceEnabled) then
|
2013-09-12 12:50:55 +02:00
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvView.WMPaint(var Message: TWMPaint);
|
2014-05-15 02:09:58 +02:00
|
|
|
Var
|
|
|
|
DC: HDC;
|
|
|
|
lpPaint: TPaintStruct;
|
2014-05-23 20:12:39 +02:00
|
|
|
i: integer;
|
2013-09-12 12:50:55 +02:00
|
|
|
begin
|
2014-05-15 02:09:58 +02:00
|
|
|
if (csDesigning in ComponentState) or (not isSourceEnabled) then
|
2013-09-12 12:50:55 +02:00
|
|
|
inherited
|
|
|
|
else
|
2014-05-15 02:09:58 +02:00
|
|
|
begin
|
|
|
|
if Assigned(FImage) then
|
|
|
|
begin
|
|
|
|
Canvas.Lock;
|
|
|
|
DC := BeginPaint(Handle, lpPaint);
|
|
|
|
try
|
|
|
|
Canvas.Handle := DC;
|
|
|
|
try
|
|
|
|
if Assigned(OnBeforePaint) then
|
|
|
|
OnBeforePaint(Self, FImage);
|
2014-05-21 19:09:22 +02:00
|
|
|
if ipDraw(DC, FImage.IpImage, PaintRect) then
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
|
|
|
for i := 0 to FFrames.Count - 1 do
|
|
|
|
With (FFrames.Items[i] as TocvViewFrame) do
|
2014-12-07 23:07:49 +01:00
|
|
|
{$IFDEF DELPHIXE2_UP}
|
2014-05-23 20:12:39 +02:00
|
|
|
if Enabled and (not DrawRect.AsRect.isEmpty) and Assigned(Image) then
|
2014-12-07 23:07:49 +01:00
|
|
|
{$ELSE}
|
2014-09-29 11:50:37 +02:00
|
|
|
if Enabled and IsRectEmpty(DrawRect.AsRect) and Assigned(Image) then
|
2014-12-07 23:07:49 +01:00
|
|
|
{$ENDIF}
|
2014-05-23 20:12:39 +02:00
|
|
|
ipDraw(DC, Image.IpImage, DrawRect.AsRect);
|
2014-05-20 17:20:29 +02:00
|
|
|
if Assigned(OnAfterPaint) then
|
|
|
|
OnAfterPaint(Self, FImage);
|
2014-05-23 20:12:39 +02:00
|
|
|
end;
|
2014-05-15 02:09:58 +02:00
|
|
|
finally
|
|
|
|
Canvas.Handle := 0;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
EndPaint(Handle, lpPaint);
|
|
|
|
Canvas.Unlock;
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
DefaultHandler(Message);
|
|
|
|
end;
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
2014-12-07 23:07:49 +01:00
|
|
|
{ TocvViewFrame }
|
2014-05-23 20:12:39 +02:00
|
|
|
|
|
|
|
constructor TocvViewFrame.Create(Collection: TCollection);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
FLock := TCriticalSection.Create;
|
2014-06-16 23:38:35 +02:00
|
|
|
FDrawRect := TocvPersistentRect.Create;
|
2014-12-07 23:07:49 +01:00
|
|
|
{$IFDEF DELPHIXE2_UP}
|
2014-05-23 20:12:39 +02:00
|
|
|
FDrawRect.FRect.Width := 50;
|
|
|
|
FDrawRect.FRect.Height := 50;
|
2014-12-07 23:07:49 +01:00
|
|
|
{$ENDIF}
|
2014-05-23 20:12:39 +02:00
|
|
|
FEnabled := false;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TocvViewFrame.Destroy;
|
|
|
|
begin
|
|
|
|
FImage := Nil;
|
|
|
|
FLock.Free;
|
|
|
|
FDrawRect.Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TocvViewFrame.GetImage: IocvImage;
|
|
|
|
begin
|
|
|
|
FLock.Enter;
|
|
|
|
try
|
|
|
|
Result := FImage;
|
|
|
|
finally
|
|
|
|
Unlock;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TocvViewFrame.Lock: Boolean;
|
|
|
|
begin
|
|
|
|
Result := FLock.TryEnter;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TocvViewFrame.QueryInterface(const IID: TGUID; out Obj): HResult;
|
|
|
|
begin
|
|
|
|
if GetInterface(IID, Obj) then
|
|
|
|
Result := 0
|
|
|
|
else
|
|
|
|
Result := E_NOINTERFACE;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvViewFrame.SetOpenCVVideoSource(const Value: IocvDataSource);
|
|
|
|
begin
|
|
|
|
if FocvVideoSource <> Value then
|
|
|
|
begin
|
|
|
|
if Assigned(FocvVideoSource) then
|
|
|
|
FocvVideoSource.RemoveReceiver(Self);
|
|
|
|
FocvVideoSource := Value;
|
|
|
|
if Assigned(FocvVideoSource) then
|
|
|
|
FocvVideoSource.AddReceiver(Self);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvViewFrame.SetVideoSource(const Value: TObject);
|
|
|
|
begin
|
|
|
|
VideoSource := Value as TocvDataSource;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvViewFrame.TakeImage(const IplImage: IocvImage);
|
|
|
|
begin
|
|
|
|
if Lock then
|
|
|
|
try
|
|
|
|
FImage := IplImage;
|
|
|
|
finally
|
|
|
|
Unlock;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvViewFrame.Unlock;
|
|
|
|
begin
|
|
|
|
FLock.Leave;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TocvViewFrame._AddRef: integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TocvViewFrame._Release: integer;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
2014-12-07 23:07:49 +01:00
|
|
|
{ TPersistentRect }
|
2014-05-23 20:12:39 +02:00
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
procedure TocvPersistentRect.AssignTo(Dest: TPersistent);
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
2014-06-16 23:38:35 +02:00
|
|
|
if Dest is TocvPersistentRect then
|
|
|
|
with TocvPersistentRect(Dest) do
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
|
|
|
AsRect := Self.AsRect;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
inherited AssignTo(Dest);
|
|
|
|
end;
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
constructor TocvPersistentRect.Create;
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
FOnChange := nil;
|
|
|
|
end;
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
function TocvPersistentRect.GetRect: TRect;
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
|
|
|
Result := FRect;
|
|
|
|
end;
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
procedure TocvPersistentRect.SetRect(const Value: TRect);
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
|
|
|
FRect.Left := Value.Left;
|
|
|
|
FRect.Top := Value.Top;
|
|
|
|
FRect.Right := Value.Right;
|
|
|
|
FRect.Bottom := Value.Bottom;
|
|
|
|
if Assigned(FOnChange) then
|
|
|
|
FOnChange(Self);
|
|
|
|
end;
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
procedure TocvPersistentRect.SetRectBottom(const Value: integer);
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
|
|
|
FRect.Bottom := Value;
|
|
|
|
if Assigned(FOnChange) then
|
|
|
|
FOnChange(Self);
|
|
|
|
end;
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
procedure TocvPersistentRect.SetRectLeft(const Value: integer);
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
|
|
|
FRect.Left := Value;
|
|
|
|
if Assigned(FOnChange) then
|
|
|
|
FOnChange(Self);
|
|
|
|
end;
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
procedure TocvPersistentRect.SetRectRight(const Value: integer);
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
|
|
|
FRect.Right := Value;
|
|
|
|
if Assigned(FOnChange) then
|
|
|
|
FOnChange(Self);
|
|
|
|
end;
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
procedure TocvPersistentRect.SetRectTop(const Value: integer);
|
2014-05-23 20:12:39 +02:00
|
|
|
begin
|
|
|
|
FRect.Top := Value;
|
|
|
|
if Assigned(FOnChange) then
|
|
|
|
FOnChange(Self);
|
|
|
|
end;
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
end.
|