2014-02-24 20:18:30 +01:00
|
|
|
|
// *****************************************************************
|
|
|
|
|
// Delphi-OpenCV Demo
|
|
|
|
|
// Copyright (C) 2013 Project Delphi-OpenCV
|
|
|
|
|
// ****************************************************************
|
|
|
|
|
// Contributor:
|
2014-05-22 22:31:51 +02:00
|
|
|
|
// Laentir Valetov
|
2014-02-24 20:18:30 +01: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.Types;
|
2014-05-19 11:56:41 +02:00
|
|
|
|
{$ENDIF}
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
2014-05-22 08:53:48 +02:00
|
|
|
|
uses
|
2014-05-23 11:53:54 +02:00
|
|
|
|
{$IFDEF VER15P}
|
2014-05-30 17:22:53 +02:00
|
|
|
|
WinApi.Windows,
|
2013-09-12 12:50:55 +02:00
|
|
|
|
System.SysUtils,
|
|
|
|
|
System.Classes,
|
|
|
|
|
System.Generics.Collections,
|
2014-05-19 13:05:37 +02:00
|
|
|
|
System.Types,
|
2014-05-18 13:12:14 +02:00
|
|
|
|
Vcl.Graphics,
|
2014-05-21 19:09:22 +02:00
|
|
|
|
{$ELSE}
|
2014-05-30 17:22:53 +02:00
|
|
|
|
Windows,
|
2014-05-19 11:56:41 +02:00
|
|
|
|
SysUtils,
|
|
|
|
|
Classes,
|
|
|
|
|
Graphics,
|
2014-05-21 19:09:22 +02:00
|
|
|
|
{$IFNDEF VER5}Types, {$ENDIF VER5}
|
2014-05-23 11:53:54 +02:00
|
|
|
|
{$ENDIF VER15P}
|
2014-05-30 17:22:53 +02:00
|
|
|
|
ocv.core_c,
|
2014-05-22 16:23:41 +02:00
|
|
|
|
ocv.core.types_c;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
|
|
Type
|
2014-05-30 17:22:53 +02:00
|
|
|
|
|
|
|
|
|
TocvRect = Type TRect;
|
2014-05-31 10:45:56 +02:00
|
|
|
|
|
2014-05-30 17:22:53 +02:00
|
|
|
|
TocvLine = record
|
|
|
|
|
S, E: TCvPoint;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TocvCircle = record
|
|
|
|
|
cX, cY: Integer;
|
|
|
|
|
Radius: Integer;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{$IFDEF VER17P}
|
|
|
|
|
|
|
|
|
|
TocvRects = TArray<TocvRect>;
|
|
|
|
|
TocvCircles = TArray<TocvCircle>;
|
|
|
|
|
TocvLines = TArray<TocvLine>;
|
|
|
|
|
{$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);
|
2014-07-18 22:05:39 +02:00
|
|
|
|
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;
|
2014-05-30 17:22:53 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
IocvImage = interface
|
|
|
|
|
['{84567F57-A399-4179-AA0F-6F8A2788F89B}']
|
|
|
|
|
function GetIplImage: pIplImage;
|
|
|
|
|
function GetisGray: Boolean;
|
|
|
|
|
function GrayImage: IocvImage;
|
|
|
|
|
function Clone: IocvImage;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
function Same: IocvImage;
|
2014-05-18 13:12:14 +02:00
|
|
|
|
function AsBitmap: TBitmap;
|
|
|
|
|
function Crop(const roi: TCvRect): IocvImage;
|
2014-05-28 20:13:29 +02:00
|
|
|
|
function GetWidth: Integer;
|
|
|
|
|
function GetHeight: Integer;
|
2014-05-30 17:22:53 +02:00
|
|
|
|
function GetCanvas: IocvCanvas;
|
|
|
|
|
// -------------------------------------------
|
2014-05-08 22:52:42 +02:00
|
|
|
|
property IpImage: pIplImage Read GetIplImage;
|
2014-05-30 17:22:53 +02:00
|
|
|
|
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);
|
2014-07-18 22:05:39 +02:00
|
|
|
|
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;
|
2014-05-30 17:22:53 +02:00
|
|
|
|
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;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
end;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
TocvImage = class(TInterfacedObject, IocvImage)
|
|
|
|
|
private
|
|
|
|
|
FImage: pIplImage;
|
2014-05-30 17:22:53 +02:00
|
|
|
|
FocvCanvas: IocvCanvas;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
protected
|
|
|
|
|
function GetIplImage: pIplImage;
|
|
|
|
|
function GetisGray: Boolean;
|
2014-05-28 20:13:29 +02:00
|
|
|
|
function GetWidth: Integer;
|
|
|
|
|
function GetHeight: Integer;
|
2014-05-30 17:22:53 +02:00
|
|
|
|
function GetCanvas: IocvCanvas;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
public
|
2014-05-30 17:22:53 +02:00
|
|
|
|
constructor Create; overload;
|
2014-05-18 13:12:14 +02:00
|
|
|
|
constructor Create(const AImage: pIplImage); overload;
|
|
|
|
|
constructor Create(const Bitmap: TBitmap); overload;
|
2014-05-11 02:42:34 +02:00
|
|
|
|
constructor CreateClone(const AImage: pIplImage);
|
2014-05-18 13:12:14 +02:00
|
|
|
|
constructor LoadFormFile(const FileName: String);
|
2014-05-08 22:52:42 +02:00
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
function GrayImage: IocvImage;
|
|
|
|
|
function Clone: IocvImage;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
function Same: IocvImage;
|
2014-05-18 13:12:14 +02:00
|
|
|
|
function AsBitmap: TBitmap;
|
|
|
|
|
function Crop(const roi: TCvRect): IocvImage;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
property IplImage: pIplImage Read GetIplImage;
|
2014-05-30 17:22:53 +02:00
|
|
|
|
property isGray: Boolean Read GetisGray;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-21 19:09:22 +02:00
|
|
|
|
TOnOcvNotifyCollectionItem = procedure(PrevOperation, Operation, NextOperation: TObject; const IplImage: IocvImage;
|
2014-05-22 22:31:51 +02:00
|
|
|
|
Var ContinueTransform: Boolean) of object;
|
2014-05-21 19:09:22 +02:00
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
|
TOnOcvNotify = procedure(Sender: TObject; Var IplImage: IocvImage) of object;
|
|
|
|
|
TOnOcvAfterViewPaint = procedure(Sender: TObject; const IplImage: IocvImage) of object;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
TOnOcvAfterTransform = TOnOcvNotify;
|
2014-07-18 22:05:39 +02:00
|
|
|
|
TOnOcvBeforeTransform = procedure(Sender: TObject; const IplImage: IocvImage; Var ContinueTransform: Boolean)
|
2014-05-08 22:52:42 +02:00
|
|
|
|
of object;
|
2014-07-18 22:05:39 +02:00
|
|
|
|
TOnOcvContour = procedure(Sender: TObject; const IplImage: IocvImage; const ContourCount: Integer;
|
|
|
|
|
const Contours: pCvSeq) of object;
|
2014-05-18 12:36:01 +02:00
|
|
|
|
TOnOcvHaarCascade = procedure(Sender: TObject; const IplImage: IocvImage; const HaarRects: TocvRects) of object;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
TOnOcvRect = procedure(Sender: TObject; const IplImage: IocvImage; const Rect: TocvRect) of object;
|
2014-05-18 12:36:01 +02:00
|
|
|
|
TOnOcvRects = procedure(Sender: TObject; const IplImage: IocvImage; const Rects: TocvRects) of object;
|
2014-05-30 17:22:53 +02:00
|
|
|
|
TOnOcvCircles = procedure(Sender: TObject; const IplImage: IocvImage; const Circles: TocvCircles) of object;
|
|
|
|
|
TOnOcvLines = procedure(Sender: TObject; const IplImage: IocvImage; const Lines: TocvLines) of object;
|
2014-05-11 15:15:21 +02:00
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
IocvDataReceiver = interface
|
|
|
|
|
['{F67DEC9E-CCE0-49D2-AB9B-AD7E1020C5DC}']
|
2014-05-08 22:52:42 +02:00
|
|
|
|
procedure TakeImage(const IplImage: IocvImage);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
procedure SetVideoSource(const Value: TObject);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
IocvDataSource = interface
|
|
|
|
|
['{80640C0A-6828-42F8-83E7-DA5FD9036DFF}']
|
2014-05-06 21:13:57 +02:00
|
|
|
|
procedure AddReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
|
|
|
|
|
procedure RemoveReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
|
2014-05-31 10:45:56 +02:00
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
function GetName: string;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function GetImage: IocvImage;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
function GetEnabled: Boolean;
|
2014-05-31 10:45:56 +02:00
|
|
|
|
function GetHeight: Integer;
|
|
|
|
|
function GetWidth: Integer;
|
|
|
|
|
function GetFPS: double;
|
|
|
|
|
|
2014-05-30 17:22:53 +02:00
|
|
|
|
property Enabled: Boolean Read GetEnabled;
|
2014-05-31 10:45:56 +02:00
|
|
|
|
property Image: IocvImage read GetImage;
|
|
|
|
|
property Name: String read GetName;
|
|
|
|
|
property Width: Integer Read GetWidth;
|
|
|
|
|
property Height: Integer Read GetHeight;
|
|
|
|
|
property FPS: double read GetFPS;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-18 12:36:01 +02:00
|
|
|
|
TocvReceiverList = class(TThreadList) // <IocvDataReceiver>;
|
|
|
|
|
public
|
|
|
|
|
procedure Add(Item: IocvDataReceiver);
|
2014-07-18 22:05:39 +02:00
|
|
|
|
procedure Remove(Item: IocvDataReceiver); {$IFDEF USE_INLINE}inline; {$ENDIF}
|
2014-05-18 12:36:01 +02:00
|
|
|
|
end;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2013-12-02 19:39:13 +01:00
|
|
|
|
TocvDataSource = class(TComponent, IocvDataSource)
|
2013-09-12 12:50:55 +02:00
|
|
|
|
protected
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FOpenCVVideoReceivers: TocvReceiverList;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FImage: IocvImage;
|
2014-05-31 10:45:56 +02:00
|
|
|
|
FWidth, FHeight: Integer;
|
|
|
|
|
FFPS: double;
|
2014-02-24 20:18:30 +01:00
|
|
|
|
function GetName: string; virtual;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
procedure NotifyReceiver(const IplImage: IocvImage); virtual;
|
|
|
|
|
function GetImage: IocvImage;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
function GetEnabled: Boolean; virtual;
|
2014-05-31 10:45:56 +02:00
|
|
|
|
function GetHeight: Integer; virtual;
|
|
|
|
|
function GetWidth: Integer; virtual;
|
|
|
|
|
function GetFPS: double; 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;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
procedure AddReceiver(const OpenCVVideoReceiver: IocvDataReceiver); virtual;
|
|
|
|
|
procedure RemoveReceiver(const OpenCVVideoReceiver: IocvDataReceiver); virtual;
|
2014-05-30 17:22:53 +02:00
|
|
|
|
property Image: IocvImage Read GetImage;
|
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 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
|
2014-05-30 17:22:53 +02:00
|
|
|
|
procedure TakeImage(const IplImage: IocvImage); virtual;
|
2013-09-16 13:49:10 +02:00
|
|
|
|
destructor Destroy; override;
|
2014-05-31 10:45:56 +02:00
|
|
|
|
function isSourceEnabled: Boolean; virtual;
|
2013-09-16 13:49:10 +02:00
|
|
|
|
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 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
|
2014-05-28 20:13:29 +02:00
|
|
|
|
procedure TakeImage(const IplImage: IocvImage); virtual;
|
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;
|
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
|
// Haar cascade types
|
|
|
|
|
TocvHaarCascadeType = (hcEye, hcEyeTreeEyeGlasses, hcFrontalFaceAlt, hcFrontalFaceAlt2, hcFrontalFaceAltTree,
|
|
|
|
|
hcFrontalFaceDefaut, hcFullBody, hcLeftEye2Splits, hcLowerBody, hcMcsEyePairBig, hcMcsEyePairSmall, hcMcsLeftEar,
|
2014-07-18 22:05:39 +02:00
|
|
|
|
hcMcsLeftEye, hcMcsMouth, hcMcsNose, hcMcsRightEar, hcMcsRightEye, hcMcsUpperBody, hcProfileFace, hcRightEye2Splits,
|
|
|
|
|
hcSmile, hcUpperBody, hcPlateNumberRus);
|
2014-06-16 23:38:35 +02:00
|
|
|
|
TocvHaarCascadeFlag = (HAAR_DO_CANNY_PRUNING, HAAR_SCALE_IMAGE, HAAR_FIND_BIGGEST_OBJECT, HAAR_DO_ROUGH_SEARCH);
|
|
|
|
|
TocvHaarCascadeFlagSet = set of TocvHaarCascadeFlag;
|
|
|
|
|
|
|
|
|
|
function HaarSetToFlag(const CascadeFlags: TocvHaarCascadeFlagSet): Integer;
|
|
|
|
|
|
2014-05-15 02:09:58 +02:00
|
|
|
|
function ocvRect(Left, Top, Right, Bottom: Integer): TocvRect;
|
2014-05-21 19:09:22 +02:00
|
|
|
|
function ocvRectCenter(cX, cY, Width, Height: Integer): TocvRect;
|
2014-06-16 23:38:35 +02:00
|
|
|
|
function cvRect(const oRect: TocvRect): TCvRect;
|
2014-05-15 02:09:58 +02:00
|
|
|
|
|
2014-05-30 17:22:53 +02:00
|
|
|
|
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);
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
implementation
|
|
|
|
|
|
2014-06-16 23:38:35 +02:00
|
|
|
|
uses
|
|
|
|
|
ocv.imgproc_c,
|
|
|
|
|
ocv.imgproc.types_c,
|
2014-07-18 22:05:39 +02:00
|
|
|
|
ocv.highgui_c, ocv.cvutils;
|
2014-06-16 23:38:35 +02:00
|
|
|
|
|
|
|
|
|
function cvRect(const oRect: TocvRect): TCvRect;
|
|
|
|
|
begin
|
|
|
|
|
Result := ocv.core.types_c.cvRect(oRect.Left, oRect.Top, oRect.Width, oRect.Height);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function HaarSetToFlag(const CascadeFlags: TocvHaarCascadeFlagSet): Integer;
|
|
|
|
|
Var
|
|
|
|
|
i: TocvHaarCascadeFlag;
|
|
|
|
|
j: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := 0;
|
|
|
|
|
j := 1;
|
|
|
|
|
for i := HAAR_DO_CANNY_PRUNING to HAAR_DO_ROUGH_SEARCH do
|
|
|
|
|
begin
|
|
|
|
|
if i in CascadeFlags then
|
|
|
|
|
Result := Result or j;
|
|
|
|
|
j := j * 2;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
|
2014-05-15 02:09:58 +02:00
|
|
|
|
function ocvRect(Left, Top, Right, Bottom: Integer): TocvRect;
|
|
|
|
|
begin
|
|
|
|
|
Result.Left := Left;
|
|
|
|
|
Result.Top := Top;
|
|
|
|
|
Result.Bottom := Bottom;
|
|
|
|
|
Result.Right := Right;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-21 19:09:22 +02:00
|
|
|
|
function ocvRectCenter(cX, cY, Width, Height: Integer): TocvRect;
|
|
|
|
|
begin
|
|
|
|
|
Result.Left := cX - (Width div 2);
|
|
|
|
|
Result.Right := cX + (Width div 2);
|
|
|
|
|
Result.Top := cY - (Height div 2);
|
|
|
|
|
Result.Bottom := cY + (Height div 2);
|
|
|
|
|
end;
|
|
|
|
|
|
2014-07-18 22:05:39 +02:00
|
|
|
|
{ TOpenCVDataSource }
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
2014-05-06 21:13:57 +02:00
|
|
|
|
procedure TocvDataSource.AddReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FOpenCVVideoReceivers.Add(OpenCVVideoReceiver);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TocvDataSource.Create(AOwner: TComponent);
|
|
|
|
|
begin
|
2013-12-02 19:39:13 +01:00
|
|
|
|
inherited;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FOpenCVVideoReceivers := TocvReceiverList.Create;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvDataSource.Destroy;
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FOpenCVVideoReceivers.Free;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FImage := nil;
|
2013-09-12 12:50:55 +02:00
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-15 02:09:58 +02:00
|
|
|
|
function TocvDataSource.GetEnabled: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-31 10:45:56 +02:00
|
|
|
|
function TocvDataSource.GetFPS: double;
|
|
|
|
|
begin
|
|
|
|
|
Result := FFPS;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvDataSource.GetHeight: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := FHeight;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvDataSource.GetImage: IocvImage;
|
2014-05-07 13:14:32 +02:00
|
|
|
|
begin
|
|
|
|
|
Result := FImage;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-02-24 20:18:30 +01:00
|
|
|
|
function TocvDataSource.GetName: string;
|
|
|
|
|
begin
|
|
|
|
|
Result := Name;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-31 10:45:56 +02:00
|
|
|
|
function TocvDataSource.GetWidth: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := FWidth;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
procedure TocvDataSource.NotifyReceiver(const IplImage: IocvImage);
|
2014-05-06 21:13:57 +02:00
|
|
|
|
Var
|
2014-05-30 17:22:53 +02:00
|
|
|
|
r: Pointer; // IocvDataReceiver;
|
2014-05-18 13:12:14 +02:00
|
|
|
|
LockList: TList; // <IocvDataReceiver>;
|
2014-05-06 21:13:57 +02:00
|
|
|
|
begin
|
|
|
|
|
LockList := FOpenCVVideoReceivers.LockList;
|
|
|
|
|
try
|
2014-05-30 17:22:53 +02:00
|
|
|
|
for r in LockList do
|
|
|
|
|
IocvDataReceiver(r).TakeImage(IplImage);
|
2014-05-06 21:13:57 +02:00
|
|
|
|
finally
|
|
|
|
|
FOpenCVVideoReceivers.UnlockList;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvDataSource.RemoveReceiver(const OpenCVVideoReceiver: IocvDataReceiver);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FOpenCVVideoReceivers.Remove(OpenCVVideoReceiver);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-07-18 22:05:39 +02:00
|
|
|
|
{ TOpenCVDataSourceAndReceiver }
|
2013-09-12 12:50:55 +02:00
|
|
|
|
|
|
|
|
|
destructor TocvDataSourceAndReceiver.Destroy;
|
|
|
|
|
begin
|
2013-09-16 13:49:10 +02:00
|
|
|
|
if Assigned(FocvVideoSource) then
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FocvVideoSource.RemoveReceiver(Self);
|
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
|
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 TocvDataSourceAndReceiver.SetVideoSource(const Value: TObject);
|
|
|
|
|
begin
|
|
|
|
|
VideoSource := Value as TocvDataSource;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
procedure TocvDataSourceAndReceiver.TakeImage(const IplImage: IocvImage);
|
2013-09-12 12:50:55 +02:00
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
2014-07-18 22:05:39 +02:00
|
|
|
|
{ TocvDataReceiver }
|
2013-09-16 13:49:10 +02:00
|
|
|
|
|
|
|
|
|
destructor TocvDataReceiver.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FocvVideoSource) then
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FocvVideoSource.RemoveReceiver(Self);
|
2013-09-16 13:49:10 +02:00
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-31 10:45:56 +02:00
|
|
|
|
function TocvDataReceiver.isSourceEnabled: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := Assigned(VideoSource) and VideoSource.Enabled;
|
|
|
|
|
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
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FocvVideoSource.RemoveReceiver(Self);
|
2013-09-16 13:49:10 +02:00
|
|
|
|
FocvVideoSource := Value;
|
|
|
|
|
if Assigned(FocvVideoSource) then
|
2014-05-06 21:13:57 +02:00
|
|
|
|
FocvVideoSource.AddReceiver(Self);
|
2013-09-16 13:49:10 +02:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvDataReceiver.SetVideoSource(const Value: TObject);
|
|
|
|
|
begin
|
2014-05-06 21:13:57 +02:00
|
|
|
|
if (Value <> Self) then
|
|
|
|
|
VideoSource := Value as TocvDataSource;
|
2013-09-16 13:49:10 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
procedure TocvDataReceiver.TakeImage(const IplImage: IocvImage);
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
2014-07-18 22:05:39 +02:00
|
|
|
|
{ TocvImage }
|
2014-05-08 22:52:42 +02:00
|
|
|
|
|
2014-05-18 13:12:14 +02:00
|
|
|
|
function TocvImage.AsBitmap: TBitmap;
|
|
|
|
|
var
|
|
|
|
|
deep: Integer;
|
|
|
|
|
i, j, K, wStep, Channels: Integer;
|
|
|
|
|
data: PByteArray;
|
|
|
|
|
pb: PByteArray;
|
|
|
|
|
begin
|
|
|
|
|
if (FImage <> NIL) then
|
|
|
|
|
begin
|
|
|
|
|
Result := TBitmap.Create;
|
|
|
|
|
Result.Width := FImage^.Width;
|
|
|
|
|
Result.Height := FImage^.Height;
|
|
|
|
|
deep := FImage^.nChannels * FImage^.depth;
|
|
|
|
|
case deep of
|
|
|
|
|
8:
|
|
|
|
|
Result.PixelFormat := pf8bit;
|
|
|
|
|
16:
|
|
|
|
|
Result.PixelFormat := pf16bit;
|
|
|
|
|
24:
|
|
|
|
|
Result.PixelFormat := pf24bit;
|
|
|
|
|
32:
|
|
|
|
|
Result.PixelFormat := pf32bit;
|
|
|
|
|
End;
|
2014-07-18 22:05:39 +02:00
|
|
|
|
if not ipDraw(Result.Canvas.Handle, FImage, Rect(0, 0, FImage^.Width - 1, FImage^.Height - 1), False) then
|
|
|
|
|
FreeAndNil(Result);
|
|
|
|
|
{
|
|
|
|
|
wStep := FImage^.WidthStep;
|
|
|
|
|
Channels := FImage^.nChannels;
|
|
|
|
|
data := Pointer(FImage^.imageData);
|
|
|
|
|
for i := 0 to FImage^.Height - 1 do
|
|
|
|
|
begin
|
2014-05-18 13:12:14 +02:00
|
|
|
|
pb := Result.Scanline[i];
|
|
|
|
|
for j := 0 to FImage^.Width - 1 do
|
2014-07-18 22:05:39 +02:00
|
|
|
|
for K := 0 to Channels - 1 do
|
|
|
|
|
pb[Channels * j + K] := data[i * wStep + j * Channels + K]
|
|
|
|
|
End; }
|
2014-05-18 13:12:14 +02:00
|
|
|
|
End
|
|
|
|
|
else
|
|
|
|
|
Result := NIL;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvImage.Clone: IocvImage;
|
|
|
|
|
begin
|
2014-05-11 02:42:34 +02:00
|
|
|
|
Result := TocvImage.CreateClone(FImage);
|
2014-05-08 22:52:42 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TocvImage.Create(const AImage: pIplImage);
|
|
|
|
|
begin
|
2014-05-30 17:22:53 +02:00
|
|
|
|
Create;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FImage := AImage;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-18 13:12:14 +02:00
|
|
|
|
constructor TocvImage.Create(const Bitmap: TBitmap);
|
|
|
|
|
Var
|
|
|
|
|
bitmapData: PByte;
|
|
|
|
|
begin
|
2014-05-30 17:22:53 +02:00
|
|
|
|
Create;
|
2014-07-18 22:05:39 +02:00
|
|
|
|
Assert(Assigned(Bitmap) and (Bitmap.Width > 0) and (Bitmap.Height > 0));
|
2014-05-18 13:12:14 +02:00
|
|
|
|
Assert(Bitmap.PixelFormat = pf24bit, 'only 24bit'); // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - IPL_DEPTH_8U, 3
|
|
|
|
|
bitmapData := Bitmap.Scanline[0];
|
|
|
|
|
FImage := cvCreateImage(cvSize(Bitmap.Width, Bitmap.Height), IPL_DEPTH_8U, 3);
|
|
|
|
|
Move(bitmapData^, FImage^.imageData^, FImage^.imageSize);
|
|
|
|
|
FImage^.imageDataOrigin := nil;
|
|
|
|
|
FImage^.imageId := nil;
|
|
|
|
|
FImage^.maskROI := nil;
|
|
|
|
|
FImage^.roi := nil;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-30 17:22:53 +02:00
|
|
|
|
constructor TocvImage.Create;
|
|
|
|
|
begin
|
|
|
|
|
FocvCanvas := TocvCanvas.Create(Self);
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 02:42:34 +02:00
|
|
|
|
constructor TocvImage.CreateClone(const AImage: pIplImage);
|
2014-05-08 22:52:42 +02:00
|
|
|
|
begin
|
2014-05-30 17:22:53 +02:00
|
|
|
|
Create;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
FImage := cvCloneImage(AImage);
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-18 13:12:14 +02:00
|
|
|
|
function TocvImage.Crop(const roi: TCvRect): IocvImage;
|
|
|
|
|
Var
|
|
|
|
|
CropIplImage: pIplImage;
|
|
|
|
|
begin
|
|
|
|
|
CropIplImage := cvCreateImage(cvSize(roi.Width, roi.Height), FImage^.depth, FImage^.nChannels);
|
|
|
|
|
cvSetImageROI(FImage, roi);
|
|
|
|
|
cvCopyImage(FImage, CropIplImage);
|
|
|
|
|
cvResetImageROI(FImage);
|
|
|
|
|
Result := TocvImage.Create(CropIplImage);
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
destructor TocvImage.Destroy;
|
|
|
|
|
begin
|
2014-05-30 17:22:53 +02:00
|
|
|
|
// FocvCanvas.Free;
|
2014-05-08 22:52:42 +02:00
|
|
|
|
cvReleaseImage(FImage);
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-30 17:22:53 +02:00
|
|
|
|
function TocvImage.GetCanvas: IocvCanvas;
|
|
|
|
|
begin
|
|
|
|
|
Result := FocvCanvas as IocvCanvas;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-28 20:13:29 +02:00
|
|
|
|
function TocvImage.GetHeight: Integer;
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FImage) then
|
|
|
|
|
Result := FImage^.Height
|
|
|
|
|
else
|
|
|
|
|
Result := 0;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvImage.GetIplImage: pIplImage;
|
2013-09-16 13:49:10 +02:00
|
|
|
|
begin
|
2014-05-08 22:52:42 +02:00
|
|
|
|
Result := FImage;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TocvImage.GetisGray: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := FImage^.nChannels = 1;
|
|
|
|
|
end;
|
2013-09-16 13:49:10 +02:00
|
|
|
|
|
2014-05-28 20:13:29 +02:00
|
|
|
|
function TocvImage.GetWidth: Integer;
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FImage) then
|
|
|
|
|
Result := FImage^.Width
|
|
|
|
|
else
|
|
|
|
|
Result := 0;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-08 22:52:42 +02:00
|
|
|
|
function TocvImage.GrayImage: IocvImage;
|
|
|
|
|
Var
|
|
|
|
|
iImage: pIplImage;
|
|
|
|
|
begin
|
|
|
|
|
if isGray then
|
|
|
|
|
Result := Self
|
|
|
|
|
else
|
|
|
|
|
begin
|
|
|
|
|
iImage := cvCreateImage(cvGetSize(FImage), IPL_DEPTH_8U, 1);
|
|
|
|
|
cvCvtColor(FImage, iImage, CV_RGB2GRAY);
|
|
|
|
|
Result := TocvImage.Create(iImage);
|
|
|
|
|
end;
|
2013-09-16 13:49:10 +02:00
|
|
|
|
end;
|
|
|
|
|
|
2014-05-18 13:12:14 +02:00
|
|
|
|
constructor TocvImage.LoadFormFile(const FileName: String);
|
|
|
|
|
begin
|
|
|
|
|
FImage := cvLoadImage(PAnsiChar(AnsiString(FileName)));
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-11 15:15:21 +02:00
|
|
|
|
function TocvImage.Same: IocvImage;
|
|
|
|
|
begin
|
|
|
|
|
Result := TocvImage.Create(cvCreateImage(cvGetSize(FImage), FImage^.depth, FImage^.nChannels));
|
|
|
|
|
end;
|
|
|
|
|
|
2014-07-18 22:05:39 +02:00
|
|
|
|
{ TocvReceiverList }
|
2014-05-18 12:36:01 +02:00
|
|
|
|
|
|
|
|
|
procedure TocvReceiverList.Add(Item: IocvDataReceiver);
|
|
|
|
|
begin
|
|
|
|
|
inherited Add(Pointer(Item));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TocvReceiverList.Remove(Item: IocvDataReceiver);
|
|
|
|
|
begin
|
|
|
|
|
inherited Remove(Pointer(Item));
|
|
|
|
|
end;
|
|
|
|
|
|
2014-05-30 17:22:53 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2014-07-18 22:05:39 +02:00
|
|
|
|
{ TocvCanvas }
|
2014-05-30 17:22:53 +02:00
|
|
|
|
|
|
|
|
|
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
|
2014-07-18 22:05:39 +02:00
|
|
|
|
cvCircle(FOwner.FImage, cvPoint(CenterX, CenterY), Radius, ColorToCvRGB(Color), Thickness,
|
|
|
|
|
cLineType[LineType], Shift);
|
2014-05-30 17:22:53 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TocvCanvas.Create(AOwner: TocvImage);
|
|
|
|
|
begin
|
|
|
|
|
FOwner := AOwner;
|
|
|
|
|
FocvFont := TocvFont.Create;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TocvCanvas.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
// FocvFont.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2014-07-18 22:05:39 +02:00
|
|
|
|
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);
|
2014-05-30 17:22:53 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2014-07-18 22:05:39 +02:00
|
|
|
|
procedure TocvCanvas.EllipseBox(const Box: TCvBox2D; const Color: TColor; const Thickness: Integer;
|
|
|
|
|
const LineType: TocvLineType; const Shift: Integer);
|
2014-05-30 17:22:53 +02:00
|
|
|
|
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
|
2014-07-18 22:05:39 +02:00
|
|
|
|
cvRectangle(FOwner.FImage, cvPoint(x1, y1), cvPoint(x2, y2), ColorToCvRGB(Color), Thickness,
|
|
|
|
|
cLineType[LineType], Shift);
|
2014-05-30 17:22:53 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2014-07-18 22:05:39 +02:00
|
|
|
|
{ TocvFont }
|
2014-05-30 17:22:53 +02:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2013-09-12 12:50:55 +02:00
|
|
|
|
end.
|