2013-09-12 12:50:55 +02:00
|
|
|
(* /*****************************************************************
|
|
|
|
// Delphi-OpenCV Demo
|
|
|
|
// Copyright (C) 2013 Project Delphi-OpenCV
|
|
|
|
// ****************************************************************
|
|
|
|
// Contributor:
|
|
|
|
// laentir Valetov
|
|
|
|
// email:laex@bk.ru
|
|
|
|
// ****************************************************************
|
|
|
|
// You may retrieve the latest version of this file at the GitHub,
|
|
|
|
// located at git://github.com/Laex/Delphi-OpenCV.git
|
|
|
|
// ****************************************************************
|
|
|
|
// The contents of this file are used with permission, subject to
|
|
|
|
// the Mozilla Public License Version 1.1 (the "License"); you may
|
|
|
|
// not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/MPL-1_1Final.html
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an
|
|
|
|
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
// implied. See the License for the specific language governing
|
|
|
|
// rights and limitations under the License.
|
|
|
|
******************************************************************* *)
|
|
|
|
|
|
|
|
unit uOCVTypes;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
Uses
|
|
|
|
System.SysUtils,
|
|
|
|
System.Classes,
|
|
|
|
System.SyncObjs,
|
|
|
|
System.Generics.Collections,
|
|
|
|
core.types_c;
|
|
|
|
|
|
|
|
Type
|
|
|
|
IocvDataReceiver = interface
|
|
|
|
['{F67DEC9E-CCE0-49D2-AB9B-AD7E1020C5DC}']
|
|
|
|
procedure TakeImage(const IplImage: pIplImage);
|
|
|
|
procedure SetVideoSource(const Value: TObject);
|
|
|
|
end;
|
|
|
|
|
|
|
|
IocvDataSource = interface
|
|
|
|
['{80640C0A-6828-42F8-83E7-DA5FD9036DFF}']
|
2013-09-16 13:49:10 +02:00
|
|
|
procedure SetReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
TocvReceiverList = TList<IocvDataReceiver>;
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
TocvDataSource = class(TComponent, IocvDataSource)
|
2013-09-12 12:50:55 +02:00
|
|
|
private
|
|
|
|
ReceiverCS: TCriticalSection;
|
|
|
|
protected
|
2013-09-16 13:49:10 +02:00
|
|
|
FOpenCVVideoReceiver: IocvDataReceiver;
|
|
|
|
procedure NotifyReceiver(const IplImage: pIplImage); virtual;
|
2013-09-12 12:50:55 +02:00
|
|
|
public
|
2013-12-02 19:39:13 +01:00
|
|
|
constructor Create(AOwner: TComponent); override;
|
2013-09-12 12:50:55 +02:00
|
|
|
destructor Destroy; override;
|
2013-09-16 13:49:10 +02:00
|
|
|
procedure SetReceiver(const OpenCVVideoReceiver: IocvDataReceiver); virtual;
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
TocvDataReceiver = class(TComponent, IocvDataReceiver)
|
2013-09-12 12:50:55 +02:00
|
|
|
private
|
2013-12-02 19:39:13 +01:00
|
|
|
FocvVideoSource: IocvDataSource;
|
2013-09-16 13:49:10 +02:00
|
|
|
protected
|
|
|
|
procedure TakeImage(const IplImage: pIplImage); virtual;
|
|
|
|
procedure SetVideoSource(const Value: TObject); virtual;
|
2013-12-02 19:39:13 +01:00
|
|
|
procedure SetOpenCVVideoSource(const Value: IocvDataSource); virtual;
|
2013-09-16 13:49:10 +02:00
|
|
|
public
|
|
|
|
destructor Destroy; override;
|
|
|
|
published
|
2013-12-02 19:39:13 +01:00
|
|
|
property VideoSource: IocvDataSource Read FocvVideoSource write SetOpenCVVideoSource;
|
2013-09-16 13:49:10 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
TocvDataSourceAndReceiver = class(TocvDataSource, IocvDataReceiver)
|
|
|
|
private
|
2013-12-02 19:39:13 +01:00
|
|
|
FocvVideoSource: IocvDataSource;
|
2013-09-12 12:50:55 +02:00
|
|
|
protected
|
|
|
|
procedure TakeImage(const IplImage: pIplImage); virtual;
|
|
|
|
procedure SetVideoSource(const Value: TObject); virtual;
|
2013-12-02 19:39:13 +01:00
|
|
|
procedure SetOpenCVVideoSource(const Value: IocvDataSource); virtual;
|
2013-09-16 13:49:10 +02:00
|
|
|
public
|
2013-09-12 12:50:55 +02:00
|
|
|
destructor Destroy; override;
|
|
|
|
published
|
2013-12-02 19:39:13 +01:00
|
|
|
property VideoSource: IocvDataSource Read FocvVideoSource write SetOpenCVVideoSource;
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{ TOpenCVDataSource }
|
|
|
|
|
2013-09-16 13:49:10 +02:00
|
|
|
procedure TocvDataSource.SetReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
|
2013-09-12 12:50:55 +02:00
|
|
|
begin
|
|
|
|
ReceiverCS.Enter;
|
|
|
|
try
|
2013-09-16 13:49:10 +02:00
|
|
|
FOpenCVVideoReceiver := OpenCVVideoReceiver;
|
2013-09-12 12:50:55 +02:00
|
|
|
finally
|
|
|
|
ReceiverCS.Leave;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TocvDataSource.Create(AOwner: TComponent);
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
inherited;
|
2013-09-12 12:50:55 +02:00
|
|
|
ReceiverCS := TCriticalSection.Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TocvDataSource.Destroy;
|
|
|
|
begin
|
|
|
|
ReceiverCS.Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2013-09-16 13:49:10 +02:00
|
|
|
procedure TocvDataSource.NotifyReceiver(const IplImage: pIplImage);
|
2013-09-12 12:50:55 +02:00
|
|
|
begin
|
2013-09-16 13:49:10 +02:00
|
|
|
if Assigned(FOpenCVVideoReceiver) then
|
|
|
|
FOpenCVVideoReceiver.TakeImage(IplImage);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ TOpenCVDataSourceAndReceiver }
|
|
|
|
|
|
|
|
destructor TocvDataSourceAndReceiver.Destroy;
|
|
|
|
begin
|
2013-09-16 13:49:10 +02:00
|
|
|
if Assigned(FocvVideoSource) then
|
|
|
|
FocvVideoSource.SetReceiver(nil);
|
2013-09-12 12:50:55 +02:00
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
procedure TocvDataSourceAndReceiver.SetOpenCVVideoSource(const Value: IocvDataSource);
|
2013-09-12 12:50:55 +02:00
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
if (FocvVideoSource <> Value) then
|
2013-09-12 12:50:55 +02:00
|
|
|
begin
|
|
|
|
if Assigned(FocvVideoSource) then
|
2013-09-16 13:49:10 +02:00
|
|
|
FocvVideoSource.SetReceiver(nil);
|
2013-09-12 12:50:55 +02:00
|
|
|
FocvVideoSource := Value;
|
|
|
|
if Assigned(FocvVideoSource) then
|
2013-09-16 13:49:10 +02:00
|
|
|
FocvVideoSource.SetReceiver(Self);
|
2013-09-12 12:50:55 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvDataSourceAndReceiver.SetVideoSource(const Value: TObject);
|
|
|
|
begin
|
|
|
|
VideoSource := Value as TocvDataSource;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvDataSourceAndReceiver.TakeImage(const IplImage: pIplImage);
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2013-09-16 13:49:10 +02:00
|
|
|
{ TocvDataReceiver }
|
|
|
|
|
|
|
|
destructor TocvDataReceiver.Destroy;
|
|
|
|
begin
|
|
|
|
if Assigned(FocvVideoSource) then
|
|
|
|
FocvVideoSource.SetReceiver(nil);
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
procedure TocvDataReceiver.SetOpenCVVideoSource(const Value: IocvDataSource);
|
2013-09-16 13:49:10 +02:00
|
|
|
begin
|
|
|
|
if (FocvVideoSource <> Value) then
|
|
|
|
begin
|
|
|
|
if Assigned(FocvVideoSource) then
|
|
|
|
FocvVideoSource.SetReceiver(nil);
|
|
|
|
FocvVideoSource := Value;
|
|
|
|
if Assigned(FocvVideoSource) then
|
|
|
|
FocvVideoSource.SetReceiver(Self);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvDataReceiver.SetVideoSource(const Value: TObject);
|
|
|
|
begin
|
|
|
|
VideoSource := Value as TocvDataSource;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TocvDataReceiver.TakeImage(const IplImage: pIplImage);
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
end.
|