mirror of
https://github.com/Laex/Delphi-OpenCV.git
synced 2024-11-16 00:05:52 +01:00
Components...
Signed-off-by: Laentir Valetov <laex@bk.ru>
This commit is contained in:
parent
518b549fb2
commit
b29888306b
33
README.md
33
README.md
@ -1,28 +1,26 @@
|
|||||||
###Delphi-OpenCV
|
###Delphi-OpenCV
|
||||||
|
----------
|
||||||
* OpenCV version - 2.4.9<br>
|
* OpenCV version - 2.4.9<br>
|
||||||
* Development environment - Delphi XE2-XE6<br>
|
* Development environment - Delphi XE2-XE6<br>
|
||||||
|
|
||||||
|
----------
|
||||||
#####Contributors:
|
#####Contributors:
|
||||||
```
|
```
|
||||||
Laentir Valetov
|
Laentir Valetov (email: laex@bk.ru)
|
||||||
email: laex@bk.ru
|
Mikhail Grigorev (email: sleuthhound@gmail.com)
|
||||||
|
|
||||||
Mikhail Grigorev
|
|
||||||
email: sleuthhound@gmail.com
|
|
||||||
```
|
```
|
||||||
####How to install:
|
####How to install:
|
||||||
1.Download the archive ```https://github.com/Laex/Delphi-OpenCV/archive/master.zip```<br>
|
Download the archive [link][1].<br>
|
||||||
2.Unzip it to a convenient directory, thus get the following directory structure
|
Unzip it to a convenient directory, thus get the following directory structure.<br>
|
||||||
|
|
||||||
```
|
```
|
||||||
<Directory, such as 'C:\OpenCV\' - <PROJECT_ROOT>>
|
<PROJECT_ROOT> - Directory, such as "C:\OpenCV\"
|
||||||
<bin>
|
<bin>
|
||||||
<component>
|
<component>
|
||||||
<include>
|
<include>
|
||||||
<opencv_classes>
|
<opencv_classes>
|
||||||
<samples>
|
<samples>
|
||||||
```
|
```
|
||||||
3.Add the search path for the modules of the project in Delphi IDE (Tools-Options-Delphi Options-Library-Library path)
|
Add the search path for the modules of the project in Delphi IDE (Tools-Options-Delphi Options-Library-Library path)
|
||||||
```
|
```
|
||||||
<PROJECT_ROOT>\include
|
<PROJECT_ROOT>\include
|
||||||
<PROJECT_ROOT>\include\calib3d
|
<PROJECT_ROOT>\include\calib3d
|
||||||
@ -40,8 +38,7 @@ email: sleuthhound@gmail.com
|
|||||||
<PROJECT_ROOT>\include\video
|
<PROJECT_ROOT>\include\video
|
||||||
<PROJECT_ROOT>\component
|
<PROJECT_ROOT>\component
|
||||||
```
|
```
|
||||||
where ```<PROJECT_ROOT>``` directory, which was unzipped project.
|
where ```<PROJECT_ROOT>``` directory, which was unzipped project.<br>
|
||||||
|
|
||||||
Additionally, you can specify the path to the library header files FFMPEG
|
Additionally, you can specify the path to the library header files FFMPEG
|
||||||
```
|
```
|
||||||
<PROJECT_ROOT>\include\ffmpeg
|
<PROJECT_ROOT>\include\ffmpeg
|
||||||
@ -56,8 +53,7 @@ Examples of using FFMPEG library header files are in the
|
|||||||
```
|
```
|
||||||
<PROJECT_ROOT>\include\ffmpeg\examples
|
<PROJECT_ROOT>\include\ffmpeg\examples
|
||||||
```
|
```
|
||||||
|
Open in Delphi IDE and compile:<br>
|
||||||
4.Open in Delphi IDE and compile:<br>
|
|
||||||
Examples of the use of certain functions and procedures
|
Examples of the use of certain functions and procedures
|
||||||
```
|
```
|
||||||
<PROJECT_ROOT>\samples\LibDemo\LibDemo.groupproj
|
<PROJECT_ROOT>\samples\LibDemo\LibDemo.groupproj
|
||||||
@ -74,5 +70,12 @@ Examples of use of components.<br>
|
|||||||
To install the components, open and install
|
To install the components, open and install
|
||||||
```
|
```
|
||||||
<PROJECT_ROOT>\include\component\OpenCV.dpk
|
<PROJECT_ROOT>\include\component\OpenCV.dpk
|
||||||
|
```
|
||||||
|
When installing the components in your PATH variable must be available should the library "opencv_*.dll".
|
||||||
|
Must also be installed visual C + + redistributable for Visual Studio 2012 is available on the [link][2]<br>
|
||||||
|
Examples of the use of components - open:
|
||||||
|
```
|
||||||
<PROJECT_ROOT>\samples\Components\cCameraCapture\cCameraCapture.dproj
|
<PROJECT_ROOT>\samples\Components\cCameraCapture\cCameraCapture.dproj
|
||||||
```
|
```
|
||||||
|
[1]: https://github.com/Laex/Delphi-OpenCV/archive/master.zip
|
||||||
|
[2]: http://www.microsoft.com/en-US/download/details.aspx?id=30679
|
BIN
component/OpenCV.dcr
Normal file
BIN
component/OpenCV.dcr
Normal file
Binary file not shown.
@ -24,6 +24,7 @@
|
|||||||
package OpenCV;
|
package OpenCV;
|
||||||
|
|
||||||
{$R *.res}
|
{$R *.res}
|
||||||
|
{$R *.dcr}
|
||||||
{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}
|
{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}
|
||||||
{$ALIGN 8}
|
{$ALIGN 8}
|
||||||
{$ASSERTIONS ON}
|
{$ASSERTIONS ON}
|
||||||
@ -32,21 +33,21 @@ package OpenCV;
|
|||||||
{$EXTENDEDSYNTAX ON}
|
{$EXTENDEDSYNTAX ON}
|
||||||
{$IMPORTEDDATA ON}
|
{$IMPORTEDDATA ON}
|
||||||
{$IOCHECKS ON}
|
{$IOCHECKS ON}
|
||||||
{$LOCALSYMBOLS ON}
|
{$LOCALSYMBOLS OFF}
|
||||||
{$LONGSTRINGS ON}
|
{$LONGSTRINGS ON}
|
||||||
{$OPENSTRINGS ON}
|
{$OPENSTRINGS ON}
|
||||||
{$OPTIMIZATION OFF}
|
{$OPTIMIZATION ON}
|
||||||
{$OVERFLOWCHECKS OFF}
|
{$OVERFLOWCHECKS OFF}
|
||||||
{$RANGECHECKS OFF}
|
{$RANGECHECKS OFF}
|
||||||
{$REFERENCEINFO ON}
|
{$REFERENCEINFO OFF}
|
||||||
{$SAFEDIVIDE OFF}
|
{$SAFEDIVIDE OFF}
|
||||||
{$STACKFRAMES ON}
|
{$STACKFRAMES OFF}
|
||||||
{$TYPEDADDRESS OFF}
|
{$TYPEDADDRESS OFF}
|
||||||
{$VARSTRINGCHECKS ON}
|
{$VARSTRINGCHECKS ON}
|
||||||
{$WRITEABLECONST OFF}
|
{$WRITEABLECONST OFF}
|
||||||
{$MINENUMSIZE 1}
|
{$MINENUMSIZE 1}
|
||||||
{$IMAGEBASE $400000}
|
{$IMAGEBASE $400000}
|
||||||
{$DEFINE DEBUG}
|
{$DEFINE RELEASE}
|
||||||
{$ENDIF IMPLICITBUILDING}
|
{$ENDIF IMPLICITBUILDING}
|
||||||
{$IMPLICITBUILD ON}
|
{$IMPLICITBUILD ON}
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ requires
|
|||||||
|
|
||||||
contains
|
contains
|
||||||
uOCVTypes in 'uOCVTypes.pas',
|
uOCVTypes in 'uOCVTypes.pas',
|
||||||
uOCVCamera in 'uOCVCamera.pas',
|
uOCVSource in 'uOCVSource.pas',
|
||||||
uOCVView in 'uOCVView.pas',
|
uOCVView in 'uOCVView.pas',
|
||||||
uOCVImageOperation in 'uOCVImageOperation.pas',
|
uOCVImageOperation in 'uOCVImageOperation.pas',
|
||||||
uOCVRegister in 'uOCVRegister.pas',
|
uOCVRegister in 'uOCVRegister.pas',
|
||||||
|
@ -100,11 +100,15 @@
|
|||||||
<DCCReference Include="vcl.dcp"/>
|
<DCCReference Include="vcl.dcp"/>
|
||||||
<DCCReference Include="DesignIDE.dcp"/>
|
<DCCReference Include="DesignIDE.dcp"/>
|
||||||
<DCCReference Include="uOCVTypes.pas"/>
|
<DCCReference Include="uOCVTypes.pas"/>
|
||||||
<DCCReference Include="uOCVCamera.pas"/>
|
<DCCReference Include="uOCVSource.pas"/>
|
||||||
<DCCReference Include="uOCVView.pas"/>
|
<DCCReference Include="uOCVView.pas"/>
|
||||||
<DCCReference Include="uOCVImageOperation.pas"/>
|
<DCCReference Include="uOCVImageOperation.pas"/>
|
||||||
<DCCReference Include="uOCVRegister.pas"/>
|
<DCCReference Include="uOCVRegister.pas"/>
|
||||||
<DCCReference Include="uOCVIOProperties.pas"/>
|
<DCCReference Include="uOCVIOProperties.pas"/>
|
||||||
|
<None Include="ModelSupport_OpenCV\default.txaPackage"/>
|
||||||
|
<None Include="ModelSupport_OpenCV\default.txvpck"/>
|
||||||
|
<None Include="ModelSupport_OpenCV\uOCVSource\default.txvpck"/>
|
||||||
|
<None Include="ModelSupport_OpenCV\uOCVSource\default.txaPackage"/>
|
||||||
<BuildConfiguration Include="Release">
|
<BuildConfiguration Include="Release">
|
||||||
<Key>Cfg_2</Key>
|
<Key>Cfg_2</Key>
|
||||||
<CfgParent>Base</CfgParent>
|
<CfgParent>Base</CfgParent>
|
||||||
@ -175,6 +179,7 @@
|
|||||||
<Platform value="Win32">True</Platform>
|
<Platform value="Win32">True</Platform>
|
||||||
<Platform value="Win64">False</Platform>
|
<Platform value="Win64">False</Platform>
|
||||||
</Platforms>
|
</Platforms>
|
||||||
|
<ModelSupport>True</ModelSupport>
|
||||||
</BorlandProject>
|
</BorlandProject>
|
||||||
<ProjectFileVersion>12</ProjectFileVersion>
|
<ProjectFileVersion>12</ProjectFileVersion>
|
||||||
</ProjectExtensions>
|
</ProjectExtensions>
|
||||||
|
BIN
component/OpenCV.dres
Normal file
BIN
component/OpenCV.dres
Normal file
Binary file not shown.
1
component/OpenCVResource.rc
Normal file
1
component/OpenCVResource.rc
Normal file
@ -0,0 +1 @@
|
|||||||
|
TocvCameraSource BITMAP "Resource\\TocvCameraSource.bmp"
|
BIN
component/Resource/TocvCameraSource.bmp
Normal file
BIN
component/Resource/TocvCameraSource.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
component/Resource/TocvImageOperation.bmp
Normal file
BIN
component/Resource/TocvImageOperation.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
component/Resource/TocvView.bmp
Normal file
BIN
component/Resource/TocvView.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
36
component/readme_en.md
Normal file
36
component/readme_en.md
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
Delphi-OpenCV Components
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
Visual and non-visual components for working with the library OpenCV.
|
||||||
|
Version: OpenCV 2.4.9
|
||||||
|
Package: OpenCV.dpk
|
||||||
|
|
||||||
|
Components:
|
||||||
|
|
||||||
|
TocvView
|
||||||
|
--------
|
||||||
|
Showcases the work of a visual component to display video camera images
|
||||||
|
|
||||||
|
TocvCamera
|
||||||
|
----------
|
||||||
|
|
||||||
|
Showcases the work of non-visual component connection to the camera and image transmission receivers TOpenCVCamera
|
||||||
|
|
||||||
|
TocvImageOperation
|
||||||
|
------------------
|
||||||
|
Component that handles images
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
1. Add to system variable PATH path to DLL libraries OpenCV.
|
||||||
|
Also may need to specify a path to msvcp120d.dll, msvcp120.dll, msvcr100d.dll, msvcr100.dll ([link][1])
|
||||||
|
(if they are not in the same directory).
|
||||||
|
2. To install, open <PROJECT_ROOT>\component\OpenCV.dpk. Install package.
|
||||||
|
3. In the panel component will be part OpenCV.
|
||||||
|
4. Open the sample
|
||||||
|
> <PROJECT_ROOT>\Samples\Components\cCameraCapture\cCameraCapture.dpr
|
||||||
|
|
||||||
|
Run the sample.
|
||||||
|
*TODO:*
|
||||||
|
*Wanted beautiful icons for the components.*
|
||||||
|
[1]: http://www.microsoft.com/en-US/download/details.aspx?id=30679
|
@ -1,48 +0,0 @@
|
|||||||
*****************************************************************
|
|
||||||
* Delphi-OpenCV Demo *
|
|
||||||
* Copyright (C) 2013 Project Delphi-OpenCV *
|
|
||||||
*****************************************************************
|
|
||||||
|
|
||||||
Visual and non-visual components for working with the library OpenCV.
|
|
||||||
Version: OpenCV 2.4.9
|
|
||||||
Package: OpenCV.dpk
|
|
||||||
|
|
||||||
The demo version.
|
|
||||||
|
|
||||||
Components:
|
|
||||||
|
|
||||||
----- TocvView -------
|
|
||||||
Showcases the work of a visual component to display
|
|
||||||
video camera images
|
|
||||||
|
|
||||||
----- TocvCamera -----
|
|
||||||
Showcases the work of non-visual component connection
|
|
||||||
to the camera and image transmission receivers TOpenCVCamera
|
|
||||||
|
|
||||||
----- TocvImageOperation -----
|
|
||||||
Component that handles images
|
|
||||||
|
|
||||||
----- TocvSplitter -----
|
|
||||||
Transmits the image to multiple receivers
|
|
||||||
|
|
||||||
Attention! Components written in a very non-optimal and require
|
|
||||||
significant improvement. The use of real-world projects
|
|
||||||
is not recommended.
|
|
||||||
Further components will be refined and improved.
|
|
||||||
|
|
||||||
----- Installation -------
|
|
||||||
1. Add to system variable PATH path to DLL libraries OpenCV.
|
|
||||||
Also may need to specify a path to msvcp100d.dll and
|
|
||||||
msvcr100d.dll (if they are not in the same directory)
|
|
||||||
|
|
||||||
2. To install, open <PROJECT_ROOT>\component\OpenCV.dpk.
|
|
||||||
Install package.
|
|
||||||
|
|
||||||
3. In the panel component will be part OpenCV.
|
|
||||||
|
|
||||||
4. Open the sample
|
|
||||||
<PROJECT_ROOT>\Samples\Components\cCameraCapture\cCameraCapture.dpr
|
|
||||||
Run the sample.
|
|
||||||
|
|
||||||
TODO:
|
|
||||||
Wanted beautiful icons for the components.
|
|
@ -1,299 +0,0 @@
|
|||||||
(* /*****************************************************************
|
|
||||||
// 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 uOCVCamera;
|
|
||||||
|
|
||||||
interface
|
|
||||||
|
|
||||||
uses
|
|
||||||
System.SysUtils,
|
|
||||||
System.Classes,
|
|
||||||
core.types_c,
|
|
||||||
highgui_c,
|
|
||||||
uOCVTypes;
|
|
||||||
|
|
||||||
type
|
|
||||||
TocvCameraCaptureSource =
|
|
||||||
//
|
|
||||||
(CAP_ANY {= 0} , // autodetect
|
|
||||||
CAP_CAM_0 {=0} , //
|
|
||||||
CAP_CAM_1 {=1} , //
|
|
||||||
CAP_CAM_2 {=2} , //
|
|
||||||
CAP_CAM_3 {=3} , //
|
|
||||||
CAP_CAM_4 {=4} , //
|
|
||||||
CAP_CAM_5 {=5} , //
|
|
||||||
CAP_MIL {= 100} , // MIL proprietary drivers
|
|
||||||
CAP_VFW {= 200} , // platform native
|
|
||||||
CAP_V4L {= 200} , //
|
|
||||||
CAP_V4L2 {= 200} , //
|
|
||||||
CAP_FIREWARE {= 300} , // IEEE 1394 drivers
|
|
||||||
CAP_FIREWIRE {= 300} , //
|
|
||||||
CAP_IEEE1394 {= 300} , //
|
|
||||||
CAP_DC1394 {= 300} , //
|
|
||||||
CAP_CMU1394 {= 300} , //
|
|
||||||
CAP_STEREO {= 400} , // TYZX proprietary drivers
|
|
||||||
CAP_TYZX {= 400} , //
|
|
||||||
TYZX_LEFT {= 400} , //
|
|
||||||
TYZX_RIGHT {= 401} , //
|
|
||||||
TYZX_COLOR {= 402} , //
|
|
||||||
TYZX_Z {= 403} , //
|
|
||||||
CAP_QT {= 500} , // QuickTime
|
|
||||||
CAP_UNICAP {= 600} , // Unicap drivers
|
|
||||||
CAP_DSHOW {= 700} , // DirectShow (via videoInput)
|
|
||||||
CAP_PVAPI {= 800} , // PvAPI, Prosilica GigE SDK
|
|
||||||
CAP_OPENNI {= 900} , // OpenNI (for Kinect)
|
|
||||||
CAP_OPENNI_ASUS {= 910} , // OpenNI (for Asus Xtion)
|
|
||||||
CAP_ANDROID {= 1000} , // Android
|
|
||||||
CAP_XIAPI {= 1100} , // XIMEA Camera API
|
|
||||||
CAP_AVFOUNDATION {= 1200} );
|
|
||||||
|
|
||||||
type
|
|
||||||
TocvCameraThread = class(TThread)
|
|
||||||
private const
|
|
||||||
ThreadSleepConst = 10;
|
|
||||||
private
|
|
||||||
FOnNotifyData: TOnOcvNotify;
|
|
||||||
protected
|
|
||||||
FCapture: pCvCapture;
|
|
||||||
procedure Execute; override;
|
|
||||||
public
|
|
||||||
property OnNotifyData: TOnOcvNotify Read FOnNotifyData write FOnNotifyData;
|
|
||||||
end;
|
|
||||||
|
|
||||||
TocvResolution = (r160x120, r320x240, r424x240, r640x360, r800x448, r960x544, r1280x720);
|
|
||||||
|
|
||||||
TocvCamera = class(TocvDataSource)
|
|
||||||
private
|
|
||||||
FEnabled: Boolean;
|
|
||||||
FCameraCaptureSource: TocvCameraCaptureSource;
|
|
||||||
FResolution: TocvResolution;
|
|
||||||
FOnImage: TOnOcvNotify;
|
|
||||||
procedure SetEnabled(const Value: Boolean);
|
|
||||||
procedure SetCameraCaptureSource(const Value: TocvCameraCaptureSource);
|
|
||||||
procedure SetResolution(const Value: TocvResolution);
|
|
||||||
procedure TerminateCameraThread;
|
|
||||||
procedure ReleaseCamera;
|
|
||||||
procedure SetCameraResolution;
|
|
||||||
protected
|
|
||||||
FCapture: pCvCapture;
|
|
||||||
FOpenCVCameraThread: TocvCameraThread;
|
|
||||||
procedure OnNotifyData(Sender: TObject; const IplImage: IocvImage);
|
|
||||||
public
|
|
||||||
constructor Create(AOwner: TComponent); override;
|
|
||||||
destructor Destroy; override;
|
|
||||||
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 OnImage: TOnOcvNotify read FOnImage write FOnImage;
|
|
||||||
end;
|
|
||||||
|
|
||||||
implementation
|
|
||||||
|
|
||||||
uses
|
|
||||||
core_c;
|
|
||||||
|
|
||||||
const
|
|
||||||
ocvCameraCaptureSource: array [TocvCameraCaptureSource] of Longint =
|
|
||||||
//
|
|
||||||
(CV_CAP_ANY, // autodetect
|
|
||||||
CV_CAP_CAM_0, //
|
|
||||||
CV_CAP_CAM_1, //
|
|
||||||
CV_CAP_CAM_2, //
|
|
||||||
CV_CAP_CAM_3, //
|
|
||||||
CV_CAP_CAM_4, //
|
|
||||||
CV_CAP_CAM_5, //
|
|
||||||
CV_CAP_MIL, // MIL proprietary drivers
|
|
||||||
CV_CAP_VFW, // platform native
|
|
||||||
CV_CAP_V4L, //
|
|
||||||
CV_CAP_V4L2, //
|
|
||||||
CV_CAP_FIREWARE, // IEEE 1394 drivers
|
|
||||||
CV_CAP_FIREWIRE, //
|
|
||||||
CV_CAP_IEEE1394, //
|
|
||||||
CV_CAP_DC1394, //
|
|
||||||
CV_CAP_CMU1394, //
|
|
||||||
CV_CAP_STEREO, // TYZX proprietary drivers
|
|
||||||
CV_CAP_TYZX, //
|
|
||||||
CV_TYZX_LEFT, //
|
|
||||||
CV_TYZX_RIGHT, //
|
|
||||||
CV_TYZX_COLOR, //
|
|
||||||
CV_TYZX_Z, //
|
|
||||||
CV_CAP_QT, // QuickTime
|
|
||||||
CV_CAP_UNICAP, // Unicap drivers
|
|
||||||
CV_CAP_DSHOW, // DirectShow (via videoInput)
|
|
||||||
CV_CAP_PVAPI, // PvAPI; Prosilica GigE SDK
|
|
||||||
CV_CAP_OPENNI, // OpenNI (for Kinect)
|
|
||||||
CV_CAP_OPENNI_ASUS, // OpenNI (for Asus Xtion)
|
|
||||||
CV_CAP_ANDROID, // Android
|
|
||||||
CV_CAP_XIAPI, // XIMEA Camera API
|
|
||||||
CV_CAP_AVFOUNDATION);
|
|
||||||
|
|
||||||
Type
|
|
||||||
TCameraResolution = record
|
|
||||||
cWidth, cHeight: Integer;
|
|
||||||
end;
|
|
||||||
|
|
||||||
Const
|
|
||||||
CameraResolution: array [TocvResolution] of TCameraResolution = ((cWidth: 160; cHeight: 120), (cWidth: 320; cHeight: 240),
|
|
||||||
(cWidth: 424; cHeight: 240), (cWidth: 640; cHeight: 360), (cWidth: 800; cHeight: 448), (cWidth: 960; cHeight: 544),
|
|
||||||
(cWidth: 1280; cHeight: 720));
|
|
||||||
|
|
||||||
{TOpenCVCameraThread}
|
|
||||||
|
|
||||||
procedure TocvCameraThread.Execute;
|
|
||||||
Var
|
|
||||||
frame: pIplImage;
|
|
||||||
begin
|
|
||||||
while not Terminated do
|
|
||||||
if Assigned(FCapture) then
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
frame := cvQueryFrame(FCapture);
|
|
||||||
if Assigned(frame) then
|
|
||||||
begin
|
|
||||||
if Assigned(OnNotifyData) then
|
|
||||||
Synchronize(
|
|
||||||
procedure
|
|
||||||
begin
|
|
||||||
OnNotifyData(Self, TocvImage.CreateCopy(frame));
|
|
||||||
end);
|
|
||||||
Sleep(ThreadSleepConst);
|
|
||||||
end;
|
|
||||||
except
|
|
||||||
end;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Suspend;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{TOpenCVCamera}
|
|
||||||
|
|
||||||
constructor TocvCamera.Create(AOwner: TComponent);
|
|
||||||
begin
|
|
||||||
inherited;
|
|
||||||
if not(csDesigning in ComponentState) then
|
|
||||||
begin
|
|
||||||
FOpenCVCameraThread := TocvCameraThread.Create(True);
|
|
||||||
FOpenCVCameraThread.OnNotifyData := OnNotifyData;
|
|
||||||
FEnabled := False;
|
|
||||||
FResolution := r160x120;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TocvCamera.Destroy;
|
|
||||||
begin
|
|
||||||
TerminateCameraThread;
|
|
||||||
ReleaseCamera;
|
|
||||||
inherited;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvCamera.ReleaseCamera;
|
|
||||||
begin
|
|
||||||
if Assigned(FCapture) then
|
|
||||||
begin
|
|
||||||
cvReleaseCapture(FCapture);
|
|
||||||
FCapture := nil;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvCamera.TerminateCameraThread;
|
|
||||||
begin
|
|
||||||
if Assigned(FOpenCVCameraThread) then
|
|
||||||
begin
|
|
||||||
FOpenCVCameraThread.Terminate;
|
|
||||||
FOpenCVCameraThread.Resume;
|
|
||||||
FOpenCVCameraThread.WaitFor;
|
|
||||||
FOpenCVCameraThread.Free;
|
|
||||||
FOpenCVCameraThread := Nil;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvCamera.OnNotifyData(Sender: TObject; const IplImage: IocvImage);
|
|
||||||
begin
|
|
||||||
if Assigned(OnImage) then
|
|
||||||
OnImage(Self, IplImage);
|
|
||||||
NotifyReceiver(IplImage);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvCamera.SetCameraCaptureSource(const Value: TocvCameraCaptureSource);
|
|
||||||
Var
|
|
||||||
isEnabled: Boolean;
|
|
||||||
begin
|
|
||||||
if FCameraCaptureSource <> Value then
|
|
||||||
begin
|
|
||||||
isEnabled := Enabled;
|
|
||||||
if Assigned(FCapture) and FEnabled then
|
|
||||||
Enabled := False;
|
|
||||||
FCameraCaptureSource := Value;
|
|
||||||
Enabled := isEnabled;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvCamera.SetEnabled(const Value: Boolean);
|
|
||||||
begin
|
|
||||||
if FEnabled <> Value then
|
|
||||||
begin
|
|
||||||
if not(csDesigning in ComponentState) then
|
|
||||||
begin
|
|
||||||
|
|
||||||
if Assigned(FCapture) and FEnabled then
|
|
||||||
begin
|
|
||||||
FOpenCVCameraThread.Suspend;
|
|
||||||
FOpenCVCameraThread.FCapture := nil;
|
|
||||||
cvReleaseCapture(FCapture);
|
|
||||||
FCapture := Nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
if Value then
|
|
||||||
begin
|
|
||||||
FCapture := cvCreateCameraCapture(ocvCameraCaptureSource[FCameraCaptureSource]);
|
|
||||||
SetCameraResolution;
|
|
||||||
FOpenCVCameraThread.FCapture := FCapture;
|
|
||||||
FOpenCVCameraThread.Resume;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end;
|
|
||||||
FEnabled := Value;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvCamera.SetCameraResolution;
|
|
||||||
begin
|
|
||||||
cvSetCaptureProperty(FCapture, CV_CAP_PROP_FRAME_WIDTH, CameraResolution[FResolution].cWidth);
|
|
||||||
cvSetCaptureProperty(FCapture, CV_CAP_PROP_FRAME_HEIGHT, CameraResolution[FResolution].cHeight);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvCamera.SetResolution(const Value: TocvResolution);
|
|
||||||
begin
|
|
||||||
if FResolution <> Value then
|
|
||||||
begin
|
|
||||||
FResolution := Value;
|
|
||||||
if Enabled then
|
|
||||||
begin
|
|
||||||
Enabled := False;
|
|
||||||
Enabled := True;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
|
@ -28,10 +28,26 @@ interface
|
|||||||
Uses
|
Uses
|
||||||
System.Classes,
|
System.Classes,
|
||||||
DesignEditors,
|
DesignEditors,
|
||||||
DesignIntf;
|
DesignIntf,
|
||||||
|
uOCVImageOperation;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
TImageOperationProperty = class(TClassProperty)
|
TImageOperationProperty = class(TComponentProperty)
|
||||||
|
private
|
||||||
|
FInstance: TPersistent;
|
||||||
|
protected
|
||||||
|
function GetInstance: TPersistent; virtual;
|
||||||
|
public
|
||||||
|
function GetAttributes: TPropertyAttributes; override;
|
||||||
|
function GetValue: string; override;
|
||||||
|
procedure GetProperties(Proc: TGetPropProc); override;
|
||||||
|
procedure GetValues(Proc: TGetStrProc); override;
|
||||||
|
procedure SetValue(const Value: string); override;
|
||||||
|
procedure Initialize; override;
|
||||||
|
property Instance: TPersistent read GetInstance;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TImageOperationCollectionItemProperty = class(TClassProperty)
|
||||||
public
|
public
|
||||||
function GetAttributes: TPropertyAttributes; override;
|
function GetAttributes: TPropertyAttributes; override;
|
||||||
function GetValue: string; override;
|
function GetValue: string; override;
|
||||||
@ -39,12 +55,37 @@ Type
|
|||||||
procedure SetValue(const Value: string); override;
|
procedure SetValue(const Value: string); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TImagePreprocessingProperty = class(TClassProperty)
|
TImagePreprocessingProperty = class(TImageOperationCollectionItemProperty)
|
||||||
public
|
public
|
||||||
function GetAttributes: TPropertyAttributes; override;
|
// function GetAttributes: TPropertyAttributes; override;
|
||||||
function GetValue: string; override;
|
// function GetValue: string; override;
|
||||||
procedure GetValues(Proc: TGetStrProc); override;
|
procedure GetValues(Proc: TGetStrProc); override;
|
||||||
procedure SetValue(const Value: string); override;
|
// procedure SetValue(const Value: string); override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TocvIOPropertyChangeEvent = procedure(Sender: TObject; const PropName: string) of object;
|
||||||
|
|
||||||
|
TocvCustomImageOperationProperty = class(TocvCustomImageOperation)
|
||||||
|
private
|
||||||
|
FUpdateCount: Integer;
|
||||||
|
FOnChanging: TNotifyEvent;
|
||||||
|
FOnChanged: TNotifyEvent;
|
||||||
|
FOnChangingProperty: TocvIOPropertyChangeEvent;
|
||||||
|
FOnChangedProperty: TocvIOPropertyChangeEvent;
|
||||||
|
protected
|
||||||
|
procedure Changed; virtual;
|
||||||
|
procedure Changing; virtual;
|
||||||
|
procedure ChangedProperty(const PropName: string); virtual;
|
||||||
|
procedure ChangingProperty(const PropName: string); virtual;
|
||||||
|
procedure SetUpdateState(Updating: Boolean); virtual;
|
||||||
|
property UpdateCount: Integer read FUpdateCount;
|
||||||
|
public
|
||||||
|
procedure BeginUpdate; virtual;
|
||||||
|
procedure EndUpdate; virtual;
|
||||||
|
property OnChanged: TNotifyEvent read FOnChanged write FOnChanged;
|
||||||
|
property OnChanging: TNotifyEvent read FOnChanging write FOnChanging;
|
||||||
|
property OnChangedProperty: TocvIOPropertyChangeEvent read FOnChangedProperty write FOnChangedProperty;
|
||||||
|
property OnChangingProperty: TocvIOPropertyChangeEvent read FOnChangingProperty write FOnChangingProperty;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -53,7 +94,6 @@ Uses
|
|||||||
System.SysUtils,
|
System.SysUtils,
|
||||||
System.TypInfo,
|
System.TypInfo,
|
||||||
System.RTLConsts,
|
System.RTLConsts,
|
||||||
uOCVImageOperation,
|
|
||||||
uOCVTypes;
|
uOCVTypes;
|
||||||
|
|
||||||
{TImageOperationProperty}
|
{TImageOperationProperty}
|
||||||
@ -61,7 +101,7 @@ Uses
|
|||||||
function TImageOperationProperty.GetAttributes: TPropertyAttributes;
|
function TImageOperationProperty.GetAttributes: TPropertyAttributes;
|
||||||
begin
|
begin
|
||||||
Result := inherited GetAttributes;
|
Result := inherited GetAttributes;
|
||||||
Result := Result - [paReadOnly] + [paValueList, paSortList, paRevertable, paVolatileSubProperties];
|
Result := Result - [paReadOnly] + [paValueList, paSortList, paRevertable, paSubProperties, paVolatileSubProperties];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TImageOperationProperty.GetValue: string;
|
function TImageOperationProperty.GetValue: string;
|
||||||
@ -98,16 +138,16 @@ end;
|
|||||||
|
|
||||||
{TImagePreprocessingProperty}
|
{TImagePreprocessingProperty}
|
||||||
|
|
||||||
function TImagePreprocessingProperty.GetAttributes: TPropertyAttributes;
|
//function TImagePreprocessingProperty.GetAttributes: TPropertyAttributes;
|
||||||
begin
|
//begin
|
||||||
Result := inherited GetAttributes;
|
// Result := inherited GetAttributes;
|
||||||
Result := Result - [paReadOnly] + [paValueList, paSortList, paRevertable, paVolatileSubProperties];
|
// Result := Result - [paReadOnly] + [paValueList, paSortList, paRevertable, paSubProperties];
|
||||||
end;
|
//end;
|
||||||
|
|
||||||
function TImagePreprocessingProperty.GetValue: string;
|
//function TImagePreprocessingProperty.GetValue: string;
|
||||||
begin
|
//begin
|
||||||
Result := GetRegisteredImageOperations.GetNameByClass(TocvImageOperation(GetOrdValue).ClassType);
|
// Result := GetRegisteredImageOperations.GetNameByClass(TocvImageOperation(GetOrdValue).ClassType);
|
||||||
end;
|
//end;
|
||||||
|
|
||||||
procedure TImagePreprocessingProperty.GetValues(Proc: TGetStrProc);
|
procedure TImagePreprocessingProperty.GetValues(Proc: TGetStrProc);
|
||||||
begin
|
begin
|
||||||
@ -116,7 +156,151 @@ begin
|
|||||||
Proc('AdaptiveThreshold');
|
Proc('AdaptiveThreshold');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TImagePreprocessingProperty.SetValue(const Value: string);
|
//procedure TImagePreprocessingProperty.SetValue(const Value: string);
|
||||||
|
//Var
|
||||||
|
// APropertiesClass: TocvImageOperationClass;
|
||||||
|
// I: Integer;
|
||||||
|
// AIntf: IocvEditorPropertiesContainer;
|
||||||
|
//begin
|
||||||
|
// APropertiesClass := GetRegisteredImageOperations.FindByName(Value);
|
||||||
|
// if APropertiesClass = nil then
|
||||||
|
// APropertiesClass := TocvImageOperationClass(GetRegisteredImageOperations.Objects[0]);
|
||||||
|
//
|
||||||
|
// for I := 0 to PropCount - 1 do
|
||||||
|
// if Supports(GetComponent(I), IocvEditorPropertiesContainer, AIntf) then
|
||||||
|
// AIntf.SetPropertiesClass(APropertiesClass);
|
||||||
|
//
|
||||||
|
// Modified;
|
||||||
|
//end;
|
||||||
|
|
||||||
|
{TocvCustomImageOperationProperty}
|
||||||
|
|
||||||
|
procedure TocvCustomImageOperationProperty.BeginUpdate;
|
||||||
|
begin
|
||||||
|
if FUpdateCount = 0 then
|
||||||
|
SetUpdateState(True);
|
||||||
|
Inc(FUpdateCount);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomImageOperationProperty.Changed;
|
||||||
|
begin
|
||||||
|
if (FUpdateCount = 0) and Assigned(FOnChanged) then
|
||||||
|
FOnChanged(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomImageOperationProperty.ChangedProperty(const PropName: string);
|
||||||
|
begin
|
||||||
|
if Assigned(FOnChangedProperty) then
|
||||||
|
FOnChangedProperty(Self, PropName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomImageOperationProperty.Changing;
|
||||||
|
begin
|
||||||
|
if (FUpdateCount = 0) and Assigned(FOnChanging) then
|
||||||
|
FOnChanging(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomImageOperationProperty.ChangingProperty(const PropName: string);
|
||||||
|
begin
|
||||||
|
if Assigned(FOnChangingProperty) then
|
||||||
|
FOnChangingProperty(Self, PropName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomImageOperationProperty.EndUpdate;
|
||||||
|
begin
|
||||||
|
Dec(FUpdateCount);
|
||||||
|
if FUpdateCount = 0 then
|
||||||
|
SetUpdateState(False);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomImageOperationProperty.SetUpdateState(Updating: Boolean);
|
||||||
|
begin
|
||||||
|
if Updating then
|
||||||
|
Changing
|
||||||
|
else
|
||||||
|
Changed;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TImageOperationProperty.GetInstance: TPersistent;
|
||||||
|
var
|
||||||
|
LInstance: TPersistent;
|
||||||
|
LPersistentPropertyName: string;
|
||||||
|
begin
|
||||||
|
if not Assigned(FInstance) then
|
||||||
|
begin
|
||||||
|
LInstance := GetComponent(0);
|
||||||
|
LPersistentPropertyName := GetName;
|
||||||
|
if IsPublishedProp(LInstance, LPersistentPropertyName) then
|
||||||
|
begin
|
||||||
|
FInstance := TPersistent(GetObjectProp(LInstance, LPersistentPropertyName));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Result := FInstance;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TImageOperationProperty.GetProperties(Proc: TGetPropProc);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TImageOperationProperty.Initialize;
|
||||||
|
var
|
||||||
|
LInstance: TPersistent;
|
||||||
|
LPersistentPropertyName: string;
|
||||||
|
begin
|
||||||
|
inherited Initialize;
|
||||||
|
LInstance := Instance;
|
||||||
|
LPersistentPropertyName := GetName;
|
||||||
|
if LInstance is TComponent then
|
||||||
|
begin
|
||||||
|
if (TComponent(LInstance).Name = '') and (TComponent(LInstance).Name <> LPersistentPropertyName) then
|
||||||
|
begin
|
||||||
|
TComponent(LInstance).Name := LPersistentPropertyName;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else if LInstance is TocvCustomImageOperation then
|
||||||
|
begin
|
||||||
|
if (TocvCustomImageOperation(LInstance).Name = '') and (TocvCustomImageOperation(LInstance).Name <> LPersistentPropertyName)
|
||||||
|
then
|
||||||
|
begin
|
||||||
|
TocvCustomImageOperation(LInstance).Name := LPersistentPropertyName;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
// else
|
||||||
|
// if LInstance is TocvImageOperationCollectionItem then
|
||||||
|
// begin
|
||||||
|
// if (TocvImageOperationCollectionItem(LInstance).DisplayName = '') and (TocvImageOperationCollectionItem(LInstance).DisplayName <> LPersistentPropertyName)
|
||||||
|
// then
|
||||||
|
// begin
|
||||||
|
// TocvImageOperationCollectionItem(LInstance).DisplayName := LPersistentPropertyName;
|
||||||
|
// end;
|
||||||
|
// end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{TImageOperationCollectionItemProperty}
|
||||||
|
|
||||||
|
function TImageOperationCollectionItemProperty.GetAttributes: TPropertyAttributes;
|
||||||
|
begin
|
||||||
|
Result := inherited GetAttributes;
|
||||||
|
Result := Result - [paReadOnly] + [paValueList, paSortList, paRevertable, paVolatileSubProperties];
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TImageOperationCollectionItemProperty.GetValue: string;
|
||||||
|
begin
|
||||||
|
Result := GetRegisteredImageOperations.GetNameByClass(TocvImageOperation(GetOrdValue).ClassType);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TImageOperationCollectionItemProperty.GetValues(Proc: TGetStrProc);
|
||||||
|
var
|
||||||
|
I: Integer;
|
||||||
|
rIO: TRegisteredImageOperations;
|
||||||
|
begin
|
||||||
|
rIO := GetRegisteredImageOperations;
|
||||||
|
for I := 0 to rIO.Count - 1 do
|
||||||
|
Proc(rIO[I]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TImageOperationCollectionItemProperty.SetValue(const Value: string);
|
||||||
Var
|
Var
|
||||||
APropertiesClass: TocvImageOperationClass;
|
APropertiesClass: TocvImageOperationClass;
|
||||||
I: Integer;
|
I: Integer;
|
||||||
@ -136,10 +320,11 @@ end;
|
|||||||
initialization
|
initialization
|
||||||
|
|
||||||
RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvImageOperation, 'Operation', TImageOperationProperty);
|
RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvImageOperation, 'Operation', TImageOperationProperty);
|
||||||
RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvImageOperationCollectionItem, 'Operation',
|
RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvImageOperationCollectionItem, 'Operation',TImageOperationCollectionItemProperty);
|
||||||
TImageOperationProperty);
|
//RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvImageOperationCollectionItem, 'Operation',TImageOperationProperty);
|
||||||
RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvContoursOperation, 'Preprocessing', TImagePreprocessingProperty);
|
RegisterPropertyEditor(TypeInfo(TocvCustomImageOperation), TocvContoursOperation, 'Preprocessing', TImagePreprocessingProperty);
|
||||||
|
|
||||||
|
UnlistPublishedProperty(TocvCustomImageOperation, 'Name');
|
||||||
UnlistPublishedProperty(TocvImageOperation, 'OperationClassName');
|
UnlistPublishedProperty(TocvImageOperation, 'OperationClassName');
|
||||||
UnlistPublishedProperty(TocvImageOperationCollectionItem, 'OperationClassName');
|
UnlistPublishedProperty(TocvImageOperationCollectionItem, 'OperationClassName');
|
||||||
UnlistPublishedProperty(TocvContoursOperation, 'OperationClassName');
|
UnlistPublishedProperty(TocvContoursOperation, 'OperationClassName');
|
||||||
|
@ -37,32 +37,40 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
TocvCustomImageOperation = class(TPersistent)
|
TocvCustomImageOperation = class(TComponent)
|
||||||
protected
|
protected
|
||||||
procedure AssignTo(Dest: TPersistent); override;
|
procedure AssignTo(Dest: TPersistent); override;
|
||||||
private
|
private
|
||||||
CS: TCriticalSection;
|
FCriticalSection: TCriticalSection;
|
||||||
FOwner: TPersistent; // TComponent;
|
FOwner: TPersistent;
|
||||||
FFloatParams: TArray<Double>;
|
FFloatParams: TArray<Double>;
|
||||||
FIntParams: TArray<Integer>;
|
FIntParams: TArray<Integer>;
|
||||||
FBoolParams: TArray<Boolean>;
|
FBoolParams: TArray<Boolean>;
|
||||||
|
FOnAfterPaint: TOnOcvNotify;
|
||||||
|
FOnBeforePaint: TOnOcvNotify;
|
||||||
|
protected
|
||||||
function GetFloatParam(const index: Integer): Double;
|
function GetFloatParam(const index: Integer): Double;
|
||||||
function GetIntParam(const index: Integer): Integer;
|
function GetIntParam(const index: Integer): Integer;
|
||||||
procedure SetFloatParam(const index: Integer; const Value: Double);
|
procedure SetFloatParam(const index: Integer; const Value: Double);
|
||||||
procedure SetIntParam(const index: Integer; const Value: Integer);
|
procedure SetIntParam(const index: Integer; const Value: Integer);
|
||||||
function GetBoolParam(const index: Integer): Boolean;
|
function GetBoolParam(const index: Integer): Boolean;
|
||||||
procedure SetBoolParam(const index: Integer; const Value: Boolean);
|
procedure SetBoolParam(const index: Integer; const Value: Boolean);
|
||||||
protected
|
|
||||||
function LockTransform: Boolean;
|
function LockTransform: Boolean;
|
||||||
procedure UnlockTransform;
|
procedure UnlockTransform;
|
||||||
|
function GetOwner: TPersistent; override;
|
||||||
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; virtual;
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; virtual;
|
||||||
property FloatParams[const index: Integer]: Double Read GetFloatParam write SetFloatParam;
|
property FloatParams[const index: Integer]: Double Read GetFloatParam write SetFloatParam;
|
||||||
property IntParams[const index: Integer]: Integer Read GetIntParam write SetIntParam;
|
property IntParams[const index: Integer]: Integer Read GetIntParam write SetIntParam;
|
||||||
property BoolParams[const index: Integer]: Boolean Read GetBoolParam write SetBoolParam;
|
property BoolParams[const index: Integer]: Boolean Read GetBoolParam write SetBoolParam;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TPersistent); virtual;
|
constructor Create(AOwner: TPersistent); reintroduce; virtual;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Transform(const Source: IocvImage; var Destanation: IocvImage): Boolean; virtual;
|
function Transform(const Source: IocvImage; var Destanation: IocvImage): Boolean; virtual;
|
||||||
|
function GetNamePath: string; override;
|
||||||
|
property Name;
|
||||||
|
published
|
||||||
|
property OnAfterPaint: TOnOcvNotify read FOnAfterPaint write FOnAfterPaint;
|
||||||
|
property OnBeforePaint: TOnOcvNotify read FOnBeforePaint write FOnBeforePaint;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TocvImageOperationClass = class of TocvCustomImageOperation;
|
TocvImageOperationClass = class of TocvCustomImageOperation;
|
||||||
@ -293,6 +301,8 @@ type
|
|||||||
FOffset: TocvPoint;
|
FOffset: TocvPoint;
|
||||||
FContourDraw: TocvContourDraw;
|
FContourDraw: TocvContourDraw;
|
||||||
FApprox: TocvContourApprox;
|
FApprox: TocvContourApprox;
|
||||||
|
FOnContour: TOnOcvContour;
|
||||||
|
FContours: pCvSeq;
|
||||||
function LockTransform: Boolean;
|
function LockTransform: Boolean;
|
||||||
procedure UnlockTransform;
|
procedure UnlockTransform;
|
||||||
procedure CreateProperties;
|
procedure CreateProperties;
|
||||||
@ -315,6 +325,7 @@ type
|
|||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean; override;
|
||||||
property OperationClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
|
property OperationClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
|
||||||
|
property Contours: pCvSeq read FContours;
|
||||||
published
|
published
|
||||||
property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
||||||
property Preprocessing: TocvCustomImageOperation read GetProperties write SetProperties;
|
property Preprocessing: TocvCustomImageOperation read GetProperties write SetProperties;
|
||||||
@ -322,8 +333,10 @@ type
|
|||||||
property ApproximationMethod: TocvContourApproximationMethods read FApproximationMethod write FApproximationMethod
|
property ApproximationMethod: TocvContourApproximationMethods read FApproximationMethod write FApproximationMethod
|
||||||
default CHAIN_APPROX_SIMPLE;
|
default CHAIN_APPROX_SIMPLE;
|
||||||
property Offset: TocvPoint read FOffset write FOffset;
|
property Offset: TocvPoint read FOffset write FOffset;
|
||||||
|
property MinArea: Integer index 0 Read GetIntParam write SetIntParam;
|
||||||
property ContourDraw: TocvContourDraw read FContourDraw write FContourDraw;
|
property ContourDraw: TocvContourDraw read FContourDraw write FContourDraw;
|
||||||
property ApproxPoly: TocvContourApprox read FApprox write FApprox;
|
property ApproxPoly: TocvContourApprox read FApprox write FApprox;
|
||||||
|
property OnContour: TOnOcvContour read FOnContour write FOnContour;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TocvImageOperationCollectionItem = class(TCollectionItem, IocvEditorPropertiesContainer)
|
TocvImageOperationCollectionItem = class(TCollectionItem, IocvEditorPropertiesContainer)
|
||||||
@ -331,6 +344,9 @@ type
|
|||||||
CS: TCriticalSection;
|
CS: TCriticalSection;
|
||||||
FOperation: TocvCustomImageOperation;
|
FOperation: TocvCustomImageOperation;
|
||||||
FOperationClass: TocvImageOperationClass;
|
FOperationClass: TocvImageOperationClass;
|
||||||
|
FOnAfterPaint: TOnOcvNotify;
|
||||||
|
FOnBeforePaint: TOnOcvNotify;
|
||||||
|
FOwner: TCollection;
|
||||||
function LockTransform: Boolean;
|
function LockTransform: Boolean;
|
||||||
procedure UnlockTransform;
|
procedure UnlockTransform;
|
||||||
procedure CreateProperties;
|
procedure CreateProperties;
|
||||||
@ -344,6 +360,7 @@ type
|
|||||||
function GetProperties: TocvCustomImageOperation;
|
function GetProperties: TocvCustomImageOperation;
|
||||||
function GetPropertiesClass: TocvImageOperationClass;
|
function GetPropertiesClass: TocvImageOperationClass;
|
||||||
function GetDisplayName: string; override;
|
function GetDisplayName: string; override;
|
||||||
|
function GetOwner: TPersistent; override;
|
||||||
{IInterface}
|
{IInterface}
|
||||||
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
|
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
|
||||||
function _AddRef: Integer; stdcall;
|
function _AddRef: Integer; stdcall;
|
||||||
@ -354,9 +371,12 @@ type
|
|||||||
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
function DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
||||||
procedure Assign(Source: TPersistent); override;
|
procedure Assign(Source: TPersistent); override;
|
||||||
property OperationClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
|
property OperationClass: TocvImageOperationClass read GetPropertiesClass write SetPropertiesClass;
|
||||||
|
|
||||||
published
|
published
|
||||||
property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
||||||
property Operation: TocvCustomImageOperation read GetProperties write SetProperties;
|
property Operation: TocvCustomImageOperation read GetProperties write SetProperties;
|
||||||
|
property OnAfterPaint: TOnOcvNotify read FOnAfterPaint write FOnAfterPaint;
|
||||||
|
property OnBeforePaint: TOnOcvNotify read FOnBeforePaint write FOnBeforePaint;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TocvImageOperationCollection = class(TOwnedCollection);
|
TocvImageOperationCollection = class(TOwnedCollection);
|
||||||
@ -367,9 +387,7 @@ type
|
|||||||
FOperation: TocvCustomImageOperation;
|
FOperation: TocvCustomImageOperation;
|
||||||
FOperationClass: TocvImageOperationClass;
|
FOperationClass: TocvImageOperationClass;
|
||||||
FOperations: TocvImageOperationCollection;
|
FOperations: TocvImageOperationCollection;
|
||||||
FOnBeforeTransorm: TOnOcvNotify;
|
FUseCollection: Boolean;
|
||||||
FOnAfterTransorm: TOnOcvNotify;
|
|
||||||
FOnContour: TOnOcvContour;
|
|
||||||
function LockTransform: Boolean;
|
function LockTransform: Boolean;
|
||||||
procedure UnlockTransform;
|
procedure UnlockTransform;
|
||||||
procedure CreateProperties;
|
procedure CreateProperties;
|
||||||
@ -379,13 +397,11 @@ type
|
|||||||
procedure SetProperties(const Value: TocvCustomImageOperation);
|
procedure SetProperties(const Value: TocvCustomImageOperation);
|
||||||
procedure SetPropertiesClass(Value: TocvImageOperationClass);
|
procedure SetPropertiesClass(Value: TocvImageOperationClass);
|
||||||
procedure SetPropertiesClassName(const Value: string);
|
procedure SetPropertiesClassName(const Value: string);
|
||||||
|
procedure SetUseCollection(const Value: Boolean);
|
||||||
protected
|
protected
|
||||||
procedure TakeImage(const IplImage: IocvImage); override;
|
procedure TakeImage(const IplImage: IocvImage); override;
|
||||||
function GetProperties: TocvCustomImageOperation;
|
function GetProperties: TocvCustomImageOperation;
|
||||||
function GetPropertiesClass: TocvImageOperationClass;
|
function GetPropertiesClass: TocvImageOperationClass;
|
||||||
procedure DoNotifyAfterTransform(Sender: TObject; const IplImage: IocvImage);
|
|
||||||
procedure DoNotifyBeforeTransform(Sender: TObject; const IplImage: IocvImage);
|
|
||||||
procedure DoNotifyContour(Sender: TObject; const IplImage: IocvImage; const ContourCount: Integer; const Contours: pCvSeq);
|
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -394,9 +410,7 @@ type
|
|||||||
property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
property OperationClassName: string read GetPropertiesClassName write SetPropertiesClassName;
|
||||||
property Operation: TocvCustomImageOperation read GetProperties write SetProperties;
|
property Operation: TocvCustomImageOperation read GetProperties write SetProperties;
|
||||||
property Operations: TocvImageOperationCollection Read FOperations write FOperations;
|
property Operations: TocvImageOperationCollection Read FOperations write FOperations;
|
||||||
property OnBeforeTransorm: TOnOcvNotify read FOnBeforeTransorm write FOnBeforeTransorm;
|
property OperationsEnabled: Boolean read FUseCollection write SetUseCollection default True;
|
||||||
property OnAfterTransorm: TOnOcvNotify read FOnAfterTransorm write FOnAfterTransorm;
|
|
||||||
property OnContour: TOnOcvContour read FOnContour write FOnContour;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TRegisteredImageOperations = class(TStringList)
|
TRegisteredImageOperations = class(TStringList)
|
||||||
@ -416,6 +430,9 @@ Uses
|
|||||||
imgproc_c,
|
imgproc_c,
|
||||||
imgproc.types_c;
|
imgproc.types_c;
|
||||||
|
|
||||||
|
type
|
||||||
|
TPersistentAccessProtected = class(TPersistent);
|
||||||
|
|
||||||
Var
|
Var
|
||||||
_RegisteredImageOperations: TRegisteredImageOperations = nil;
|
_RegisteredImageOperations: TRegisteredImageOperations = nil;
|
||||||
|
|
||||||
@ -465,11 +482,25 @@ begin
|
|||||||
OperationClass := TocvImageOperationClass(GetRegisteredImageOperations.FindByClassName(Value));
|
OperationClass := TocvImageOperationClass(GetRegisteredImageOperations.FindByClassName(Value));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TocvImageOperation.SetUseCollection(const Value: Boolean);
|
||||||
|
begin
|
||||||
|
if FUseCollection <> Value then
|
||||||
|
begin
|
||||||
|
CS.Enter;
|
||||||
|
try
|
||||||
|
FUseCollection := Value;
|
||||||
|
finally
|
||||||
|
CS.Leave;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TocvImageOperation.Create(AOwner: TComponent);
|
constructor TocvImageOperation.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
CS := TCriticalSection.Create;
|
CS := TCriticalSection.Create;
|
||||||
FOperations := TocvImageOperationCollection.Create(Self, TocvImageOperationCollectionItem);
|
FOperations := TocvImageOperationCollection.Create(Self, TocvImageOperationCollectionItem);
|
||||||
|
FUseCollection := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TocvImageOperation.Destroy;
|
destructor TocvImageOperation.Destroy;
|
||||||
@ -511,55 +542,22 @@ var
|
|||||||
begin
|
begin
|
||||||
if LockTransform then
|
if LockTransform then
|
||||||
try
|
try
|
||||||
if FOperations.Count > 0 then
|
Destanation := IplImage;
|
||||||
|
if OperationsEnabled and (FOperations.Count > 0) then
|
||||||
begin
|
begin
|
||||||
Destanation := IplImage;
|
|
||||||
for i := 0 to FOperations.Count - 1 do
|
for i := 0 to FOperations.Count - 1 do
|
||||||
begin
|
|
||||||
DoNotifyBeforeTransform(FOperations.Items[i], IplImage);
|
|
||||||
if not(FOperations.Items[i] as TocvImageOperationCollectionItem).DoTransform(Destanation, Destanation) then
|
if not(FOperations.Items[i] as TocvImageOperationCollectionItem).DoTransform(Destanation, Destanation) then
|
||||||
Exit;
|
Exit;
|
||||||
DoNotifyAfterTransform(FOperation, Destanation);
|
|
||||||
end;
|
|
||||||
NotifyReceiver(Destanation);
|
|
||||||
end
|
end
|
||||||
else
|
else if Assigned(FOperation) then
|
||||||
begin
|
FOperation.DoTransform(IplImage, Destanation);
|
||||||
if Assigned(FOperation) then
|
NotifyReceiver(Destanation);
|
||||||
begin
|
|
||||||
DoNotifyBeforeTransform(FOperation, IplImage);
|
|
||||||
if FOperation.DoTransform(IplImage, Destanation) then
|
|
||||||
begin
|
|
||||||
DoNotifyAfterTransform(FOperation, Destanation);
|
|
||||||
NotifyReceiver(Destanation);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
finally
|
finally
|
||||||
Destanation := nil;
|
Destanation := nil;
|
||||||
UnlockTransform;
|
UnlockTransform;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TocvImageOperation.DoNotifyBeforeTransform(Sender: TObject; const IplImage: IocvImage);
|
|
||||||
begin
|
|
||||||
if Assigned(OnBeforeTransorm) then
|
|
||||||
OnBeforeTransorm(Sender, IplImage);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvImageOperation.DoNotifyContour(Sender: TObject; const IplImage: IocvImage; const ContourCount: Integer;
|
|
||||||
const Contours: pCvSeq);
|
|
||||||
begin
|
|
||||||
if Assigned(OnContour) then
|
|
||||||
OnContour(Sender, IplImage, ContourCount, Contours);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvImageOperation.DoNotifyAfterTransform(Sender: TObject; const IplImage: IocvImage);
|
|
||||||
begin
|
|
||||||
if Assigned(OnAfterTransorm) then
|
|
||||||
OnAfterTransorm(Sender, IplImage);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TocvImageOperation.UnlockTransform;
|
procedure TocvImageOperation.UnlockTransform;
|
||||||
begin
|
begin
|
||||||
CS.Leave;
|
CS.Leave;
|
||||||
@ -614,20 +612,25 @@ end;
|
|||||||
|
|
||||||
constructor TocvCustomImageOperation.Create(AOwner: TPersistent);
|
constructor TocvCustomImageOperation.Create(AOwner: TPersistent);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
if AOwner is TComponent then
|
||||||
|
inherited Create(AOwner as TComponent)
|
||||||
|
else
|
||||||
|
inherited Create(nil);
|
||||||
|
SetSubComponent(True);
|
||||||
|
|
||||||
FOwner := AOwner;
|
FOwner := AOwner;
|
||||||
CS := TCriticalSection.Create;
|
FCriticalSection := TCriticalSection.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TocvCustomImageOperation.Destroy;
|
destructor TocvCustomImageOperation.Destroy;
|
||||||
begin
|
begin
|
||||||
CS.Free;
|
FCriticalSection.Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TocvCustomImageOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
function TocvCustomImageOperation.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
||||||
begin
|
begin
|
||||||
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TocvCustomImageOperation.GetBoolParam(const index: Integer): Boolean;
|
function TocvCustomImageOperation.GetBoolParam(const index: Integer): Boolean;
|
||||||
@ -635,7 +638,7 @@ begin
|
|||||||
if (index >= 0) and (index < Length(FBoolParams)) then
|
if (index >= 0) and (index < Length(FBoolParams)) then
|
||||||
Result := FBoolParams[index]
|
Result := FBoolParams[index]
|
||||||
else
|
else
|
||||||
Result := false;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TocvCustomImageOperation.GetFloatParam(const index: Integer): Double;
|
function TocvCustomImageOperation.GetFloatParam(const index: Integer): Double;
|
||||||
@ -654,9 +657,34 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TocvCustomImageOperation.GetNamePath: string;
|
||||||
|
var
|
||||||
|
S: string;
|
||||||
|
lOwner: TPersistent;
|
||||||
|
begin
|
||||||
|
Result := inherited GetNamePath;
|
||||||
|
lOwner := GetOwner;
|
||||||
|
if
|
||||||
|
{} (lOwner <> nil) and
|
||||||
|
{} (
|
||||||
|
{} (csSubComponent in TComponent(lOwner).ComponentStyle) or
|
||||||
|
{} (TPersistentAccessProtected(lOwner).GetOwner <> nil)
|
||||||
|
{} ) then
|
||||||
|
begin
|
||||||
|
S := lOwner.GetNamePath;
|
||||||
|
if S <> '' then
|
||||||
|
Result := S + '.' + Result;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TocvCustomImageOperation.GetOwner: TPersistent;
|
||||||
|
begin
|
||||||
|
Result := FOwner;
|
||||||
|
end;
|
||||||
|
|
||||||
function TocvCustomImageOperation.LockTransform: Boolean;
|
function TocvCustomImageOperation.LockTransform: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := CS.TryEnter;
|
Result := FCriticalSection.TryEnter;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TocvCustomImageOperation.SetBoolParam(const index: Integer; const Value: Boolean);
|
procedure TocvCustomImageOperation.SetBoolParam(const index: Integer; const Value: Boolean);
|
||||||
@ -700,7 +728,11 @@ begin
|
|||||||
Result := LockTransform;
|
Result := LockTransform;
|
||||||
if Result then
|
if Result then
|
||||||
try
|
try
|
||||||
|
if Assigned(OnBeforePaint) then
|
||||||
|
OnBeforePaint(Self, Source);
|
||||||
Result := DoTransform(Source, Destanation);
|
Result := DoTransform(Source, Destanation);
|
||||||
|
if Result and Assigned(OnAfterPaint) then
|
||||||
|
OnAfterPaint(Self, Source);
|
||||||
finally
|
finally
|
||||||
UnlockTransform;
|
UnlockTransform;
|
||||||
end;
|
end;
|
||||||
@ -708,7 +740,7 @@ end;
|
|||||||
|
|
||||||
procedure TocvCustomImageOperation.UnlockTransform;
|
procedure TocvCustomImageOperation.UnlockTransform;
|
||||||
begin
|
begin
|
||||||
CS.Leave;
|
FCriticalSection.Leave;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{TovcImageOperationSmooth}
|
{TovcImageOperationSmooth}
|
||||||
@ -909,13 +941,17 @@ end;
|
|||||||
constructor TocvImageOperationCollectionItem.Create(Collection: TCollection);
|
constructor TocvImageOperationCollectionItem.Create(Collection: TCollection);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
|
FOwner := Collection;
|
||||||
CS := TCriticalSection.Create;
|
CS := TCriticalSection.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TocvImageOperationCollectionItem.CreateProperties;
|
procedure TocvImageOperationCollectionItem.CreateProperties;
|
||||||
begin
|
begin
|
||||||
if FOperationClass <> nil then
|
if FOperationClass <> nil then
|
||||||
|
begin
|
||||||
FOperation := FOperationClass.Create(Self);
|
FOperation := FOperationClass.Create(Self);
|
||||||
|
FOperation.SetParentComponent((GetOwner as TOwnedCollection).Owner as TComponent);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TocvImageOperationCollectionItem.Destroy;
|
destructor TocvImageOperationCollectionItem.Destroy;
|
||||||
@ -936,6 +972,11 @@ begin
|
|||||||
Result := GetRegisteredImageOperations.GetNameByClass(FOperation.ClassType);
|
Result := GetRegisteredImageOperations.GetNameByClass(FOperation.ClassType);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TocvImageOperationCollectionItem.GetOwner: TPersistent;
|
||||||
|
begin
|
||||||
|
Result := FOwner;
|
||||||
|
end;
|
||||||
|
|
||||||
function TocvImageOperationCollectionItem.GetProperties: TocvCustomImageOperation;
|
function TocvImageOperationCollectionItem.GetProperties: TocvCustomImageOperation;
|
||||||
begin
|
begin
|
||||||
if not Assigned(FOperation) then
|
if not Assigned(FOperation) then
|
||||||
@ -994,7 +1035,8 @@ end;
|
|||||||
|
|
||||||
function TocvImageOperationCollectionItem.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
function TocvImageOperationCollectionItem.DoTransform(const Source: IocvImage; var Destanation: IocvImage): Boolean;
|
||||||
begin
|
begin
|
||||||
if LockTransform then
|
Result := LockTransform;
|
||||||
|
if Result then
|
||||||
try
|
try
|
||||||
Result := Assigned(FOperation) and FOperation.DoTransform(Source, Destanation)
|
Result := Assigned(FOperation) and FOperation.DoTransform(Source, Destanation)
|
||||||
finally
|
finally
|
||||||
@ -1103,6 +1145,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
RetrievalMode := RETR_LIST;
|
RetrievalMode := RETR_LIST;
|
||||||
ApproximationMethod := CHAIN_APPROX_SIMPLE;
|
ApproximationMethod := CHAIN_APPROX_SIMPLE;
|
||||||
|
MinArea := 100;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TocvContoursOperation.CreateProperties;
|
procedure TocvContoursOperation.CreateProperties;
|
||||||
@ -1200,15 +1243,15 @@ const
|
|||||||
|
|
||||||
Var
|
Var
|
||||||
th_image: IocvImage;
|
th_image: IocvImage;
|
||||||
Contours: pCvSeq;
|
|
||||||
storage: pCvMemStorage;
|
storage: pCvMemStorage;
|
||||||
contoursCont: Integer;
|
contoursCont: Integer;
|
||||||
RGBColor: TColor;
|
|
||||||
er, eg, eb: byte;
|
er, eg, eb: byte;
|
||||||
hr, hg, hb: byte;
|
hr, hg, hb: byte;
|
||||||
|
s_contours: pCvSeq;
|
||||||
|
area: Double;
|
||||||
begin
|
begin
|
||||||
Result := false;
|
Result := False;
|
||||||
Contours := nil;
|
FContours := nil;
|
||||||
th_image := nil;
|
th_image := nil;
|
||||||
storage := cvCreateMemStorage(0);
|
storage := cvCreateMemStorage(0);
|
||||||
try
|
try
|
||||||
@ -1218,15 +1261,28 @@ begin
|
|||||||
contoursCont := cvFindContours(th_image.IpImage, storage, @Contours, SizeOf(TCvContour), Integer(RetrievalMode),
|
contoursCont := cvFindContours(th_image.IpImage, storage, @Contours, SizeOf(TCvContour), Integer(RetrievalMode),
|
||||||
Integer(ApproximationMethod), cvPoint(Offset.X, Offset.Y));
|
Integer(ApproximationMethod), cvPoint(Offset.X, Offset.Y));
|
||||||
if ApproxPoly.Enabled then
|
if ApproxPoly.Enabled then
|
||||||
Contours := cvApproxPoly(Contours, SizeOf(TCvContour), storage, CV_POLY_APPROX_DP, ApproxPoly.Eps,
|
FContours := cvApproxPoly(Contours, SizeOf(TCvContour), storage, CV_POLY_APPROX_DP, ApproxPoly.Eps,
|
||||||
Integer(ApproxPoly.Recursive));
|
Integer(ApproxPoly.Recursive));
|
||||||
DoNotifyContours(Destanation, contoursCont, Contours);
|
DoNotifyContours(Destanation, contoursCont, Contours);
|
||||||
if (contoursCont > 0) and ContourDraw.Enabled then
|
if (contoursCont > 0) and ContourDraw.Enabled then
|
||||||
begin
|
begin
|
||||||
GetRGBValue(ContourDraw.ExternalColor, er, eg, eb);
|
GetRGBValue(ContourDraw.ExternalColor, er, eg, eb);
|
||||||
GetRGBValue(ContourDraw.HoleColor, hr, hg, hb);
|
GetRGBValue(ContourDraw.HoleColor, hr, hg, hb);
|
||||||
cvDrawContours(Destanation.IpImage, Contours, CV_RGB(er, eg, eb), CV_RGB(hr, hg, hb), ContourDraw.MaxLevel,
|
if MinArea > 0 then
|
||||||
ContourDraw.Thickness, cLineType[ContourDraw.LineType], cvPoint(ContourDraw.Offset.X, ContourDraw.Offset.Y));
|
begin
|
||||||
|
s_contours := Contours;
|
||||||
|
while (s_contours <> nil) do
|
||||||
|
begin
|
||||||
|
area := cvContourArea(s_contours, CV_WHOLE_SEQ);
|
||||||
|
if abs(area) > MinArea then
|
||||||
|
cvDrawContours(Destanation.IpImage, s_contours, CV_RGB(er, eg, eb), CV_RGB(hr, hg, hb), ContourDraw.MaxLevel,
|
||||||
|
ContourDraw.Thickness, cLineType[ContourDraw.LineType], cvPoint(ContourDraw.Offset.X, ContourDraw.Offset.Y));
|
||||||
|
s_contours := s_contours.h_next;
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
cvDrawContours(Destanation.IpImage, FContours, CV_RGB(er, eg, eb), CV_RGB(hr, hg, hb), ContourDraw.MaxLevel,
|
||||||
|
ContourDraw.Thickness, cLineType[ContourDraw.LineType], cvPoint(ContourDraw.Offset.X, ContourDraw.Offset.Y));
|
||||||
end;
|
end;
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
@ -1236,22 +1292,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TocvContoursOperation.DoNotifyContours(const Image: IocvImage; const ContourCount: Integer; const Contours: pCvSeq);
|
procedure TocvContoursOperation.DoNotifyContours(const Image: IocvImage; const ContourCount: Integer; const Contours: pCvSeq);
|
||||||
Var
|
|
||||||
NotifyTarget: TocvImageOperation;
|
|
||||||
begin
|
begin
|
||||||
if FOwner is TocvImageOperation then
|
if Assigned(OnContour) then
|
||||||
NotifyTarget := FOwner as TocvImageOperation
|
OnContour(Self, Image, ContourCount, Contours);
|
||||||
else {}
|
|
||||||
if
|
|
||||||
{} (FOwner is TocvImageOperationCollectionItem) and
|
|
||||||
{} ((FOwner as TocvImageOperationCollectionItem).GetOwner is TocvImageOperationCollection) and
|
|
||||||
{} (((FOwner as TocvImageOperationCollectionItem).GetOwner as TocvImageOperationCollection).Owner is TocvImageOperation) then
|
|
||||||
NotifyTarget := ((FOwner as TocvImageOperationCollectionItem).GetOwner as TocvImageOperationCollection)
|
|
||||||
.Owner as TocvImageOperation
|
|
||||||
else
|
|
||||||
NotifyTarget := nil;
|
|
||||||
if Assigned(NotifyTarget) then
|
|
||||||
NotifyTarget.DoNotifyContour(Self, Image, ContourCount, Contours);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TocvContoursOperation.UnlockTransform;
|
procedure TocvContoursOperation.UnlockTransform;
|
||||||
|
@ -31,16 +31,17 @@ implementation
|
|||||||
Uses
|
Uses
|
||||||
DesignIntf,
|
DesignIntf,
|
||||||
System.Classes,
|
System.Classes,
|
||||||
uOCVCamera,
|
uOCVSource,
|
||||||
uOCVView,
|
uOCVView,
|
||||||
uOCVImageOperation;
|
uOCVImageOperation;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
begin
|
begin
|
||||||
RegisterComponents('OpenCV', [TocvImageOperation]);
|
RegisterComponents('OpenCV', [TocvImageOperation,TocvCameraSource,TocvView,TocvFileSource,TocvIPCamSource]);
|
||||||
RegisterComponents('OpenCV', [TocvCamera]);
|
RegisterClasses([ TocvNoneOperation, TocvGrayScaleOperation, TovcCannyOperation,
|
||||||
RegisterComponents('OpenCV', [TocvView]);
|
TovcSmoothOperation, TovcErodeOperation, TovcDilateOperation,
|
||||||
RegisterClasses([TocvNoneOperation, TocvGrayScaleOperation, TovcCannyOperation, TovcSmoothOperation, TovcErodeOperation, TovcDilateOperation, TocvLaplaceOperation, TovcSobelOperation, TocvThresholdOperation, TocvAdaptiveThresholdOperation, TocvContoursOperation, TocvRotateOperation]);
|
TocvLaplaceOperation, TovcSobelOperation, TocvThresholdOperation,
|
||||||
|
TocvAdaptiveThresholdOperation, TocvContoursOperation, TocvRotateOperation]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
536
component/uOCVSource.pas
Normal file
536
component/uOCVSource.pas
Normal file
@ -0,0 +1,536 @@
|
|||||||
|
(* /*****************************************************************
|
||||||
|
// 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 uOCVSource;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
System.SysUtils,
|
||||||
|
System.Classes,
|
||||||
|
System.SyncObjs,
|
||||||
|
core.types_c,
|
||||||
|
highgui_c,
|
||||||
|
uOCVTypes;
|
||||||
|
|
||||||
|
type
|
||||||
|
TocvCameraCaptureSource =
|
||||||
|
//
|
||||||
|
(CAP_ANY {= 0} , // autodetect
|
||||||
|
CAP_CAM_0 {=0} , //
|
||||||
|
CAP_CAM_1 {=1} , //
|
||||||
|
CAP_CAM_2 {=2} , //
|
||||||
|
CAP_CAM_3 {=3} , //
|
||||||
|
CAP_CAM_4 {=4} , //
|
||||||
|
CAP_CAM_5 {=5} , //
|
||||||
|
CAP_MIL {= 100} , // MIL proprietary drivers
|
||||||
|
CAP_VFW {= 200} , // platform native
|
||||||
|
CAP_V4L {= 200} , //
|
||||||
|
CAP_V4L2 {= 200} , //
|
||||||
|
CAP_FIREWARE {= 300} , // IEEE 1394 drivers
|
||||||
|
CAP_FIREWIRE {= 300} , //
|
||||||
|
CAP_IEEE1394 {= 300} , //
|
||||||
|
CAP_DC1394 {= 300} , //
|
||||||
|
CAP_CMU1394 {= 300} , //
|
||||||
|
CAP_STEREO {= 400} , // TYZX proprietary drivers
|
||||||
|
CAP_TYZX {= 400} , //
|
||||||
|
TYZX_LEFT {= 400} , //
|
||||||
|
TYZX_RIGHT {= 401} , //
|
||||||
|
TYZX_COLOR {= 402} , //
|
||||||
|
TYZX_Z {= 403} , //
|
||||||
|
CAP_QT {= 500} , // QuickTime
|
||||||
|
CAP_UNICAP {= 600} , // Unicap drivers
|
||||||
|
CAP_DSHOW {= 700} , // DirectShow (via videoInput)
|
||||||
|
CAP_PVAPI {= 800} , // PvAPI, Prosilica GigE SDK
|
||||||
|
CAP_OPENNI {= 900} , // OpenNI (for Kinect)
|
||||||
|
CAP_OPENNI_ASUS {= 910} , // OpenNI (for Asus Xtion)
|
||||||
|
CAP_ANDROID {= 1000} , // Android
|
||||||
|
CAP_XIAPI {= 1100} , // XIMEA Camera API
|
||||||
|
CAP_AVFOUNDATION {= 1200} );
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
TocvCustomSourceThread = class(TThread)
|
||||||
|
private
|
||||||
|
FOnNotifyData: TOnOcvNotify;
|
||||||
|
FOnNoData: TNotifyEvent;
|
||||||
|
FThreadDelay: Integer;
|
||||||
|
FLock: TCriticalSection;
|
||||||
|
procedure SetCapture(const Value: pCvCapture); virtual;
|
||||||
|
protected
|
||||||
|
FCapture: pCvCapture;
|
||||||
|
public
|
||||||
|
constructor Create(CreateSuspended: Boolean);
|
||||||
|
destructor Destroy; override;
|
||||||
|
property OnNoData: TNotifyEvent Read FOnNoData write FOnNoData;
|
||||||
|
property OnNotifyData: TOnOcvNotify Read FOnNotifyData write FOnNotifyData;
|
||||||
|
property Capture: pCvCapture read FCapture write SetCapture;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TocvCaptureThread = class(TocvCustomSourceThread)
|
||||||
|
protected
|
||||||
|
procedure Execute; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TocvCustomSource = class(TocvDataSource)
|
||||||
|
protected
|
||||||
|
FCapture: pCvCapture;
|
||||||
|
FSourceThread: TocvCustomSourceThread;
|
||||||
|
FThreadDelay: Integer;
|
||||||
|
procedure OnNotifyData(Sender: TObject; const IplImage: IocvImage);
|
||||||
|
procedure SetEnabled(Value: Boolean); virtual;
|
||||||
|
procedure Loaded; override;
|
||||||
|
private
|
||||||
|
FEnabled: Boolean;
|
||||||
|
FOnImage: TOnOcvNotify;
|
||||||
|
procedure TerminateSourceThread;
|
||||||
|
procedure ReleaseSource;
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
destructor Destroy; override;
|
||||||
|
published
|
||||||
|
property Enabled: Boolean Read FEnabled write SetEnabled default False;
|
||||||
|
property OnImage: TOnOcvNotify read FOnImage write FOnImage;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TocvResolution = (r160x120, r320x240, r424x240, r640x360, r800x448, r960x544, r1280x720);
|
||||||
|
|
||||||
|
TocvCameraSource = class(TocvCustomSource)
|
||||||
|
protected
|
||||||
|
procedure SetEnabled(Value: Boolean); override;
|
||||||
|
private
|
||||||
|
FCaptureSource: TocvCameraCaptureSource;
|
||||||
|
FResolution: TocvResolution;
|
||||||
|
procedure SetCameraSource(const Value: TocvCameraCaptureSource);
|
||||||
|
procedure SetResolution(const Value: TocvResolution);
|
||||||
|
procedure SetCameraResolution;
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
published
|
||||||
|
property Camera: TocvCameraCaptureSource read FCaptureSource write SetCameraSource default CAP_ANY;
|
||||||
|
property Resolution: TocvResolution read FResolution write SetResolution;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TocvFileSource = class(TocvCustomSource)
|
||||||
|
protected
|
||||||
|
procedure SetEnabled(Value: Boolean); override;
|
||||||
|
procedure OnNoData(Sender: TObject);
|
||||||
|
private
|
||||||
|
FFileName: TFileName;
|
||||||
|
FLoop: Boolean;
|
||||||
|
FOnEndOfFile: TNotifyEvent;
|
||||||
|
FDelay: Integer;
|
||||||
|
procedure SetFileName(const Value: TFileName);
|
||||||
|
procedure SetDelay(const Value: Integer);
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
published
|
||||||
|
property Delay: Integer read FDelay write SetDelay default (1000 div 25);
|
||||||
|
property FileName: TFileName read FFileName write SetFileName;
|
||||||
|
property Loop: Boolean read FLoop write FLoop default True;
|
||||||
|
property OnEndOfFile: TNotifyEvent read FOnEndOfFile Write FOnEndOfFile;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TocvIPCamSource = class(TocvCustomSource)
|
||||||
|
private
|
||||||
|
FPort: Word;
|
||||||
|
FPassword: string;
|
||||||
|
FIP: string;
|
||||||
|
FUserName: String;
|
||||||
|
FPostfix: string;
|
||||||
|
protected
|
||||||
|
procedure SetEnabled(Value: Boolean); override;
|
||||||
|
public
|
||||||
|
constructor Create(AOwner: TComponent); override;
|
||||||
|
published
|
||||||
|
property UserName: String read FUserName write FUserName;
|
||||||
|
property Password: string read FPassword write FPassword;
|
||||||
|
property IP: string read FIP write FIP;
|
||||||
|
property Postfix: string read FPostfix write FPostfix; {TODO: Need rename}
|
||||||
|
property Port: Word read FPort write FPort default 554;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
core_c;
|
||||||
|
|
||||||
|
const
|
||||||
|
ocvCameraCaptureSource: array [TocvCameraCaptureSource] of Longint =
|
||||||
|
//
|
||||||
|
(CV_CAP_ANY, // autodetect
|
||||||
|
CV_CAP_CAM_0, //
|
||||||
|
CV_CAP_CAM_1, //
|
||||||
|
CV_CAP_CAM_2, //
|
||||||
|
CV_CAP_CAM_3, //
|
||||||
|
CV_CAP_CAM_4, //
|
||||||
|
CV_CAP_CAM_5, //
|
||||||
|
CV_CAP_MIL, // MIL proprietary drivers
|
||||||
|
CV_CAP_VFW, // platform native
|
||||||
|
CV_CAP_V4L, //
|
||||||
|
CV_CAP_V4L2, //
|
||||||
|
CV_CAP_FIREWARE, // IEEE 1394 drivers
|
||||||
|
CV_CAP_FIREWIRE, //
|
||||||
|
CV_CAP_IEEE1394, //
|
||||||
|
CV_CAP_DC1394, //
|
||||||
|
CV_CAP_CMU1394, //
|
||||||
|
CV_CAP_STEREO, // TYZX proprietary drivers
|
||||||
|
CV_CAP_TYZX, //
|
||||||
|
CV_TYZX_LEFT, //
|
||||||
|
CV_TYZX_RIGHT, //
|
||||||
|
CV_TYZX_COLOR, //
|
||||||
|
CV_TYZX_Z, //
|
||||||
|
CV_CAP_QT, // QuickTime
|
||||||
|
CV_CAP_UNICAP, // Unicap drivers
|
||||||
|
CV_CAP_DSHOW, // DirectShow (via videoInput)
|
||||||
|
CV_CAP_PVAPI, // PvAPI; Prosilica GigE SDK
|
||||||
|
CV_CAP_OPENNI, // OpenNI (for Kinect)
|
||||||
|
CV_CAP_OPENNI_ASUS, // OpenNI (for Asus Xtion)
|
||||||
|
CV_CAP_ANDROID, // Android
|
||||||
|
CV_CAP_XIAPI, // XIMEA Camera API
|
||||||
|
CV_CAP_AVFOUNDATION);
|
||||||
|
|
||||||
|
Type
|
||||||
|
TCameraResolution = record
|
||||||
|
cWidth, cHeight: Integer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Const
|
||||||
|
CameraResolution: array [TocvResolution] of TCameraResolution = ((cWidth: 160; cHeight: 120), (cWidth: 320; cHeight: 240),
|
||||||
|
(cWidth: 424; cHeight: 240), (cWidth: 640; cHeight: 360), (cWidth: 800; cHeight: 448), (cWidth: 960; cHeight: 544),
|
||||||
|
(cWidth: 1280; cHeight: 720));
|
||||||
|
|
||||||
|
{TOpenCVCameraThread}
|
||||||
|
|
||||||
|
procedure TocvCaptureThread.Execute;
|
||||||
|
Var
|
||||||
|
frame: pIplImage;
|
||||||
|
begin
|
||||||
|
while not Terminated do
|
||||||
|
if Assigned(FCapture) then
|
||||||
|
begin
|
||||||
|
try
|
||||||
|
FLock.Enter;
|
||||||
|
try
|
||||||
|
frame := cvQueryFrame(FCapture);
|
||||||
|
finally
|
||||||
|
FLock.Leave;
|
||||||
|
end;
|
||||||
|
if not Terminated then
|
||||||
|
begin
|
||||||
|
if Assigned(frame) then
|
||||||
|
begin
|
||||||
|
if Assigned(OnNotifyData) then
|
||||||
|
Synchronize(
|
||||||
|
procedure
|
||||||
|
begin
|
||||||
|
OnNotifyData(Self, TocvImage.CreateClone(frame));
|
||||||
|
end);
|
||||||
|
Sleep(FThreadDelay);
|
||||||
|
end
|
||||||
|
else if Assigned(OnNoData) then
|
||||||
|
OnNoData(Self);
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Suspend;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{TOpenCVCamera}
|
||||||
|
|
||||||
|
constructor TocvCameraSource.Create(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
FEnabled := False;
|
||||||
|
FResolution := r160x120;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCameraSource.SetCameraSource(const Value: TocvCameraCaptureSource);
|
||||||
|
Var
|
||||||
|
isEnabled: Boolean;
|
||||||
|
begin
|
||||||
|
if FCaptureSource <> Value then
|
||||||
|
begin
|
||||||
|
isEnabled := Enabled;
|
||||||
|
if Assigned(FCapture) and FEnabled then
|
||||||
|
Enabled := False;
|
||||||
|
FCaptureSource := Value;
|
||||||
|
Enabled := isEnabled;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCameraSource.SetEnabled(Value: Boolean);
|
||||||
|
begin
|
||||||
|
if FEnabled <> Value then
|
||||||
|
begin
|
||||||
|
if not(csDesigning in ComponentState) then
|
||||||
|
begin
|
||||||
|
if Assigned(FCapture) and FEnabled then
|
||||||
|
begin
|
||||||
|
FSourceThread.Capture := nil;
|
||||||
|
cvReleaseCapture(FCapture);
|
||||||
|
FCapture := Nil;
|
||||||
|
end;
|
||||||
|
if Value then
|
||||||
|
begin
|
||||||
|
FCapture := cvCreateCameraCapture(ocvCameraCaptureSource[FCaptureSource]);
|
||||||
|
if Assigned(FCapture) then
|
||||||
|
begin
|
||||||
|
SetCameraResolution;
|
||||||
|
FSourceThread.Capture := FCapture;
|
||||||
|
FSourceThread.Resume;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
FEnabled := Value;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCameraSource.SetCameraResolution;
|
||||||
|
begin
|
||||||
|
cvSetCaptureProperty(FCapture, CV_CAP_PROP_FRAME_WIDTH, CameraResolution[FResolution].cWidth);
|
||||||
|
cvSetCaptureProperty(FCapture, CV_CAP_PROP_FRAME_HEIGHT, CameraResolution[FResolution].cHeight);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCameraSource.SetResolution(const Value: TocvResolution);
|
||||||
|
begin
|
||||||
|
if FResolution <> Value then
|
||||||
|
begin
|
||||||
|
FResolution := Value;
|
||||||
|
if Enabled then
|
||||||
|
begin
|
||||||
|
Enabled := False;
|
||||||
|
Enabled := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{TocvCustomSource}
|
||||||
|
|
||||||
|
constructor TocvCustomSource.Create(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
if not(csDesigning in ComponentState) then
|
||||||
|
begin
|
||||||
|
FSourceThread := TocvCaptureThread.Create(True);
|
||||||
|
FSourceThread.OnNotifyData := OnNotifyData;
|
||||||
|
FSourceThread.FThreadDelay := FThreadDelay;
|
||||||
|
FSourceThread.FreeOnTerminate := True;
|
||||||
|
end;
|
||||||
|
FThreadDelay := 10;
|
||||||
|
FEnabled := False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TocvCustomSource.Destroy;
|
||||||
|
begin
|
||||||
|
TerminateSourceThread;
|
||||||
|
ReleaseSource;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomSource.Loaded;
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
if Enabled and (not Assigned(FCapture)) then
|
||||||
|
begin
|
||||||
|
// Hack
|
||||||
|
FEnabled := False;
|
||||||
|
Enabled := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomSource.OnNotifyData(Sender: TObject; const IplImage: IocvImage);
|
||||||
|
begin
|
||||||
|
if Assigned(OnImage) then
|
||||||
|
OnImage(Self, IplImage);
|
||||||
|
NotifyReceiver(IplImage);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomSource.SetEnabled(Value: Boolean);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomSource.TerminateSourceThread;
|
||||||
|
begin
|
||||||
|
if Assigned(FSourceThread) then
|
||||||
|
begin
|
||||||
|
FSourceThread.Terminate;
|
||||||
|
if FSourceThread.Suspended then
|
||||||
|
FSourceThread.Resume;
|
||||||
|
FSourceThread := Nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomSource.ReleaseSource;
|
||||||
|
begin
|
||||||
|
if Assigned(FCapture) then
|
||||||
|
begin
|
||||||
|
cvReleaseCapture(FCapture);
|
||||||
|
FCapture := nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{TocvFileSourceclass}
|
||||||
|
|
||||||
|
constructor TocvFileSource.Create(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
FLoop := True;
|
||||||
|
FDelay := (1000 div 25);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvFileSource.OnNoData(Sender: TObject);
|
||||||
|
begin
|
||||||
|
if Assigned(FOnEndOfFile) then
|
||||||
|
FOnEndOfFile(Self);
|
||||||
|
if Loop then
|
||||||
|
begin
|
||||||
|
Enabled := False;
|
||||||
|
Enabled := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvFileSource.SetDelay(const Value: Integer);
|
||||||
|
begin
|
||||||
|
if FDelay <> Value then
|
||||||
|
begin
|
||||||
|
FDelay := Value;
|
||||||
|
if Assigned(FSourceThread) then
|
||||||
|
FSourceThread.FThreadDelay := FDelay;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvFileSource.SetEnabled(Value: Boolean);
|
||||||
|
begin
|
||||||
|
if FEnabled <> Value then
|
||||||
|
begin
|
||||||
|
if not(csDesigning in ComponentState) then
|
||||||
|
begin
|
||||||
|
if Assigned(FCapture) and FEnabled then
|
||||||
|
begin
|
||||||
|
FSourceThread.Capture := nil;
|
||||||
|
cvReleaseCapture(FCapture);
|
||||||
|
FCapture := Nil;
|
||||||
|
end;
|
||||||
|
if Value then
|
||||||
|
begin
|
||||||
|
FCapture := cvCreateFileCapture(PAnsiChar(AnsiString(FileName)));
|
||||||
|
if Assigned(FCapture) then
|
||||||
|
begin
|
||||||
|
FSourceThread.Capture := FCapture;
|
||||||
|
FSourceThread.Resume;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
FEnabled := Value;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvFileSource.SetFileName(const Value: TFileName);
|
||||||
|
Var
|
||||||
|
_Enabled: Boolean;
|
||||||
|
begin
|
||||||
|
if FFileName <> Value then
|
||||||
|
begin
|
||||||
|
_Enabled := Enabled;
|
||||||
|
Enabled := False;
|
||||||
|
FFileName := Value;
|
||||||
|
Enabled := _Enabled;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{TocvCustomSourceThread}
|
||||||
|
|
||||||
|
constructor TocvCustomSourceThread.Create(CreateSuspended: Boolean);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
FThreadDelay := 10;
|
||||||
|
FLock := TCriticalSection.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TocvCustomSourceThread.Destroy;
|
||||||
|
begin
|
||||||
|
FLock.Free;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvCustomSourceThread.SetCapture(const Value: pCvCapture);
|
||||||
|
begin
|
||||||
|
FLock.Enter;
|
||||||
|
try
|
||||||
|
FCapture := Value;
|
||||||
|
finally
|
||||||
|
FLock.Leave;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{TocvIPCamSource}
|
||||||
|
|
||||||
|
constructor TocvIPCamSource.Create(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
FPort := 554;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TocvIPCamSource.SetEnabled(Value: Boolean);
|
||||||
|
Var
|
||||||
|
IPCam: AnsiString;
|
||||||
|
begin
|
||||||
|
if FEnabled <> Value then
|
||||||
|
begin
|
||||||
|
if not(csDesigning in ComponentState) then
|
||||||
|
begin
|
||||||
|
if Assigned(FCapture) and FEnabled then
|
||||||
|
begin
|
||||||
|
FSourceThread.Capture := nil;
|
||||||
|
cvReleaseCapture(FCapture);
|
||||||
|
FCapture := Nil;
|
||||||
|
end;
|
||||||
|
if Value then
|
||||||
|
begin
|
||||||
|
IPCam := 'rtsp://';
|
||||||
|
if Length(Trim(UserName)) <> 0 then
|
||||||
|
IPCam := IPCam + Trim(UserName) + ':' + Trim(Password) + '@';
|
||||||
|
IPCam := IPCam + IP + ':' + Port.ToString;
|
||||||
|
if Length(Trim(Postfix)) > 0 then
|
||||||
|
begin
|
||||||
|
if (IPCam[Length(IPCam)] <> '/') and (Postfix[1] <> '/') then
|
||||||
|
IPCam := IPCam + '/';
|
||||||
|
IPCam := IPCam + Postfix;
|
||||||
|
end;
|
||||||
|
FCapture := cvCreateFileCapture(PAnsiChar(IPCam));
|
||||||
|
if Assigned(FCapture) then
|
||||||
|
begin
|
||||||
|
FSourceThread.Capture := FCapture;
|
||||||
|
FSourceThread.Resume;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
FEnabled := Value;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
@ -50,7 +50,7 @@ Type
|
|||||||
function GetisGray: Boolean;
|
function GetisGray: Boolean;
|
||||||
public
|
public
|
||||||
constructor Create(const AImage: pIplImage);
|
constructor Create(const AImage: pIplImage);
|
||||||
constructor CreateCopy(const AImage: pIplImage);
|
constructor CreateClone(const AImage: pIplImage);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function GrayImage: IocvImage;
|
function GrayImage: IocvImage;
|
||||||
function Clone: IocvImage;
|
function Clone: IocvImage;
|
||||||
@ -241,7 +241,7 @@ end;
|
|||||||
|
|
||||||
function TocvImage.Clone: IocvImage;
|
function TocvImage.Clone: IocvImage;
|
||||||
begin
|
begin
|
||||||
Result := TocvImage.CreateCopy(FImage);
|
Result := TocvImage.CreateClone(FImage);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TocvImage.Create(const AImage: pIplImage);
|
constructor TocvImage.Create(const AImage: pIplImage);
|
||||||
@ -249,7 +249,7 @@ begin
|
|||||||
FImage := AImage;
|
FImage := AImage;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TocvImage.CreateCopy(const AImage: pIplImage);
|
constructor TocvImage.CreateClone(const AImage: pIplImage);
|
||||||
begin
|
begin
|
||||||
FImage := cvCloneImage(AImage);
|
FImage := cvCloneImage(AImage);
|
||||||
end;
|
end;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<FrameworkType>VCL</FrameworkType>
|
<FrameworkType>VCL</FrameworkType>
|
||||||
<MainSource>cCameraCapture.dpr</MainSource>
|
<MainSource>cCameraCapture.dpr</MainSource>
|
||||||
<Base>True</Base>
|
<Base>True</Base>
|
||||||
<Config Condition="'$(Config)'==''">Release</Config>
|
<Config Condition="'$(Config)'==''">Debug</Config>
|
||||||
<Platform Condition="'$(Platform)'==''">Win32</Platform>
|
<Platform Condition="'$(Platform)'==''">Win32</Platform>
|
||||||
<TargetedPlatforms>1</TargetedPlatforms>
|
<TargetedPlatforms>1</TargetedPlatforms>
|
||||||
<AppType>Application</AppType>
|
<AppType>Application</AppType>
|
||||||
|
@ -4,8 +4,8 @@ object MainForm: TMainForm
|
|||||||
BorderIcons = [biSystemMenu, biMinimize]
|
BorderIcons = [biSystemMenu, biMinimize]
|
||||||
BorderStyle = bsSingle
|
BorderStyle = bsSingle
|
||||||
Caption = 'OpenCV - Component demo'
|
Caption = 'OpenCV - Component demo'
|
||||||
ClientHeight = 499
|
ClientHeight = 550
|
||||||
ClientWidth = 466
|
ClientWidth = 616
|
||||||
Color = clBtnFace
|
Color = clBtnFace
|
||||||
Font.Charset = DEFAULT_CHARSET
|
Font.Charset = DEFAULT_CHARSET
|
||||||
Font.Color = clWindowText
|
Font.Color = clWindowText
|
||||||
@ -18,15 +18,15 @@ object MainForm: TMainForm
|
|||||||
PixelsPerInch = 96
|
PixelsPerInch = 96
|
||||||
TextHeight = 13
|
TextHeight = 13
|
||||||
object lbl1: TLabel
|
object lbl1: TLabel
|
||||||
Left = 308
|
Left = 8
|
||||||
Top = 8
|
Top = 8
|
||||||
Width = 79
|
Width = 79
|
||||||
Height = 13
|
Height = 13
|
||||||
Caption = 'Image operation'
|
Caption = 'Image operation'
|
||||||
end
|
end
|
||||||
object cbb1: TComboBox
|
object cbb1: TComboBox
|
||||||
Left = 308
|
Left = 93
|
||||||
Top = 24
|
Top = 5
|
||||||
Width = 145
|
Width = 145
|
||||||
Height = 21
|
Height = 21
|
||||||
Style = csDropDownList
|
Style = csDropDownList
|
||||||
@ -44,8 +44,8 @@ object MainForm: TMainForm
|
|||||||
'Threshold')
|
'Threshold')
|
||||||
end
|
end
|
||||||
object chk1: TCheckBox
|
object chk1: TCheckBox
|
||||||
Left = 308
|
Left = 8
|
||||||
Top = 60
|
Top = 29
|
||||||
Width = 97
|
Width = 97
|
||||||
Height = 17
|
Height = 17
|
||||||
Caption = 'Camera enabled'
|
Caption = 'Camera enabled'
|
||||||
@ -56,34 +56,88 @@ object MainForm: TMainForm
|
|||||||
end
|
end
|
||||||
object ocvw1: TocvView
|
object ocvw1: TocvView
|
||||||
Left = 8
|
Left = 8
|
||||||
Top = 8
|
Top = 52
|
||||||
Width = 285
|
Width = 285
|
||||||
Height = 229
|
Height = 229
|
||||||
VideoSource = ocvcmr1
|
VideoSource = ocvcmrsrc1
|
||||||
end
|
end
|
||||||
object ocvw2: TocvView
|
object ocvw2: TocvView
|
||||||
Left = 8
|
Left = 8
|
||||||
Top = 255
|
Top = 307
|
||||||
Width = 285
|
Width = 285
|
||||||
Height = 229
|
Height = 229
|
||||||
VideoSource = ocvmgprtn1
|
VideoSource = ocvmgprtn1
|
||||||
end
|
end
|
||||||
object ocvcmr1: TocvCamera
|
object ocvw3: TocvView
|
||||||
Resolution = r320x240
|
Left = 316
|
||||||
Left = 328
|
Top = 307
|
||||||
Top = 104
|
Width = 285
|
||||||
|
Height = 229
|
||||||
|
VideoSource = ocvflsrc1
|
||||||
|
end
|
||||||
|
object ocvw4: TocvView
|
||||||
|
Left = 316
|
||||||
|
Top = 52
|
||||||
|
Width = 285
|
||||||
|
Height = 229
|
||||||
|
VideoSource = ocvpcmsrc1
|
||||||
end
|
end
|
||||||
object ocvmgprtn1: TocvImageOperation
|
object ocvmgprtn1: TocvImageOperation
|
||||||
VideoSource = ocvcmr1
|
VideoSource = ocvcmrsrc1
|
||||||
OperationClassName = 'TocvRotateOperation'
|
OperationClassName = 'TocvContoursOperation'
|
||||||
Operation.Angle = 45
|
Operation.OperationClassName = 'TocvAdaptiveThresholdOperation'
|
||||||
Operation.RotateAroundCenter = False
|
Operation.Preprocessing.MaxValue = 250.000000000000000000
|
||||||
Operation.CustomCenter.X = 50
|
Operation.Preprocessing.BlockSize = 3
|
||||||
Operation.CustomCenter.Y = 50
|
Operation.Preprocessing.Param = 5.000000000000000000
|
||||||
Operation.Method = INTER_LANCZOS4
|
Operation.Offset.X = 0
|
||||||
Operation.Scale = 0.500000000000000000
|
Operation.Offset.Y = 0
|
||||||
Operations = <>
|
Operation.MinArea = 100
|
||||||
Left = 328
|
Operation.ContourDraw.Thickness = 1
|
||||||
Top = 164
|
Operation.ContourDraw.Offset.X = 0
|
||||||
|
Operation.ContourDraw.Offset.Y = 0
|
||||||
|
Operation.ApproxPoly.Eps = 3.000000000000000000
|
||||||
|
Operations = <
|
||||||
|
item
|
||||||
|
OperationClassName = 'TocvContoursOperation'
|
||||||
|
Operation.OperationClassName = 'TocvThresholdOperation'
|
||||||
|
Operation.Preprocessing.MaxValue = 255.000000000000000000
|
||||||
|
Operation.Preprocessing.ThresholdType = THRESH_BINARY_INV
|
||||||
|
Operation.Preprocessing.Threshold = 128.000000000000000000
|
||||||
|
Operation.Offset.X = 0
|
||||||
|
Operation.Offset.Y = 0
|
||||||
|
Operation.MinArea = 100
|
||||||
|
Operation.ContourDraw.Thickness = 1
|
||||||
|
Operation.ContourDraw.Offset.X = 0
|
||||||
|
Operation.ContourDraw.Offset.Y = 0
|
||||||
|
Operation.ApproxPoly.Eps = 3.000000000000000000
|
||||||
|
end
|
||||||
|
item
|
||||||
|
OperationClassName = 'TocvNoneOperation'
|
||||||
|
end>
|
||||||
|
OperationsEnabled = False
|
||||||
|
Left = 24
|
||||||
|
Top = 316
|
||||||
|
end
|
||||||
|
object ocvflsrc1: TocvFileSource
|
||||||
|
Enabled = True
|
||||||
|
Delay = 120
|
||||||
|
FileName = '.\Resource\768x576.avi'
|
||||||
|
Left = 336
|
||||||
|
Top = 328
|
||||||
|
end
|
||||||
|
object ocvcmrsrc1: TocvCameraSource
|
||||||
|
Enabled = True
|
||||||
|
Resolution = r160x120
|
||||||
|
Left = 32
|
||||||
|
Top = 64
|
||||||
|
end
|
||||||
|
object ocvpcmsrc1: TocvIPCamSource
|
||||||
|
Enabled = True
|
||||||
|
UserName = 'admin'
|
||||||
|
Password = 'admin'
|
||||||
|
IP = '10.1.1.202'
|
||||||
|
Postfix = 'cam/realmonitor?channel=1&subtype=0'
|
||||||
|
Left = 336
|
||||||
|
Top = 68
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
||||||
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uOCVTypes, uOCVImageOperation,
|
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uOCVTypes, uOCVImageOperation,
|
||||||
core.types_c, uOCVCamera, uOCVView, Vcl.StdCtrls, Vcl.ExtCtrls;
|
core.types_c, uOCVSource, uOCVView, Vcl.StdCtrls, Vcl.ExtCtrls;
|
||||||
|
|
||||||
type
|
type
|
||||||
TMainForm = class(TForm)
|
TMainForm = class(TForm)
|
||||||
@ -36,9 +36,13 @@ type
|
|||||||
cbb1: TComboBox;
|
cbb1: TComboBox;
|
||||||
chk1: TCheckBox;
|
chk1: TCheckBox;
|
||||||
ocvw1: TocvView;
|
ocvw1: TocvView;
|
||||||
ocvcmr1: TocvCamera;
|
|
||||||
ocvmgprtn1: TocvImageOperation;
|
ocvmgprtn1: TocvImageOperation;
|
||||||
ocvw2: TocvView;
|
ocvw2: TocvView;
|
||||||
|
ocvflsrc1: TocvFileSource;
|
||||||
|
ocvw3: TocvView;
|
||||||
|
ocvcmrsrc1: TocvCameraSource;
|
||||||
|
ocvw4: TocvView;
|
||||||
|
ocvpcmsrc1: TocvIPCamSource;
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure cbb1Change(Sender: TObject);
|
procedure cbb1Change(Sender: TObject);
|
||||||
procedure chk1Click(Sender: TObject);
|
procedure chk1Click(Sender: TObject);
|
||||||
@ -60,14 +64,15 @@ end;
|
|||||||
|
|
||||||
procedure TMainForm.chk1Click(Sender: TObject);
|
procedure TMainForm.chk1Click(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
ocvcmr1.Enabled := chk1.Checked;
|
ocvcmrsrc1.Enabled := chk1.Checked;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMainForm.FormCreate(Sender: TObject);
|
procedure TMainForm.FormCreate(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
cbb1.Items.Assign(GetRegisteredImageOperations);
|
cbb1.Items.Assign(GetRegisteredImageOperations);
|
||||||
cbb1.ItemIndex := cbb1.Items.IndexOf(GetRegisteredImageOperations.GetNameByClass(ocvmgprtn1.OperationClass));
|
cbb1.ItemIndex := cbb1.Items.IndexOf(GetRegisteredImageOperations.GetNameByClass(ocvmgprtn1.OperationClass));
|
||||||
ocvcmr1.Enabled := True;
|
// ocvcmrsrc1.Enabled := True;
|
||||||
|
// ocvpcmsrc1.Enabled := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user