Refactoring, new wrapper Opencv classes

Signed-off-by: Laentir Valetov <laex@bk.ru>
This commit is contained in:
Laentir Valetov 2014-04-04 21:14:06 +04:00
parent 0dcba1e673
commit 4f8d961498
76 changed files with 4586 additions and 372 deletions

63
.gitattributes vendored Normal file
View File

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

5
.gitignore vendored
View File

@ -37,4 +37,7 @@ __history
*.vlb *.vlb
/bin/carnumdetect.ini /bin/carnumdetect.ini
/bin/*.bsc /bin/*.bsc
/Bin/vclFaceRecogData /Bin/vclFaceRecogData
Debug
ipch
*.sdf

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,160 @@
// --------------------------------- OpenCV license.txt ---------------------------
(* // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage. *)
(* / **************************************************************************************************
// 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
// **************************************************************************************************
// License:
// The contents of this file are 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/
//
// 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.
//
// Alternatively, the contents of this file may be used under the terms of the
// GNU Lesser General Public License (the "LGPL License"), in which case the
// provisions of the LGPL License are applicable instead of those above.
// If you wish to allow use of your version of this file only under the terms
// of the LGPL License and not to allow others to use your version of this file
// under the MPL, indicate your decision by deleting the provisions above and
// replace them with the notice and other provisions required by the LGPL
// License. If you do not delete the provisions above, a recipient may use
// your version of this file under either the MPL or the LGPL License.
//
// For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
// **************************************************************************************************
// Warning: Using Delphi XE3 syntax!
// **************************************************************************************************
// The Initial Developer of the Original Code:
// OpenCV: open source computer vision library
// Homepage: http://opencv.org
// Online docs: http://docs.opencv.org
// Q&A forum: http://answers.opencv.org
// Dev zone: http://code.opencv.org
// **************************************************************************************************
// Original file:
// opencv\modules\core\include\opencv2\core\mat.hpp
// ************************************************************************************************* *)
unit Mat;
interface
Uses WinApi.Windows, Core.types_c;
const
MAGIC_VAL = $42FF0000;
AUTO_STEP = 0;
CONTINUOUS_FLAG = CV_MAT_CONT_FLAG;
SUBMATRIX_FLAG = CV_SUBMAT_FLAG;
MAGIC_MASK = $FFFF0000;
TYPE_MASK = $00000FFF;
DEPTH_MASK = 7;
Type
// Attention!
// The sequence of function declarations interface must match the
// sequence of function declarations in the project "opencv_classes" (C++)
IMat = interface
['{9C458D5C-F577-4A2D-89A0-FC426B80CC56}']
// ! returns element size in bytes,
// similar to CV_ELEM_SIZE(cvmat->type)
function elemSize(): size_t; stdcall;
// ! returns the size of element channel in bytes.
function elemSize1(): size_t; stdcall;
// ! returns element type, similar to CV_MAT_TYPE(cvmat->type)
function _type: Integer; stdcall;
// ! returns element type, similar to CV_MAT_DEPTH(cvmat->type)
function depth: Integer; stdcall;
// ! returns element type, similar to CV_MAT_CN(cvmat->type)
function channels: Integer; stdcall;
// ! returns step/elemSize1()
function step1(i: Integer = 0): size_t; stdcall;
// ! returns true if matrix data is NULL
function empty: bool; stdcall;
// ! returns the total number of matrix elements
function total: size_t; stdcall;
// * ! includes several bit - fields: - the magic signature - continuity flag - depth - number of channels * /
function flags: Integer; stdcall;
// ! the matrix dimensionality, >= 2
function dims: Integer; stdcall;
// ! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
function rows: Integer; stdcall;
function cols: Integer; stdcall;
// ! pointer to the data
function data: pByte; stdcall;
//! copies the matrix content to "m".
// It calls m.create(this->size(), this->type()).
procedure copyto(Var _mat:IMat); stdcall;
// ! pointer to the reference counter;
// when matrix points to user-allocated data, the pointer is NULL
function refcount: pInteger; stdcall;
// -----------------------------------
function getMat(): Pointer; stdcall;
// procedure setMat(mat:Pointer); stdcall;
end;
// ! default constructor
function CreateMat: IMat; overload; safecall;
// ! constructs 2D matrix of the specified size and type
// (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
function CreateMat(rows, cols, _type: Integer): IMat; overload; safecall;
function CreateMat(_mat: Pointer): IMat; overload; safecall;
implementation
Uses uLibName;
function CreateMat: IMat; external OpenCV_Classes_DLL name 'CreateMat';
function CreateMat(rows, cols, _type: Integer): IMat; external OpenCV_Classes_DLL name 'CreateMat_rct';
function CreateMat(_mat: Pointer): IMat; external OpenCV_Classes_DLL name 'CreateMat_Mat';
end.

View File

@ -167,15 +167,8 @@ function CString; external OpenCV_Classes_DLL index 300;
function TIplImageRecordHelper.InitFromMat(const Mat: IMat): TIplImage; function TIplImageRecordHelper.InitFromMat(const Mat: IMat): TIplImage;
begin begin
Assert(Mat.dims <= 2); Assert(Mat.dims <= 2);
cvInitImageHeader( cvInitImageHeader(@Self, CvSize(Mat.cols, Mat.rows), cvIplDepth(Mat.flags), Mat.channels);
@Self, cvSetData(@Self, Mat.data, Mat.step1);
CvSize(Mat.cols, Mat.rows),
cvIplDepth(Mat.flags),
Mat.channels);
cvSetData(
@Self,
Mat.data,
Mat.step1);
end; end;
end. end.

View File

@ -0,0 +1,245 @@
// --------------------------------- OpenCV license.txt ---------------------------
(* // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage. *)
(* / **************************************************************************************************
// 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
// **************************************************************************************************
// License:
// The contents of this file are 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/
//
// 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.
//
// Alternatively, the contents of this file may be used under the terms of the
// GNU Lesser General Public License (the "LGPL License"), in which case the
// provisions of the LGPL License are applicable instead of those above.
// If you wish to allow use of your version of this file only under the terms
// of the LGPL License and not to allow others to use your version of this file
// under the MPL, indicate your decision by deleting the provisions above and
// replace them with the notice and other provisions required by the LGPL
// License. If you do not delete the provisions above, a recipient may use
// your version of this file under either the MPL or the LGPL License.
//
// For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
// **************************************************************************************************
// Warning: Using Delphi XE3 syntax!
// **************************************************************************************************
// The Initial Developer of the Original Code:
// OpenCV: open source computer vision library
// Homepage: http://opencv.org
// Online docs: http://docs.opencv.org
// Q&A forum: http://answers.opencv.org
// Dev zone: http://code.opencv.org
// **************************************************************************************************
// Original file:
// opencv\modules\highgui\include\opencv2\highgui.hpp
// ************************************************************************************************* *)
unit highgui;
interface
Uses
WinApi.Windows,
Mat,
Core.types_c,
Core.types,
highgui_c;
Type
// Attention!
// The sequence of function declarations interface must match the
// sequence of function declarations in the project "opencv_classes" (C++)
IVideoCapture = interface
['{3F605CF0-ECAC-4230-B30B-AF9BFD516C4F}']
function open(device: Integer): bool; overload; stdcall;
function openfilename(filename: pAnsiChar): bool; overload; stdcall;
function isOpened(): bool; stdcall;
procedure release(); stdcall;
function grab(): bool; stdcall;
function retrieve(Var image: IMat; flag: Integer): bool; stdcall;
function read(Var image: IMat): bool; stdcall;
function setValue(propId: Integer; value: double): bool; stdcall;
function getValue(propId: Integer): double; stdcall;
end;
function CreateVideoCapture: IVideoCapture; overload; safecall;
function CreateVideoCapture(device: Integer): IVideoCapture; overload; safecall;
function CreateVideoCapture(filename: pAnsiChar): IVideoCapture; overload; safecall;
// Flags for namedWindow
Const
WINDOW_NORMAL = $00000000;
// the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size
WINDOW_AUTOSIZE = $00000001; // the user cannot resize the window, the size is constrainted by the image displayed
WINDOW_OPENGL = $00001000; // window with opengl support
WINDOW_FULLSCREEN = 1; // change the window to fullscreen
WINDOW_FREERATIO = $00000100; // the image expends as much as it can (no ratio constraint)
WINDOW_KEEPRATIO = $00000000; // the ratio of the image is respected
// CV_EXPORTS_W void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE);
procedure namedWindow(const winname: String; const flags: Integer = WINDOW_AUTOSIZE);
// CV_EXPORTS_W void destroyWindow(const String& winname);
procedure destroyWindow(const winname: String);
// CV_EXPORTS_W void destroyAllWindows();
procedure destroyAllWindows();
// CV_EXPORTS_W int startWindowThread();
function startWindowThread(): Integer;
// CV_EXPORTS_W int waitKey(int delay = 0);
function waitKey(const delay: Integer = 0): Integer;
// CV_EXPORTS_W void imshow(const String& winname, InputArray mat);
procedure imshow(const winname: String; const Mat: IMat);
// CV_EXPORTS_W void resizeWindow(const String& winname, int width, int height);
procedure resizeWindow(const winname: String; const width, height: Integer);
// CV_EXPORTS_W void moveWindow(const String& winname, int x, int y);
procedure moveWindow(const winname: String; const x, y: Integer);
// CV_EXPORTS_W void setWindowProperty(const String& winname, int prop_id, double prop_value);
procedure setWindowProperty(const winname: String; const prop_id: Integer; const prop_value: double);
// CV_EXPORTS_W double getWindowProperty(const String& winname, int prop_id);
function getWindowProperty(const winname: String; const prop_id: Integer): double;
// CV_EXPORTS int createTrackbar(const String& trackbarname, const String& winname,
// int* value, int count,
// TrackbarCallback onChange = 0,
// void* userdata = 0);
function createTrackbar(const trackbarname: String; const winname: String; value: PInteger; count: Integer; onChange: CvTrackbarCallback2 = nil;
userdata: Pointer = nil): Integer;
// CV_EXPORTS_W Mat imread( const string& filename, int flags=1 );
function imread(const filename: string; flag: Integer = 1): IMat;
// CV_EXPORTS_W bool imwrite( const string& filename, InputArray img, const vector<int>& params=vector<int>());
function imwrite(const filename: String; const img: IMat): bool;
implementation
Uses
uLibName,
cvUtils,
core_c;
function CreateVideoCapture: IVideoCapture; external OpenCV_Classes_DLL name 'CreateVideoCapture';
function CreateVideoCapture(device: Integer): IVideoCapture; external OpenCV_Classes_DLL name 'CreateVideoCapture_dvc';
function CreateVideoCapture(filename: pAnsiChar): IVideoCapture; external OpenCV_Classes_DLL name 'CreateVideoCapture_fln';
function _imread(const filename: pCvChar; flag: Integer): IMat; external OpenCV_Classes_DLL name '_imread';
function _imwrite(const filename: pCvChar; const img: IMat): bool; external OpenCV_Classes_DLL name '_imwrite';
function imread(const filename: string; flag: Integer): IMat;
begin
Result := _imread(c_str(filename), flag);
end;
function imwrite(const filename: String; const img: IMat): bool;
begin
Result := _imwrite(c_str(filename), img);
end;
procedure namedWindow(const winname: String; const flags: Integer = WINDOW_AUTOSIZE);
begin
cvNamedWindow(c_str(winname), flags);
end;
procedure destroyWindow(const winname: String);
begin
cvDestroyWindow(c_str(winname));
end;
procedure destroyAllWindows();
begin
cvDestroyAllWindows();
end;
function startWindowThread(): Integer;
begin
Result := cvStartWindowThread();
end;
function waitKey(const delay: Integer = 0): Integer;
begin
Result := cvWaitKey(delay);
end;
procedure imshow(const winname: String; const Mat: IMat);
Var
IplImage: TIplImage;
begin
IplImage.InitFromMat(Mat);
cvShowImage(c_str(winname), @IplImage);
end;
procedure resizeWindow(const winname: String; const width, height: Integer);
begin
cvResizeWindow(c_str(winname), width, height);
end;
procedure moveWindow(const winname: String; const x, y: Integer);
begin
cvMoveWindow(c_str(winname), x, y);
end;
procedure setWindowProperty(const winname: String; const prop_id: Integer; const prop_value: double);
begin
cvSetWindowProperty(c_str(winname), prop_id, prop_value);
end;
function getWindowProperty(const winname: String; const prop_id: Integer): double;
begin
Result := cvGetWindowProperty(c_str(winname), prop_id);
end;
function createTrackbar(const trackbarname: String; const winname: String; value: PInteger; count: Integer; onChange: CvTrackbarCallback2 = nil;
userdata: Pointer = nil): Integer;
begin
Result := cvCreateTrackbar2(c_str(trackbarname), c_str(winname), value, count, onChange, userdata);
end;
end.

2244
deprecated/include/ml/ml.pas Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,160 +1,77 @@
// --------------------------------- OpenCV license.txt --------------------------- // *****************************************************************
(* // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // Delphi-OpenCV Demo
// // Copyright (C) 2013 Project Delphi-OpenCV
// By downloading, copying, installing or using the software you agree to this license. // ****************************************************************
// If you do not agree to this license, do not download, install, // Contributor:
// copy or use the software. // Laentir Valetov
// // email:laex@bk.ru
// // ****************************************************************
// License Agreement // You may retrieve the latest version of this file at the GitHub,
// For Open Source Computer Vision Library // located at git://github.com/Laex/Delphi-OpenCV.git
// // ****************************************************************
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // The contents of this file are used with permission, subject to
// Copyright (C) 2009, Willow Garage Inc., all rights reserved. // the Mozilla Public License Version 1.1 (the "License"); you may
// Third party copyrights are property of their respective owners. // not use this file except in compliance with the License. You may
// // obtain a copy of the License at
// Redistribution and use in source and binary forms, with or without modification, // http://www.mozilla.org/MPL/MPL-1_1Final.html
// are permitted provided that the following conditions are met: //
// // Software distributed under the License is distributed on an
// * Redistribution's of source code must retain the above copyright notice, // "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
// this list of conditions and the following disclaimer. // implied. See the License for the specific language governing
// // rights and limitations under the License.
// * Redistribution's in binary form must reproduce the above copyright notice, // *******************************************************************
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage. *)
(* / ************************************************************************************************** unit mat;
// 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
// **************************************************************************************************
// License:
// The contents of this file are 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/
//
// 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.
//
// Alternatively, the contents of this file may be used under the terms of the
// GNU Lesser General Public License (the "LGPL License"), in which case the
// provisions of the LGPL License are applicable instead of those above.
// If you wish to allow use of your version of this file only under the terms
// of the LGPL License and not to allow others to use your version of this file
// under the MPL, indicate your decision by deleting the provisions above and
// replace them with the notice and other provisions required by the LGPL
// License. If you do not delete the provisions above, a recipient may use
// your version of this file under either the MPL or the LGPL License.
//
// For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
// **************************************************************************************************
// Warning: Using Delphi XE3 syntax!
// **************************************************************************************************
// The Initial Developer of the Original Code:
// OpenCV: open source computer vision library
// Homepage: http://opencv.org
// Online docs: http://docs.opencv.org
// Q&A forum: http://answers.opencv.org
// Dev zone: http://code.opencv.org
// **************************************************************************************************
// Original file:
// opencv\modules\core\include\opencv2\core\mat.hpp
// ************************************************************************************************* *)
unit Mat;
interface interface
Uses WinApi.Windows, Core.types_c; Uses
WinApi.Windows,
const core.types_c,
MAGIC_VAL = $42FF0000; highgui_c;
AUTO_STEP = 0;
CONTINUOUS_FLAG = CV_MAT_CONT_FLAG;
SUBMATRIX_FLAG = CV_SUBMAT_FLAG;
MAGIC_MASK = $FFFF0000;
TYPE_MASK = $00000FFF;
DEPTH_MASK = 7;
Type Type
TOCVMat = class
// Attention! public
// The sequence of function declarations interface must match the
// sequence of function declarations in the project "opencv_classes" (C++)
IMat = interface
['{9C458D5C-F577-4A2D-89A0-FC426B80CC56}']
// ! returns element size in bytes,
// similar to CV_ELEM_SIZE(cvmat->type) // similar to CV_ELEM_SIZE(cvmat->type)
function elemSize(): size_t; stdcall; function elemSize(): size_t; virtual; stdcall; abstract;
// ! returns the size of element channel in bytes. // ! returns the size of element channel in bytes.
function elemSize1(): size_t; stdcall; function elemSize1(): size_t; virtual; stdcall; abstract;
// ! returns element type, similar to CV_MAT_TYPE(cvmat->type) // ! returns element type, similar to CV_MAT_TYPE(cvmat->type)
function _type: Integer; stdcall; function _type: Integer; virtual; stdcall; abstract;
// ! returns element type, similar to CV_MAT_DEPTH(cvmat->type) // ! returns element type, similar to CV_MAT_DEPTH(cvmat->type)
function depth: Integer; stdcall; function depth: Integer; virtual; stdcall; abstract;
// ! returns element type, similar to CV_MAT_CN(cvmat->type) // ! returns element type, similar to CV_MAT_CN(cvmat->type)
function channels: Integer; stdcall; function channels: Integer; virtual; stdcall; abstract;
// ! returns step/elemSize1() // ! returns step/elemSize1()
function step1(i: Integer = 0): size_t; stdcall; function step1(i: Integer = 0): size_t; virtual; stdcall; abstract;
// ! returns true if matrix data is NULL // ! returns true if matrix data is NULL
function empty: bool; stdcall; function empty: bool; virtual; stdcall; abstract;
// ! returns the total number of matrix elements // ! returns the total number of matrix elements
function total: size_t; stdcall; function total: size_t; virtual; stdcall; abstract;
// * ! includes several bit - fields: - the magic signature - continuity flag - depth - number of channels * / // * ! includes several bit - fields: - the magic signature - continuity flag - depth - number of channels * /
function flags: Integer; stdcall; function flags: Integer; virtual; stdcall; abstract;
// ! the matrix dimensionality, >= 2 // ! the matrix dimensionality, >= 2
function dims: Integer; stdcall; function dims: Integer; virtual; stdcall; abstract;
// ! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions // ! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
function rows: Integer; stdcall; function rows: Integer; virtual; stdcall; abstract;
function cols: Integer; stdcall; function cols: Integer; virtual; stdcall; abstract;
// ! pointer to the data // ! pointer to the data
function data: pByte; stdcall; function data: pByte; virtual; stdcall; abstract;
//! copies the matrix content to "m". // ------------------------------------------------
// It calls m.create(this->size(), this->type()).
procedure copyto(Var _mat:IMat); stdcall;
// ! pointer to the reference counter;
// when matrix points to user-allocated data, the pointer is NULL
function refcount: pInteger; stdcall;
// -----------------------------------
function getMat(): Pointer; stdcall;
// procedure setMat(mat:Pointer); stdcall;
end; end;
// ! default constructor function CreateMat: TOCVMat; stdcall; overload;
function CreateMat: IMat; overload; safecall; function CreateMat(rows, cols, _type: Integer): TOCVMat; stdcall; overload;
// ! constructs 2D matrix of the specified size and type procedure ReleaseMat(ex: TOCVMat); stdcall;
// (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
function CreateMat(rows, cols, _type: Integer): IMat; overload; safecall;
function CreateMat(_mat: Pointer): IMat; overload; safecall;
implementation implementation
Uses uLibName; Uses
uLibName;
function CreateMat: IMat; external OpenCV_Classes_DLL name 'CreateMat'; function CreateMat: TOCVMat; stdcall; external OpenCV_Classes_DLL name 'CreateMat'; overload;
function CreateMat(rows, cols, _type: Integer): IMat; external OpenCV_Classes_DLL name 'CreateMat_rct'; function CreateMat(rows, cols, _type: Integer): TOCVMat; stdcall; external OpenCV_Classes_DLL name 'CreateMatRCT'; overload;
function CreateMat(_mat: Pointer): IMat; external OpenCV_Classes_DLL name 'CreateMat_Mat'; procedure ReleaseMat; external OpenCV_Classes_DLL;
end. end.

View File

@ -1,85 +1,85 @@
// --------------------------------- OpenCV license.txt --------------------------- // --------------------------------- OpenCV license.txt ---------------------------
(* // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
// //
// By downloading, copying, installing or using the software you agree to this license. // By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install, // If you do not agree to this license, do not download, install,
// copy or use the software. // copy or use the software.
// //
// //
// License Agreement // License Agreement
// For Open Source Computer Vision Library // For Open Source Computer Vision Library
// //
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners. // Third party copyrights are property of their respective owners.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// * Redistribution's of source code must retain the above copyright notice, // * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// * Redistribution's in binary form must reproduce the above copyright notice, // * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation // this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution. // and/or other materials provided with the distribution.
// //
// * The name of the copyright holders may not be used to endorse or promote products // * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission. // derived from this software without specific prior written permission.
// //
// This software is provided by the copyright holders and contributors "as is" and // This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied // any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed. // warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct, // In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages // indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services; // (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused // loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability, // and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of // or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage. *) // the use of this software, even if advised of the possibility of such damage. *)
(* / ************************************************************************************************** // **************************************************************************************************
// Project Delphi-OpenCV // Project Delphi-OpenCV
// ************************************************************************************************** // **************************************************************************************************
// Contributor: // Contributor:
// laentir Valetov // laentir Valetov
// email:laex@bk.ru // email:laex@bk.ru
// ************************************************************************************************** // **************************************************************************************************
// You may retrieve the latest version of this file at the GitHub, // You may retrieve the latest version of this file at the GitHub,
// located at git://github.com/Laex/Delphi-OpenCV.git // located at git://github.com/Laex/Delphi-OpenCV.git
// ************************************************************************************************** // **************************************************************************************************
// License: // License:
// The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); // The contents of this file are 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 // 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/ // License at http://www.mozilla.org/MPL/
// //
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF // 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 // ANY KIND, either express or implied. See the License for the specific language governing rights
// and limitations under the License. // and limitations under the License.
// //
// Alternatively, the contents of this file may be used under the terms of the // Alternatively, the contents of this file may be used under the terms of the
// GNU Lesser General Public License (the "LGPL License"), in which case the // GNU Lesser General Public License (the "LGPL License"), in which case the
// provisions of the LGPL License are applicable instead of those above. // provisions of the LGPL License are applicable instead of those above.
// If you wish to allow use of your version of this file only under the terms // If you wish to allow use of your version of this file only under the terms
// of the LGPL License and not to allow others to use your version of this file // of the LGPL License and not to allow others to use your version of this file
// under the MPL, indicate your decision by deleting the provisions above and // under the MPL, indicate your decision by deleting the provisions above and
// replace them with the notice and other provisions required by the LGPL // replace them with the notice and other provisions required by the LGPL
// License. If you do not delete the provisions above, a recipient may use // License. If you do not delete the provisions above, a recipient may use
// your version of this file under either the MPL or the LGPL License. // your version of this file under either the MPL or the LGPL License.
// //
// For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html // For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
// ************************************************************************************************** // **************************************************************************************************
// Warning: Using Delphi XE3 syntax! // Warning: Using Delphi XE3 syntax!
// ************************************************************************************************** // **************************************************************************************************
// The Initial Developer of the Original Code: // The Initial Developer of the Original Code:
// OpenCV: open source computer vision library // OpenCV: open source computer vision library
// Homepage: http://opencv.org // Homepage: http://opencv.org
// Online docs: http://docs.opencv.org // Online docs: http://docs.opencv.org
// Q&A forum: http://answers.opencv.org // Q&A forum: http://answers.opencv.org
// Dev zone: http://code.opencv.org // Dev zone: http://code.opencv.org
// ************************************************************************************************** // **************************************************************************************************
// Original file: // Original file:
// opencv\modules\highgui\include\opencv2\highgui.hpp // opencv\modules\highgui\include\opencv2\highgui.hpp
// ************************************************************************************************* *) // *************************************************************************************************
unit highgui; unit highgui;
@ -87,9 +87,8 @@ interface
Uses Uses
WinApi.Windows, WinApi.Windows,
Mat, mat,
Core.types_c, Core.types_c,
Core.types,
highgui_c; highgui_c;
Type Type
@ -98,35 +97,33 @@ Type
// The sequence of function declarations interface must match the // The sequence of function declarations interface must match the
// sequence of function declarations in the project "opencv_classes" (C++) // sequence of function declarations in the project "opencv_classes" (C++)
IVideoCapture = interface TOCVVideoCapture = class
['{3F605CF0-ECAC-4230-B30B-AF9BFD516C4F}'] function open(device: Integer): bool; overload; virtual; stdcall; abstract;
function open(device: Integer): bool; overload; stdcall; function openfile(filename: pAnsiChar): bool; overload; virtual; stdcall; abstract;
function openfilename(filename: pAnsiChar): bool; overload; stdcall; function isOpened(): bool; virtual; stdcall; abstract;
function isOpened(): bool; stdcall; procedure release(); virtual; stdcall; abstract;
procedure release(); stdcall; function grab(): bool; virtual; stdcall; abstract;
function retrieve(Var image: TOCVMat; flag: Integer): bool; virtual; stdcall; abstract;
function grab(): bool; stdcall; function read(Var image: TOCVMat): bool; virtual; stdcall; abstract;
function retrieve(Var image: IMat; flag: Integer): bool; stdcall; function setValue(propId: Integer; value: double): bool; virtual; stdcall; abstract;
function read(Var image: IMat): bool; stdcall; function getValue(propId: Integer): double; virtual; stdcall; abstract;
function setValue(propId: Integer; value: double): bool; stdcall;
function getValue(propId: Integer): double; stdcall;
end; end;
function CreateVideoCapture: IVideoCapture; overload; safecall; function CreateVideoCapture: TOCVVideoCapture; stdcall; overload;
function CreateVideoCapture(device: Integer): IVideoCapture; overload; safecall; function CreateVideoCapture(device: Integer): TOCVVideoCapture; stdcall; overload;
function CreateVideoCapture(filename: pAnsiChar): IVideoCapture; overload; safecall; function CreateVideoCapture(filename: pAnsiChar): TOCVVideoCapture; stdcall; overload;
procedure DestroyVideoCapture(ex: TOCVVideoCapture); stdcall;
// Flags for namedWindow // Flags for namedWindow
Const Const
WINDOW_NORMAL = $00000000; WINDOW_NORMAL = $00000000;
// the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size // the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size
WINDOW_AUTOSIZE = $00000001; // the user cannot resize the window, the size is constrainted by the image displayed WINDOW_AUTOSIZE = $00000001; // the user cannot resize the window, the size is constrainted by the image displayed
WINDOW_OPENGL = $00001000; // window with opengl support WINDOW_OPENGL = $00001000; // window with opengl support
WINDOW_FULLSCREEN = 1; // change the window to fullscreen WINDOW_FULLSCREEN = 1; // change the window to fullscreen
WINDOW_FREERATIO = $00000100; // the image expends as much as it can (no ratio constraint) WINDOW_FREERATIO = $00000100; // the image expends as much as it can (no ratio constraint)
WINDOW_KEEPRATIO = $00000000; // the ratio of the image is respected WINDOW_KEEPRATIO = $00000000; // the ratio of the image is respected
// CV_EXPORTS_W void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE); // CV_EXPORTS_W void namedWindow(const String& winname, int flags = WINDOW_AUTOSIZE);
procedure namedWindow(const winname: String; const flags: Integer = WINDOW_AUTOSIZE); procedure namedWindow(const winname: String; const flags: Integer = WINDOW_AUTOSIZE);
@ -139,7 +136,7 @@ function startWindowThread(): Integer;
// CV_EXPORTS_W int waitKey(int delay = 0); // CV_EXPORTS_W int waitKey(int delay = 0);
function waitKey(const delay: Integer = 0): Integer; function waitKey(const delay: Integer = 0): Integer;
// CV_EXPORTS_W void imshow(const String& winname, InputArray mat); // CV_EXPORTS_W void imshow(const String& winname, InputArray mat);
procedure imshow(const winname: String; const Mat: IMat); procedure imshow(const winname: String; const mat: TOCVMat);
// CV_EXPORTS_W void resizeWindow(const String& winname, int width, int height); // CV_EXPORTS_W void resizeWindow(const String& winname, int width, int height);
procedure resizeWindow(const winname: String; const width, height: Integer); procedure resizeWindow(const winname: String; const width, height: Integer);
// CV_EXPORTS_W void moveWindow(const String& winname, int x, int y); // CV_EXPORTS_W void moveWindow(const String& winname, int x, int y);
@ -152,13 +149,18 @@ function getWindowProperty(const winname: String; const prop_id: Integer): doubl
// int* value, int count, // int* value, int count,
// TrackbarCallback onChange = 0, // TrackbarCallback onChange = 0,
// void* userdata = 0); // void* userdata = 0);
function createTrackbar(const trackbarname: String; const winname: String; value: PInteger; count: Integer; function createTrackbar(const trackbarname: String; const winname: String; value: PInteger; count: Integer; onChange: CvTrackbarCallback2 = nil;
onChange: CvTrackbarCallback2 = nil; userdata: Pointer = nil): Integer; userdata: Pointer = nil): Integer;
// CV_EXPORTS_W Mat imread( const string& filename, int flags=1 ); // CV_EXPORTS_W Mat imread( const string& filename, int flags=1 );
function imread(const filename: string; flag: Integer = 1): IMat; function imread(const filename: string; flag: Integer = 1): TOCVMat;
// CV_EXPORTS_W bool imwrite( const string& filename, InputArray img, const vector<int>& params=vector<int>()); // CV_EXPORTS_W bool imwrite( const string& filename, InputArray img, const vector<int>& params=vector<int>());
function imwrite(const filename: String; const img: IMat): bool; function imwrite(const filename: String; const img: TOCVMat): bool;
Type
TIplImageRecordHelper = record helper for TIplImage
function InitFromMat(const mat: TOCVMat): TIplImage;
end;
implementation implementation
@ -167,32 +169,27 @@ Uses
cvUtils, cvUtils,
core_c; core_c;
function CreateVideoCapture: IVideoCapture; external OpenCV_Classes_DLL name 'CreateVideoCapture'; function CreateVideoCapture: TOCVVideoCapture; stdcall; external OpenCV_Classes_DLL name 'CreateVideoCapture'; overload;
function CreateVideoCapture(device: Integer): IVideoCapture; external OpenCV_Classes_DLL name 'CreateVideoCapture_dvc'; function CreateVideoCapture(device: Integer): TOCVVideoCapture; stdcall; external OpenCV_Classes_DLL name 'CreateVideoCaptureDevice'; overload;
function CreateVideoCapture(filename: pAnsiChar): IVideoCapture; function CreateVideoCapture(filename: pAnsiChar): TOCVVideoCapture; stdcall; external OpenCV_Classes_DLL name 'CreateVideoCaptureFileName'; overload;
external OpenCV_Classes_DLL name 'CreateVideoCapture_fln'; procedure DestroyVideoCapture(ex: TOCVVideoCapture); stdcall; external OpenCV_Classes_DLL;
function _imread(const filename: pCvChar; flag: Integer): IMat; external OpenCV_Classes_DLL name '_imread';
function _imwrite(const filename: pCvChar; const img: IMat): bool; external OpenCV_Classes_DLL name '_imwrite';
function imread(const filename: string; flag: Integer): IMat; function _imread(const filename: pCvChar; flag: Integer): TOCVMat; external OpenCV_Classes_DLL name '_imread';
function _imwrite(const filename: pCvChar; const img: TOCVMat): bool; external OpenCV_Classes_DLL name '_imwrite';
function imread(const filename: string; flag: Integer): TOCVMat;
begin begin
Result := _imread( Result := _imread(c_str(filename), flag);
c_str(filename),
flag);
end; end;
function imwrite(const filename: String; const img: IMat): bool; function imwrite(const filename: String; const img: TOCVMat): bool;
begin begin
Result := _imwrite( Result := _imwrite(c_str(filename), img);
c_str(filename),
img);
end; end;
procedure namedWindow(const winname: String; const flags: Integer = WINDOW_AUTOSIZE); procedure namedWindow(const winname: String; const flags: Integer = WINDOW_AUTOSIZE);
begin begin
cvNamedWindow( cvNamedWindow(c_str(winname), flags);
c_str(winname),
flags);
end; end;
procedure destroyWindow(const winname: String); procedure destroyWindow(const winname: String);
@ -215,57 +212,47 @@ begin
Result := cvWaitKey(delay); Result := cvWaitKey(delay);
end; end;
procedure imshow(const winname: String; const Mat: IMat); procedure imshow(const winname: String; const mat: TOCVMat);
Var Var
IplImage: TIplImage; IplImage: TIplImage;
begin begin
IplImage.InitFromMat(Mat); IplImage.InitFromMat(mat);
cvShowImage( cvShowImage(c_str(winname), @IplImage);
c_str(winname),
@IplImage);
end; end;
procedure resizeWindow(const winname: String; const width, height: Integer); procedure resizeWindow(const winname: String; const width, height: Integer);
begin begin
cvResizeWindow( cvResizeWindow(c_str(winname), width, height);
c_str(winname),
width,
height);
end; end;
procedure moveWindow(const winname: String; const x, y: Integer); procedure moveWindow(const winname: String; const x, y: Integer);
begin begin
cvMoveWindow( cvMoveWindow(c_str(winname), x, y);
c_str(winname),
x,
y);
end; end;
procedure setWindowProperty(const winname: String; const prop_id: Integer; const prop_value: double); procedure setWindowProperty(const winname: String; const prop_id: Integer; const prop_value: double);
begin begin
cvSetWindowProperty( cvSetWindowProperty(c_str(winname), prop_id, prop_value);
c_str(winname),
prop_id,
prop_value);
end; end;
function getWindowProperty(const winname: String; const prop_id: Integer): double; function getWindowProperty(const winname: String; const prop_id: Integer): double;
begin begin
Result := cvGetWindowProperty( Result := cvGetWindowProperty(c_str(winname), prop_id);
c_str(winname),
prop_id);
end; end;
function createTrackbar(const trackbarname: String; const winname: String; value: PInteger; count: Integer; function createTrackbar(const trackbarname: String; const winname: String; value: PInteger; count: Integer; onChange: CvTrackbarCallback2 = nil;
onChange: CvTrackbarCallback2 = nil; userdata: Pointer = nil): Integer; userdata: Pointer = nil): Integer;
begin begin
Result := cvCreateTrackbar2( Result := cvCreateTrackbar2(c_str(trackbarname), c_str(winname), value, count, onChange, userdata);
c_str(trackbarname), end;
c_str(winname),
value, { TIplImageRecordHelper }
count,
onChange, function TIplImageRecordHelper.InitFromMat(const mat: TOCVMat): TIplImage;
userdata); begin
Assert(mat.dims <= 2);
cvInitImageHeader(@Self, CvSize(mat.cols, mat.rows), cvIplDepth(mat.flags), mat.channels);
cvSetData(@Self, mat.data, mat.step1);
end; end;
end. end.

View File

@ -82,20 +82,10 @@
// opencv\modules\ml\include\opencv2\ml.hpp // opencv\modules\ml\include\opencv2\ml.hpp
// ************************************************************************************************* // *************************************************************************************************
{$IFDEF DEBUG}
{$A8,B-,C+,D+,E-,F-,G+,H+,I+,J-,K-,L+,M-,N+,O-,P+,Q+,R+,S-,T-,U-,V+,W+,X+,Y+,Z1}
{$ELSE}
{$A8,B-,C-,D-,E-,F-,G+,H+,I+,J-,K-,L-,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y-,Z1}
{$ENDIF}
{$WARN SYMBOL_DEPRECATED OFF}
{$WARN SYMBOL_PLATFORM OFF}
{$WARN UNIT_PLATFORM OFF}
{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_CAST OFF}
{$POINTERMATH ON}
unit ml; unit ml;
{$POINTERMATH ON}
interface interface
Uses Uses
@ -161,8 +151,8 @@ Uses
const const
/// * Variable type */ /// * Variable type */
CV_VAR_NUMERICAL = 0; CV_VAR_NUMERICAL = 0;
CV_VAR_ORDERED = 0; CV_VAR_ORDERED = 0;
CV_VAR_CATEGORICAL = 1; CV_VAR_CATEGORICAL = 1;
// //
@ -279,12 +269,11 @@ const
// * K-Nearest Neighbour Classifier * // * K-Nearest Neighbour Classifier *
// \****************************************************************************************/ // \****************************************************************************************/
Type Type
ICvKNearest = interface TCvKNearest = class
['{2F98E12A-AB71-48B5-AACC-025D0D0A3611}']
function train(const trainData: pCvMat; const responses: pCvMat; const sampleIdx: pCvMat = nil; function train(const trainData: pCvMat; const responses: pCvMat; const sampleIdx: pCvMat = nil;
is_regression: bool = false; maxK: Integer = 32; updateBase: bool = false): bool; stdcall; is_regression: bool = false; maxK: Integer = 32; updateBase: bool = false): bool; virtual; stdcall; abstract;
function find_nearest(const samples: pCvMat; k: Integer; results: pCvMat = nil; const neighbors: pSingle = nil; function find_nearest(const samples: pCvMat; k: Integer; results: pCvMat = nil; const neighbors: pSingle = nil;
neighborResponses: pCvMat = nil; dist: pCvMat = nil): float; stdcall; neighborResponses: pCvMat = nil; dist: pCvMat = nil): float; virtual; stdcall; abstract;
end; end;
// k Nearest Neighbors // k Nearest Neighbors
@ -725,11 +714,11 @@ Type
pCvDTreeSplit = ^TCvDTreeSplit; pCvDTreeSplit = ^TCvDTreeSplit;
TCvDTreeSplit = packed record // struct CvDTreeSplit TCvDTreeSplit = packed record // struct CvDTreeSplit
var_idx: Integer; // int var_idx; var_idx: Integer; // int var_idx;
condensed_idx: Integer; // int condensed_idx; condensed_idx: Integer; // int condensed_idx;
inversed: Integer; // int inversed; inversed: Integer; // int inversed;
quality: float; // float quality; quality: float; // float quality;
next: pCvDTreeSplit; // CvDTreeSplit* next; next: pCvDTreeSplit; // CvDTreeSplit* next;
case byte of case byte of
// union // union
// { // {
@ -750,31 +739,31 @@ Type
pCvDTreeNode = ^TCvDTreeNode; pCvDTreeNode = ^TCvDTreeNode;
TCvDTreeNode = packed record // struct CvDTreeNode TCvDTreeNode = packed record // struct CvDTreeNode
class_idx: Integer; // int class_idx; class_idx: Integer; // int class_idx;
Tn: Integer; // int Tn; Tn: Integer; // int Tn;
value: Double; // double value; value: Double; // double value;
// //
parent: pCvDTreeNode; // CvDTreeNode* parent; parent: pCvDTreeNode; // CvDTreeNode* parent;
left: pCvDTreeNode; // CvDTreeNode* left; left: pCvDTreeNode; // CvDTreeNode* left;
right: pCvDTreeNode; // CvDTreeNode* right; right: pCvDTreeNode; // CvDTreeNode* right;
// //
split: pCvDTreeSplit; // CvDTreeSplit* split; split: pCvDTreeSplit; // CvDTreeSplit* split;
// //
sample_count: Integer; // int sample_count; sample_count: Integer; // int sample_count;
depth: Integer; // int depth; depth: Integer; // int depth;
num_valid: pInteger; // int* num_valid; num_valid: pInteger; // int* num_valid;
offset: Integer; // int offset; offset: Integer; // int offset;
buf_idx: Integer; // int buf_idx; buf_idx: Integer; // int buf_idx;
maxlr: Double; // double maxlr; maxlr: Double; // double maxlr;
// //
// // global pruning data // // global pruning data
complexity: Integer; // int complexity; complexity: Integer; // int complexity;
alpha: Double; // double alpha; alpha: Double; // double alpha;
node_risk, tree_risk, tree_error: Double; // double node_risk, tree_risk, tree_error; node_risk, tree_risk, tree_error: Double; // double node_risk, tree_risk, tree_error;
// //
// // cross-validation pruning data // // cross-validation pruning data
cv_Tn: pInteger; // int* cv_Tn; cv_Tn: pInteger; // int* cv_Tn;
cv_node_risk: pDouble; // double* cv_node_risk; cv_node_risk: pDouble; // double* cv_node_risk;
cv_node_error: pDouble; // double* cv_node_error; cv_node_error: pDouble; // double* cv_node_error;
// //
// int get_num_valid(int vi) { return num_valid ? num_valid[vi] : sample_count; } // int get_num_valid(int vi) { return num_valid ? num_valid[vi] : sample_count; }
@ -783,16 +772,16 @@ Type
procedure set_num_valid(vi: Integer; n: Integer); procedure set_num_valid(vi: Integer; n: Integer);
end; end;
TCvDTreeParams = packed record // struct CV_EXPORTS_W_MAP CvDTreeParams TCvDTreeParams = packed record // struct CV_EXPORTS_W_MAP CvDTreeParams
max_categories: Integer; // CV_PROP_RW int max_categories ; max_categories: Integer; // CV_PROP_RW int max_categories ;
max_depth: Integer; // CV_PROP_RW int max_depth ; max_depth: Integer; // CV_PROP_RW int max_depth ;
min_sample_count: Integer; // CV_PROP_RW int min_sample_count ; min_sample_count: Integer; // CV_PROP_RW int min_sample_count ;
cv_folds: Integer; // CV_PROP_RW int cv_folds ; cv_folds: Integer; // CV_PROP_RW int cv_folds ;
use_surrogates: ByteBool; // CV_PROP_RW bool use_surrogates ; use_surrogates: ByteBool; // CV_PROP_RW bool use_surrogates ;
use_1se_rule: ByteBool; // CV_PROP_RW bool use_1se_rule ; use_1se_rule: ByteBool; // CV_PROP_RW bool use_1se_rule ;
truncate_pruned_tree: ByteBool; // CV_PROP_RW bool truncate_pruned_tree ; truncate_pruned_tree: ByteBool; // CV_PROP_RW bool truncate_pruned_tree ;
regression_accuracy: float; // CV_PROP_RW float regression_accuracy ; regression_accuracy: float; // CV_PROP_RW float regression_accuracy ;
priors: pFloat; // const float* priors; priors: pFloat; // const float* priors;
// //
// CvDTreeParams(); // CvDTreeParams();
{ {
@ -2212,18 +2201,20 @@ Type
// CV_EXPORTS bool initModule_ml(void); // CV_EXPORTS bool initModule_ml(void);
// } // }
function CreateCvKNearest: ICvKNearest; overload; safecall; function CreateCvKNearest: TCvKNearest; stdcall; overload;
function CreateCvKNearest(const trainData: pCvMat; const responses: pCvMat; const sampleIdx: pCvMat = nil; function CreateCvKNearest(const trainData: pCvMat; const responses: pCvMat; const sampleIdx: pCvMat = nil; isRegression: bool = false; max_k: Integer = 32)
isRegression: bool = false; max_k: Integer = 32): ICvKNearest; overload; safecall; : TCvKNearest; stdcall; overload;
procedure ReleaseCvKNearest(ex: TCvKNearest); stdcall;
implementation implementation
Uses Uses
uLibName; uLibName;
function CreateCvKNearest: ICvKNearest; external OpenCV_Classes_DLL name 'CreateCvKNearest'; function CreateCvKNearest: TCvKNearest; stdcall; external OpenCV_Classes_DLL name 'CreateCvKNearest';
function CreateCvKNearest(const trainData: pCvMat; const responses: pCvMat; const sampleIdx: pCvMat = nil; function CreateCvKNearest(const trainData: pCvMat; const responses: pCvMat; const sampleIdx: pCvMat = nil; isRegression: bool = false; max_k: Integer = 32)
isRegression: bool = false; max_k: Integer = 32): ICvKNearest; external OpenCV_Classes_DLL name 'CreateCvKNearestTR'; : TCvKNearest; stdcall; external OpenCV_Classes_DLL name 'CreateCvKNearestTR';
procedure ReleaseCvKNearest; stdcall; external OpenCV_Classes_DLL;
{ TCvDTreeNode } { TCvDTreeNode }

View File

@ -36,40 +36,40 @@ interface
const const
CV_VERSION_EPOCH = '2'; CV_VERSION_EPOCH = '2';
CV_VERSION_MAJOR = '4'; CV_VERSION_MAJOR = '4';
CV_VERSION_MINOR = '8'; CV_VERSION_MINOR = '8';
CV_VERSION_REVISION = '0'; CV_VERSION_REVISION = '0';
CV_VERSION = CV_VERSION_EPOCH + '.' + CV_VERSION_MAJOR + '.' + CV_VERSION_MINOR + '.' + CV_VERSION_REVISION; CV_VERSION = CV_VERSION_EPOCH + '.' + CV_VERSION_MAJOR + '.' + CV_VERSION_MINOR + '.' + CV_VERSION_REVISION;
// * old style version constants*/ // * old style version constants*/
CV_MAJOR_VERSION = CV_VERSION_EPOCH; CV_MAJOR_VERSION = CV_VERSION_EPOCH;
CV_MINOR_VERSION = CV_VERSION_MAJOR; CV_MINOR_VERSION = CV_VERSION_MAJOR;
CV_SUBMINOR_VERSION = CV_VERSION_MINOR; CV_SUBMINOR_VERSION = CV_VERSION_MINOR;
CV_VERSION_DLL = CV_VERSION_EPOCH + CV_VERSION_MAJOR + CV_VERSION_MINOR; CV_VERSION_DLL = CV_VERSION_EPOCH + CV_VERSION_MAJOR + CV_VERSION_MINOR;
{$IFDEF DEBUG} {$IFDEF DEBUG}
Core_Dll = 'opencv_core' + CV_VERSION_DLL + 'd.dll'; Core_Dll = 'opencv_core' + CV_VERSION_DLL + 'd.dll';
highgui_Dll = 'opencv_highgui' + CV_VERSION_DLL + 'd.dll'; highgui_Dll = 'opencv_highgui' + CV_VERSION_DLL + 'd.dll';
imgproc_Dll = 'opencv_imgproc' + CV_VERSION_DLL + 'd.dll'; imgproc_Dll = 'opencv_imgproc' + CV_VERSION_DLL + 'd.dll';
objdetect_dll = 'opencv_objdetect' + CV_VERSION_DLL + 'd.dll'; objdetect_dll = 'opencv_objdetect' + CV_VERSION_DLL + 'd.dll';
legacy_dll = 'opencv_legacy' + CV_VERSION_DLL + 'd.dll'; legacy_dll = 'opencv_legacy' + CV_VERSION_DLL + 'd.dll';
calib3d_dll = 'opencv_calib3d' + CV_VERSION_DLL + 'd.dll'; calib3d_dll = 'opencv_calib3d' + CV_VERSION_DLL + 'd.dll';
tracking_DLL = 'opencv_video' + CV_VERSION_DLL + 'd.dll'; tracking_DLL = 'opencv_video' + CV_VERSION_DLL + 'd.dll';
Nonfree_DLL = 'opencv_nonfree' + CV_VERSION_DLL + 'd.dll'; Nonfree_DLL = 'opencv_nonfree' + CV_VERSION_DLL + 'd.dll';
OpenCV_Classes_DLL = 'OpenCV_Classes.dll'; OpenCV_Classes_DLL = 'opencv_classes' + CV_VERSION_DLL + 'd.dll';
{$ELSE} {$ELSE}
Core_Dll = 'opencv_core' + CV_VERSION_DLL + '.dll'; Core_Dll = 'opencv_core' + CV_VERSION_DLL + '.dll';
highgui_Dll = 'opencv_highgui' + CV_VERSION_DLL + '.dll'; highgui_Dll = 'opencv_highgui' + CV_VERSION_DLL + '.dll';
imgproc_Dll = 'opencv_imgproc' + CV_VERSION_DLL + '.dll'; imgproc_Dll = 'opencv_imgproc' + CV_VERSION_DLL + '.dll';
objdetect_dll = 'opencv_objdetect' + CV_VERSION_DLL + '.dll'; objdetect_dll = 'opencv_objdetect' + CV_VERSION_DLL + '.dll';
legacy_dll = 'opencv_legacy' + CV_VERSION_DLL + '.dll'; legacy_dll = 'opencv_legacy' + CV_VERSION_DLL + '.dll';
calib3d_dll = 'opencv_calib3d' + CV_VERSION_DLL + '.dll'; calib3d_dll = 'opencv_calib3d' + CV_VERSION_DLL + '.dll';
tracking_DLL = 'opencv_video' + CV_VERSION_DLL + '.dll'; tracking_DLL = 'opencv_video' + CV_VERSION_DLL + '.dll';
Nonfree_DLL = 'opencv_nonfree' + CV_VERSION_DLL + '.dll'; Nonfree_DLL = 'opencv_nonfree' + CV_VERSION_DLL + '.dll';
OpenCV_Classes_DLL = 'OpenCV_Classes.dll'; OpenCV_Classes_DLL = 'opencv_classes' + CV_VERSION_DLL + '.dll';
{$ENDIF} {$ENDIF}
implementation implementation

View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ocvclasses", "ocvclasses\ocvclasses.vcxproj", "{D15D0A8B-0AD6-4139-8354-5D1C07CC3A22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D15D0A8B-0AD6-4139-8354-5D1C07CC3A22}.Debug|Win32.ActiveCfg = Debug|Win32
{D15D0A8B-0AD6-4139-8354-5D1C07CC3A22}.Debug|Win32.Build.0 = Debug|Win32
{D15D0A8B-0AD6-4139-8354-5D1C07CC3A22}.Release|Win32.ActiveCfg = Release|Win32
{D15D0A8B-0AD6-4139-8354-5D1C07CC3A22}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,51 @@
// dllmain.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include <afxwin.h>
#include <afxdllx.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
static AFX_EXTENSION_MODULE ocvclassesDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("ocvclasses.DLL Initializing!\n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(ocvclassesDLL, hInstance))
return 0;
// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
new CDynLinkLibrary(ocvclassesDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("ocvclasses.DLL Terminating!\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(ocvclassesDLL);
}
return 1; // ok
}

Binary file not shown.

View File

@ -0,0 +1,10 @@
// ocvclass.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

View File

@ -0,0 +1,18 @@
; ocvclass.def : Declares the module parameters for the DLL.
LIBRARY "ocvclasses.DLL"
DESCRIPTION 'Wrapper for OpenCV classes'
EXPORTS
CreateMat
CreateMatRCT
ReleaseMat
CreateVideoCapture
CreateVideoCaptureDevice
CreateVideoCaptureFileName
ReleaseVideoCapture
CreateCvKNearest
CreateCvKNearestTR
ReleaseCvKNearest

Binary file not shown.

View File

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{D15D0A8B-0AD6-4139-8354-5D1C07CC3A22}</ProjectGuid>
<RootNamespace>ocvclass</RootNamespace>
<Keyword>MFCDLLProj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>C:\OpenCV\build\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\OpenCV\build\x86\vc12\lib\;$(LibraryPath)</LibraryPath>
<OutDir>..\..\bin\</OutDir>
<TargetName>opencv_classes248d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>C:\OpenCV\build\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\OpenCV\build\x86\vc12\lib\;$(LibraryPath)</LibraryPath>
<OutDir>..\bin\</OutDir>
<TargetName>opencv_classes248</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;_AFXEXT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>.\ocvclasses.def</ModuleDefinitionFile>
<AdditionalLibraryDirectories>C:\OpenCV\build\x86\vc12\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opencv_calib3d248.lib;opencv_calib3d248d.lib;opencv_contrib248.lib;opencv_contrib248d.lib;opencv_core248.lib;opencv_core248d.lib;opencv_features2d248.lib;opencv_features2d248d.lib;opencv_flann248.lib;opencv_flann248d.lib;opencv_gpu248.lib;opencv_gpu248d.lib;opencv_highgui248.lib;opencv_highgui248d.lib;opencv_imgproc248.lib;opencv_imgproc248d.lib;opencv_legacy248.lib;opencv_legacy248d.lib;opencv_ml248.lib;opencv_ml248d.lib;opencv_nonfree248.lib;opencv_nonfree248d.lib;opencv_objdetect248.lib;opencv_objdetect248d.lib;opencv_ocl248.lib;opencv_ocl248d.lib;opencv_photo248.lib;opencv_photo248d.lib;opencv_stitching248.lib;opencv_stitching248d.lib;opencv_superres248.lib;opencv_superres248d.lib;opencv_ts248.lib;opencv_ts248d.lib;opencv_video248.lib;opencv_video248d.lib;opencv_videostab248.lib;opencv_videostab248d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0409</Culture>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_AFXEXT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>.\ocvclass.def</ModuleDefinitionFile>
</Link>
<Midl>
<MkTypLibCompatible>false</MkTypLibCompatible>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</Midl>
<ResourceCompile>
<Culture>0x0409</Culture>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</CompileAsManaged>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PrecompiledHeader>
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsManaged>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="ocvclasses.cpp" />
<ClCompile Include="ocvclassesdll.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ocvclassesdll.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ocvclasses.rc" />
</ItemGroup>
<ItemGroup>
<None Include="ocvclasses.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ocvclasses.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ocvclassesdll.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ocvclassesdll.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ocvclasses.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ocvclasses.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -0,0 +1,56 @@
#include "stdafx.h"
#include "ocvclassesdll.h"
///////////////////////////////////////////////////
TMat * __stdcall CreateMat()
{
return new TMat();
};
TMat * __stdcall CreateMatRCT(int rows, int cols, int type)
{
return new TMat(rows, cols, type);
};
void __stdcall ReleaseMat(TMat * ex)
{
delete ex;
};
//////////////////////////////////////////////////
TVideoCapture * __stdcall CreateVideoCapture()
{
return new TVideoCapture();
};
TVideoCapture * __stdcall CreateVideoCaptureDevice(int device)
{
return new TVideoCapture(device);
};
TVideoCapture * __stdcall CreateVideoCaptureFileName(const char* filename)
{
return new TVideoCapture(filename);
};
void __stdcall ReleaseVideoCapture(TVideoCapture * ex)
{
delete ex;
};
////////////////////////////////////////////////
TCvKNearest * __stdcall CreateCvKNearest()
{
return new TCvKNearest();
};
TCvKNearest * __stdcall CreateCvKNearestTR(CvMat* _trainData, CvMat* _responses, CvMat* _sampleIdx, BOOL _isRegression, int _max_k)
{
return new TCvKNearest(_trainData, _responses, _sampleIdx, _isRegression, _max_k);
};
void __stdcall ReleaseCvKNearest(TCvKNearest * ex)
{
delete ex;
};

Binary file not shown.

View File

@ -0,0 +1,7 @@
// stdafx.cpp : source file that includes just the standard includes
// ocvclass.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"

View File

@ -0,0 +1,147 @@
// *****************************************************************
// Delphi-OpenCV Class 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.
// *******************************************************************
// Original:
// http://docs.opencv.org/modules/ml/doc/k_nearest_neighbors.html#cvknearest-is-regression
// *******************************************************************
program cls2DPointClassification;
{$APPTYPE CONSOLE}
{$POINTERMATH ON}
{$R *.res}
uses
System.SysUtils,
System.Classes,
Core.types_c,
core_c,
highgui_c,
ml;
Const
K10: Integer = 10;
Var
i, j, K, accuracy: Integer;
response: float;
train_sample_count: Integer = 100;
rng_state: TCvRNG;
trainData: pCvMat;
trainClasses: pCvMat;
img: pIplImage;
_sample: array [0 .. 1] of float;
sample: TCvMat;
trainData1, //
trainData2, //
trainClasses1, //
trainClasses2: TCvMat;
knn: TCvKNearest;
nearests: pCvMat;
t: TCvScalar;
pt: TCvPoint;
begin
try
rng_state := CvRNG(-1);
trainData := cvCreateMat(train_sample_count, 2, CV_32FC1);
trainClasses := cvCreateMat(train_sample_count, 1, CV_32FC1);
img := cvCreateImage(cvSize(500, 500), 8, 3);
sample := CvMat(1, 2, CV_32FC1, @_sample);
cvZero(img);
// form the training samples
cvGetRows(trainData, @trainData1, 0, train_sample_count div 2);
cvRandArr(@rng_state, @trainData1, CV_RAND_NORMAL, cvScalar(200, 200), cvScalar(50, 50));
cvGetRows(trainData, @trainData2, train_sample_count div 2, train_sample_count);
cvRandArr(@rng_state, @trainData2, CV_RAND_NORMAL, cvScalar(300, 300), cvScalar(50, 50));
cvGetRows(trainClasses, @trainClasses1, 0, train_sample_count div 2);
cvSet(@trainClasses1, cvScalar(1));
cvGetRows(trainClasses, @trainClasses2, train_sample_count div 2, train_sample_count);
cvSet(@trainClasses2, cvScalar(2));
// learn classifier
knn := CreateCvKNearest(trainData, trainClasses, nil, false, K10);
nearests := cvCreateMat(1, K10, CV_32FC1);
for i := 0 to img^.height - 1 do
begin
for j := 0 to img^.width - 1 do
begin
pFloat(sample.data)[0] := j;
pFloat(sample.data)[1] := i;
// estimate the response and get the neighbors' labels
response := knn.find_nearest(@sample, K10, nil, nil, nearests, nil);
// compute the number of neighbors representing the majority
accuracy := 0;
for K := 0 to K10 - 1 do
begin
if (pFloat(nearests^.data)[K] = response) then
Inc(accuracy);
end;
// highlight the pixel depending on the accuracy (or confidence)
if response = 1 then
begin
if accuracy > 5 then
t := CV_RGB(180, 0, 0)
else
CV_RGB(180, 120, 0);
end
else
begin
if accuracy > 5 then
t := CV_RGB(0, 180, 0)
else
CV_RGB(120, 120, 0);
end;
cvSet2D(img, i, j, t);
end;
end;
ReleaseCvKNearest(knn);
// display the original training samples
for i := 0 to (train_sample_count div 2) - 1 do
begin
pt.x := cvRound(pFloat(trainData1.data)[i * 2]);
pt.y := cvRound(pFloat(trainData1.data)[i * 2 + 1]);
cvCircle(img, pt, 2, CV_RGB(255, 0, 0), CV_FILLED);
pt.x := cvRound(pFloat(trainData2.data)[i * 2]);
pt.y := cvRound(pFloat(trainData2.data)[i * 2 + 1]);
cvCircle(img, pt, 2, CV_RGB(0, 255, 0), CV_FILLED);
end;
cvNamedWindow('classifier result', 1);
cvShowImage('classifier result', img);
cvWaitKey(0);
cvReleaseMat(trainClasses);
cvReleaseMat(trainData);
except
on E: Exception do
WriteLn(E.ClassName, ': ', E.Message);
end;
end.

View File

@ -0,0 +1,170 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{18754223-3415-44A1-BB17-A5574106F304}</ProjectGuid>
<MainSource>cls2DPointClassification.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<TargetedPlatforms>17</TargetedPlatforms>
<AppType>Console</AppType>
<FrameworkType>None</FrameworkType>
<ProjectVersion>15.3</ProjectVersion>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
<Cfg_2_Win32>true</Cfg_2_Win32>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_E>false</DCC_E>
<DCC_ExeOutput>..\..\..\bin\</DCC_ExeOutput>
<VerInfo_Locale>1049</VerInfo_Locale>
<DCC_DebugInformation>true</DCC_DebugInformation>
<DCC_ImageBase>00400000</DCC_ImageBase>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=;CFBundleDisplayName=;UIDeviceFamily=;CFBundleIdentifier=;CFBundleVersion=;CFBundlePackageType=;CFBundleSignature=;CFBundleAllowMixedLocalizations=;UISupportedInterfaceOrientations=;CFBundleExecutable=;CFBundleResourceSpecification=;LSRequiresIPhoneOS=;CFBundleInfoDictionaryVersion=;CFBundleDevelopmentRegion=;package=;label=;versionCode=;versionName=;persistent=;restoreAnyVersion=;installLocation=;largeHeap=;theme=</VerInfo_Keys>
<DCC_K>false</DCC_K>
<Manifest_File>None</Manifest_File>
<DCC_F>false</DCC_F>
<DCC_N>false</DCC_N>
<DCC_S>false</DCC_S>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
<DCC_DebugInformation>0</DCC_DebugInformation>
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
<DCC_Optimize>false</DCC_Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<Manifest_File>None</Manifest_File>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType/>
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">cls2DPointClassification.dpr</Source>
</Source>
<VersionInfo>
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">0</VersionInfo>
<VersionInfo Name="Release">0</VersionInfo>
<VersionInfo Name="Build">0</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
<VersionInfo Name="Private">False</VersionInfo>
<VersionInfo Name="DLL">False</VersionInfo>
<VersionInfo Name="Locale">1049</VersionInfo>
<VersionInfo Name="CodePage">1251</VersionInfo>
</VersionInfo>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription"/>
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName"/>
<VersionInfoKeys Name="LegalCopyright"/>
<VersionInfoKeys Name="LegalTrademarks"/>
<VersionInfoKeys Name="OriginalFilename"/>
<VersionInfoKeys Name="ProductName"/>
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"/>
<VersionInfoKeys Name="CFBundleName"/>
<VersionInfoKeys Name="CFBundleDisplayName"/>
<VersionInfoKeys Name="UIDeviceFamily"/>
<VersionInfoKeys Name="CFBundleIdentifier"/>
<VersionInfoKeys Name="CFBundleVersion"/>
<VersionInfoKeys Name="CFBundlePackageType"/>
<VersionInfoKeys Name="CFBundleSignature"/>
<VersionInfoKeys Name="CFBundleAllowMixedLocalizations"/>
<VersionInfoKeys Name="UISupportedInterfaceOrientations"/>
<VersionInfoKeys Name="CFBundleExecutable"/>
<VersionInfoKeys Name="CFBundleResourceSpecification"/>
<VersionInfoKeys Name="LSRequiresIPhoneOS"/>
<VersionInfoKeys Name="CFBundleInfoDictionaryVersion"/>
<VersionInfoKeys Name="CFBundleDevelopmentRegion"/>
<VersionInfoKeys Name="package"/>
<VersionInfoKeys Name="label"/>
<VersionInfoKeys Name="versionCode"/>
<VersionInfoKeys Name="versionName"/>
<VersionInfoKeys Name="persistent"/>
<VersionInfoKeys Name="restoreAnyVersion"/>
<VersionInfoKeys Name="installLocation"/>
<VersionInfoKeys Name="largeHeap"/>
<VersionInfoKeys Name="theme"/>
</VersionInfoKeys>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k190.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dclofficexp190.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
</Excluded_Packages>
</Delphi.Personality>
<Platforms>
<Platform value="Android" ActiveMobileDevice="rsxe5_android">True</Platform>
<Platform value="OSX32">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
</Project>
<!-- EurekaLog First Line
[Exception Log]
EurekaLog Version=7007
Activate=0
DeleteMapAfterCompile=1
Encrypt Password=""
EurekaLog Last Line -->

View File

@ -0,0 +1,219 @@
// *****************************************************************
// Delphi-OpenCV Class 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.
// *******************************************************************
// Original:
// http://public.cranfield.ac.uk/c5354/teaching/ml/examples/c/knn_ex/
// *******************************************************************
program clsKNN;
{$APPTYPE CONSOLE}
{$POINTERMATH ON}
{$R *.res}
uses
System.SysUtils,
System.Classes,
Core.types_c,
core_c,
ml;
{ DEFINE Test }
Const
CarTrain_FileName = 'resource\car.train';
{$IFDEF Test}
CarTest_FileName = 'resource\car.test';
NUMBER_OF_TESTING_SAMPLES = 345;
{$ELSE}
CarTest_FileName = 'resource\car.data';
NUMBER_OF_TESTING_SAMPLES = 1728;
{$ENDIF}
ATTRIBUTES_PER_SAMPLE = 6; // not the last as this is the class
NUMBER_OF_CLASSES = 4; // classes 0->3
Classes: array [0 .. NUMBER_OF_CLASSES - 1] of String = ('unacc', 'acc', 'good', 'vgood');
NUMBER_OF_TRAINING_SAMPLES = 1383;
function hash(str: AnsiString): Single;
Var
i, R: Integer;
begin
R := 5381;
for i := 1 to Length(str) do
R := (R shl 5) + R + ord(str[i]);
Result := R;
end;
function read_data_from_csv(const filename: String; Var data, _classes: TCvMat): Boolean;
var
i, line, attribute: Integer;
S: TStringList;
Sp: TStringList;
begin
if not FileExists(filename) then
begin
WriteLn('ERROR: cannot read file ', filename);
Exit(False); // all not OK
end;
S := TStringList.Create;
Sp := TStringList.Create;
try
S.LoadFromFile(filename);
// for each sample in the file
for line := 0 to S.Count - 1 do
begin
Sp.CommaText := S[line];
// for each attribute on the line in the file
for attribute := 0 to Sp.Count - 1 do
if attribute = 6 then
// last attribute is the class
begin
// find the class number and record this
for i := 0 to NUMBER_OF_CLASSES - 1 do
if SameText(Classes[i], Sp[attribute]) then
PSingle(CV_MAT_ELEM(_classes, CV_32FC1, line, 0))^ := i;
end
else
// for all other attributes just read in the string value
// and use a hash function to convert to to a float
// (N.B. openCV uses a floating point decision tree implementation!)
begin
PSingle(CV_MAT_ELEM(data, CV_32FC1, line, attribute))^ := hash(AnsiString(Sp[attribute]));
end;
end;
finally
S.Free;
Sp.Free;
end;
Result := True;
end;
Var
k, i: Integer;
training_data, //
training_classifications: pCvMat;
testing_data, //
testing_classifications: pCvMat;
var_type: pCvMat;
resultNode: Float; // node returned from a prediction
knn: TCvKNearest;
tsample: Integer;
test_sample: TCvMat;
correct_class: Integer;
wrong_class: Integer;
false_positives: array [0 .. NUMBER_OF_CLASSES - 1] of Integer;
begin
try
// lets just check the version first
// WriteLn(Format('OpenCV version %s (%d.%d.%d)', [CV_VERSION, CV_MAJOR_VERSION, CV_MINOR_VERSION,CV_SUBMINOR_VERSION]);
k := 10;
// define training data storage matrices (one for attribute examples, one
// for classifications)
training_data := cvCreateMat(NUMBER_OF_TRAINING_SAMPLES, ATTRIBUTES_PER_SAMPLE, CV_32FC1);
training_classifications := cvCreateMat(NUMBER_OF_TRAINING_SAMPLES, 1, CV_32FC1);
// define testing data storage matrices
testing_data := cvCreateMat(NUMBER_OF_TESTING_SAMPLES, ATTRIBUTES_PER_SAMPLE, CV_32FC1);
testing_classifications := cvCreateMat(NUMBER_OF_TESTING_SAMPLES, 1, CV_32FC1);
// define all the attributes as categorical (i.e. categories)
// alternatives are CV_VAR_CATEGORICAL or CV_VAR_ORDERED(=CV_VAR_NUMERICAL)
// that can be assigned on a per attribute basis
// this is a classification problem (i.e. predict a discrete number of class
// outputs) so also the last (+1) output var_type element to CV_VAR_CATEGORICAL
var_type := cvCreateMat(ATTRIBUTES_PER_SAMPLE + 1, 1, CV_8U);
cvSet(var_type, cvScalarAll(CV_VAR_CATEGORICAL)); // all inputs are categorical
try
// load training and testing data sets
if read_data_from_csv(CarTrain_FileName, training_data^, training_classifications^) and
read_data_from_csv(CarTest_FileName, testing_data^, testing_classifications^) then
begin
// train K-Nearest Neighbour classifier (using training data)
WriteLn('Using training database: ', CarTrain_FileName);
knn := CreateCvKNearest;
knn.train(training_data, training_classifications, nil, False, k);
// perform classifier testing and report results
correct_class := 0;
wrong_class := 0;
FillChar(false_positives, SizeOf(false_positives), 0);
WriteLn('Using testing database: ', CarTest_FileName);
for tsample := 0 to NUMBER_OF_TESTING_SAMPLES - 1 do
begin
// extract a row from the testing matrix
cvGetRow(testing_data, @test_sample, tsample);
// run decision tree prediction
resultNode := knn.find_nearest(@test_sample, k, nil, nil, nil);
WriteLn(Format('Testing Sample %d -> class result %s', [tsample, Classes[Trunc(resultNode)]]));
// if the prediction and the (true) testing classification are the same
// (N.B. openCV uses a floating point decision tree implementation!)
if abs(resultNode - PSingle(CV_MAT_ELEM(testing_classifications^, CV_32FC1, tsample, 0))^) >= FLT_EPSILON then
begin
// if they differ more than floating point error => wrong class
Inc(wrong_class);
Inc(false_positives[Trunc(resultNode)]);
end
else
begin
// otherwise correct
Inc(correct_class);
end;
end;
WriteLn(Format('Results on the testing database: %s'#13#10#9'Correct classification: %d (%4.2f%%)'#13#10#9 + 'Wrong classifications: %d (%4.2f%%)',
[CarTest_FileName, correct_class, correct_class * 100 / NUMBER_OF_TESTING_SAMPLES, wrong_class, wrong_class * 100 / NUMBER_OF_TESTING_SAMPLES]));
for i := 0 to NUMBER_OF_CLASSES - 1 do
begin
WriteLn(Format(#9'Class %s false postives %d (%4.2f%%)', [Classes[i], false_positives[i], false_positives[i] * 100 / NUMBER_OF_TESTING_SAMPLES]));
end;
end;
finally
// free all memory
ReleaseCvKNearest(knn);
cvReleaseMat(training_data);
cvReleaseMat(training_classifications);
cvReleaseMat(testing_data);
cvReleaseMat(testing_classifications);
cvReleaseMat(var_type);
WriteLn('Press Enter to Exit');
Readln;
end;
except
on E: Exception do
WriteLn(E.ClassName, ': ', E.Message);
end;
end.

View File

@ -0,0 +1,170 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{6822E0E3-69E6-4818-A2F5-2D778C63AE9A}</ProjectGuid>
<MainSource>clsKNN.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<TargetedPlatforms>17</TargetedPlatforms>
<AppType>Console</AppType>
<FrameworkType>None</FrameworkType>
<ProjectVersion>15.3</ProjectVersion>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
<Cfg_2_Win32>true</Cfg_2_Win32>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_E>false</DCC_E>
<DCC_ExeOutput>..\..\..\bin\</DCC_ExeOutput>
<VerInfo_Locale>1049</VerInfo_Locale>
<DCC_DebugInformation>true</DCC_DebugInformation>
<DCC_ImageBase>00400000</DCC_ImageBase>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=;CFBundleDisplayName=;UIDeviceFamily=;CFBundleIdentifier=;CFBundleVersion=;CFBundlePackageType=;CFBundleSignature=;CFBundleAllowMixedLocalizations=;UISupportedInterfaceOrientations=;CFBundleExecutable=;CFBundleResourceSpecification=;LSRequiresIPhoneOS=;CFBundleInfoDictionaryVersion=;CFBundleDevelopmentRegion=;package=;label=;versionCode=;versionName=;persistent=;restoreAnyVersion=;installLocation=;largeHeap=;theme=</VerInfo_Keys>
<DCC_K>false</DCC_K>
<Manifest_File>None</Manifest_File>
<DCC_F>false</DCC_F>
<DCC_N>false</DCC_N>
<DCC_S>false</DCC_S>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
<DCC_DebugInformation>0</DCC_DebugInformation>
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
<DCC_Optimize>false</DCC_Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<Manifest_File>None</Manifest_File>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType/>
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">clsKNN.dpr</Source>
</Source>
<VersionInfo>
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">0</VersionInfo>
<VersionInfo Name="Release">0</VersionInfo>
<VersionInfo Name="Build">0</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
<VersionInfo Name="Private">False</VersionInfo>
<VersionInfo Name="DLL">False</VersionInfo>
<VersionInfo Name="Locale">1049</VersionInfo>
<VersionInfo Name="CodePage">1251</VersionInfo>
</VersionInfo>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription"/>
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName"/>
<VersionInfoKeys Name="LegalCopyright"/>
<VersionInfoKeys Name="LegalTrademarks"/>
<VersionInfoKeys Name="OriginalFilename"/>
<VersionInfoKeys Name="ProductName"/>
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"/>
<VersionInfoKeys Name="CFBundleName"/>
<VersionInfoKeys Name="CFBundleDisplayName"/>
<VersionInfoKeys Name="UIDeviceFamily"/>
<VersionInfoKeys Name="CFBundleIdentifier"/>
<VersionInfoKeys Name="CFBundleVersion"/>
<VersionInfoKeys Name="CFBundlePackageType"/>
<VersionInfoKeys Name="CFBundleSignature"/>
<VersionInfoKeys Name="CFBundleAllowMixedLocalizations"/>
<VersionInfoKeys Name="UISupportedInterfaceOrientations"/>
<VersionInfoKeys Name="CFBundleExecutable"/>
<VersionInfoKeys Name="CFBundleResourceSpecification"/>
<VersionInfoKeys Name="LSRequiresIPhoneOS"/>
<VersionInfoKeys Name="CFBundleInfoDictionaryVersion"/>
<VersionInfoKeys Name="CFBundleDevelopmentRegion"/>
<VersionInfoKeys Name="package"/>
<VersionInfoKeys Name="label"/>
<VersionInfoKeys Name="versionCode"/>
<VersionInfoKeys Name="versionName"/>
<VersionInfoKeys Name="persistent"/>
<VersionInfoKeys Name="restoreAnyVersion"/>
<VersionInfoKeys Name="installLocation"/>
<VersionInfoKeys Name="largeHeap"/>
<VersionInfoKeys Name="theme"/>
</VersionInfoKeys>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k190.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dclofficexp190.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
</Excluded_Packages>
</Delphi.Personality>
<Platforms>
<Platform value="Android" ActiveMobileDevice="rsxe5_android">True</Platform>
<Platform value="OSX32">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
</Project>
<!-- EurekaLog First Line
[Exception Log]
EurekaLog Version=7007
Activate=0
DeleteMapAfterCompile=1
Encrypt Password=""
EurekaLog Last Line -->

Binary file not shown.

View File

@ -0,0 +1,101 @@
// *****************************************************************
// 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.
// *******************************************************************
program clsMat;
{$APPTYPE CONSOLE}
{$POINTERMATH ON}
{$R *.res}
uses
System.SysUtils,
Core.types_c,
core_c,
mat;
procedure Print(const M: TOCVMat);
Var
matdata: PByte;
begin
Writeln('M = $', IntToHex(Integer(M), 8));
With M do
begin
Writeln('elemSize = ', elemSize);
Writeln('elemSize1 = ', elemSize1);
Writeln('type = ', _type);
Writeln('depth = ', depth);
Writeln('channels = ', channels);
Writeln('empty = ', empty);
Writeln('total = ', total);
Writeln('flags = $', IntToHex(flags, 8));
Writeln('dims = ', dims);
Writeln('rows = ', rows);
Writeln('cols = ', cols);
Writeln('data = $', IntToHex(Integer(data), 8));
matdata := data;
if Assigned(matdata) then
Writeln('($', IntToHex(Integer(matdata^), 2), ')')
else
Writeln;
end;
end;
Var
mat: TOCVMat;
begin
try
Writeln('--------- Create empty MAT');
mat := CreateMat;
Print(mat);
DestroyMat(mat);
Readln;
Writeln('--------- Create MAT 2x2 CV_8UC1 - 1 byte, 1 channel');
mat := CreateMat(2, 2, CV_8UC1);
Print(mat);
DestroyMat(mat);
Readln;
Writeln('--------- Create MAT 4x2 CV_32FC2 - single (4-byte floating point), 2 channel');
mat := CreateMat(4, 2, CV_32FC2);
Print(mat);
DestroyMat(mat);
Readln;
Writeln('--------- Create 2x2 MAT');
mat := CreateMat(2, 2, CV_8UC1);
Print(mat);
DestroyMat(mat);
Readln;
Writeln('--------- Create 3x3 MAT');
mat := CreateMat(3, 3, CV_8UC1);
Print(mat);
DestroyMat(mat);
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.

View File

@ -0,0 +1,170 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{4354743C-AB35-4447-AFCE-DBE2CA117163}</ProjectGuid>
<MainSource>clsMat.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<TargetedPlatforms>17</TargetedPlatforms>
<AppType>Console</AppType>
<FrameworkType>None</FrameworkType>
<ProjectVersion>15.3</ProjectVersion>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
<Cfg_2_Win32>true</Cfg_2_Win32>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_E>false</DCC_E>
<DCC_ExeOutput>..\..\..\bin\</DCC_ExeOutput>
<VerInfo_Locale>1049</VerInfo_Locale>
<DCC_DebugInformation>true</DCC_DebugInformation>
<DCC_ImageBase>00400000</DCC_ImageBase>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=;CFBundleDisplayName=;UIDeviceFamily=;CFBundleIdentifier=;CFBundleVersion=;CFBundlePackageType=;CFBundleSignature=;CFBundleAllowMixedLocalizations=;UISupportedInterfaceOrientations=;CFBundleExecutable=;CFBundleResourceSpecification=;LSRequiresIPhoneOS=;CFBundleInfoDictionaryVersion=;CFBundleDevelopmentRegion=;package=;label=;versionCode=;versionName=;persistent=;restoreAnyVersion=;installLocation=;largeHeap=;theme=</VerInfo_Keys>
<DCC_K>false</DCC_K>
<Manifest_File>None</Manifest_File>
<DCC_F>false</DCC_F>
<DCC_N>false</DCC_N>
<DCC_S>false</DCC_S>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
<DCC_DebugInformation>0</DCC_DebugInformation>
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
<DCC_Optimize>false</DCC_Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<VerInfo_Locale>1033</VerInfo_Locale>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<Manifest_File>None</Manifest_File>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType/>
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">clsMat.dpr</Source>
</Source>
<VersionInfo>
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">0</VersionInfo>
<VersionInfo Name="Release">0</VersionInfo>
<VersionInfo Name="Build">0</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
<VersionInfo Name="Private">False</VersionInfo>
<VersionInfo Name="DLL">False</VersionInfo>
<VersionInfo Name="Locale">1049</VersionInfo>
<VersionInfo Name="CodePage">1251</VersionInfo>
</VersionInfo>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription"/>
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName"/>
<VersionInfoKeys Name="LegalCopyright"/>
<VersionInfoKeys Name="LegalTrademarks"/>
<VersionInfoKeys Name="OriginalFilename"/>
<VersionInfoKeys Name="ProductName"/>
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"/>
<VersionInfoKeys Name="CFBundleName"/>
<VersionInfoKeys Name="CFBundleDisplayName"/>
<VersionInfoKeys Name="UIDeviceFamily"/>
<VersionInfoKeys Name="CFBundleIdentifier"/>
<VersionInfoKeys Name="CFBundleVersion"/>
<VersionInfoKeys Name="CFBundlePackageType"/>
<VersionInfoKeys Name="CFBundleSignature"/>
<VersionInfoKeys Name="CFBundleAllowMixedLocalizations"/>
<VersionInfoKeys Name="UISupportedInterfaceOrientations"/>
<VersionInfoKeys Name="CFBundleExecutable"/>
<VersionInfoKeys Name="CFBundleResourceSpecification"/>
<VersionInfoKeys Name="LSRequiresIPhoneOS"/>
<VersionInfoKeys Name="CFBundleInfoDictionaryVersion"/>
<VersionInfoKeys Name="CFBundleDevelopmentRegion"/>
<VersionInfoKeys Name="package"/>
<VersionInfoKeys Name="label"/>
<VersionInfoKeys Name="versionCode"/>
<VersionInfoKeys Name="versionName"/>
<VersionInfoKeys Name="persistent"/>
<VersionInfoKeys Name="restoreAnyVersion"/>
<VersionInfoKeys Name="installLocation"/>
<VersionInfoKeys Name="largeHeap"/>
<VersionInfoKeys Name="theme"/>
</VersionInfoKeys>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k190.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dclofficexp190.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
</Excluded_Packages>
</Delphi.Personality>
<Platforms>
<Platform value="Android" ActiveMobileDevice="rsxe5_android">True</Platform>
<Platform value="OSX32">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
</Project>
<!-- EurekaLog First Line
[Exception Log]
EurekaLog Version=7007
Activate=0
DeleteMapAfterCompile=1
Encrypt Password=""
EurekaLog Last Line -->

Binary file not shown.

View File

@ -0,0 +1,100 @@
// *****************************************************************
// 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.
// *******************************************************************
program clsVideoCapture;
{$APPTYPE CONSOLE}
{$POINTERMATH ON}
{$R *.res}
uses
System.SysUtils,
mat,
highgui,
highgui_c;
Const
VK_ESCAPE = 27;
DESIRED_CAMERA_WIDTH: Integer = 320;
DESIRED_CAMERA_HEIGHT: Integer = 200;
windowName = 'Test VideoCapture'; // Name shown in the GUI window.
// Get access to the webcam.
procedure initWebcam(videoCapture: TOCVVideoCapture; cameraNumber: Integer = CV_CAP_ANY);
begin
// Get access to the default camera.
// Surround the OpenCV call by a try/catch block so we can give a useful error message!
videoCapture.open(cameraNumber);
if not videoCapture.isOpened() then
begin
Writeln('ERROR: Could not access the camera!');
Halt(1);
end;
Writeln('Loaded camera ', cameraNumber);
end;
Var
cameraNumber: Integer = CV_CAP_ANY;
camera: TOCVVideoCapture;
cameraFrame: TOCVMat = nil;
begin
try
camera := CreateVideoCapture();
initWebcam(camera, cameraNumber);
// Try to set the camera resolution. Note that this only works for some cameras on
// some computers and only for some drivers, so don't rely on it to work!
camera.setValue(CV_CAP_PROP_FRAME_WIDTH, DESIRED_CAMERA_WIDTH);
camera.setValue(CV_CAP_PROP_FRAME_HEIGHT, DESIRED_CAMERA_HEIGHT);
// Create a GUI window for display on the screen.
namedWindow(windowName); // Resizable window, might not work on Windows.
// Run forever, until the user hits Escape to "break" out of this loop.
while true do
begin
// Grab the next camera frame. Note that you can't modify camera frames.
if camera.read(cameraFrame) then
begin
if Assigned(cameraFrame) and (cameraFrame.empty()) then
begin
Writeln('ERROR: Couldn''t grab the next camera frame.');
Halt(1);
end;
if Assigned(cameraFrame) then
imshow(windowName, cameraFrame);
end;
// IMPORTANT: Wait for atleast 20 milliseconds, so that the image can be displayed on the screen!
if (waitKey(20) = VK_ESCAPE) then // Escape Key
break; // Quit the program!
end;
camera.release;
cvDestroyAllWindows;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.

View File

@ -0,0 +1,170 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{C63D42FE-D135-473C-A773-6EFDE83EAE78}</ProjectGuid>
<MainSource>clsVideoCapture.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<TargetedPlatforms>17</TargetedPlatforms>
<AppType>Console</AppType>
<FrameworkType>None</FrameworkType>
<ProjectVersion>15.3</ProjectVersion>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
<Cfg_2_Win32>true</Cfg_2_Win32>
<CfgParent>Cfg_2</CfgParent>
<Cfg_2>true</Cfg_2>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
<DCC_DebugInformation>true</DCC_DebugInformation>
<DCC_K>false</DCC_K>
<DCC_ExeOutput>..\..\..\bin\</DCC_ExeOutput>
<DCC_S>false</DCC_S>
<DCC_ImageBase>00400000</DCC_ImageBase>
<DCC_F>false</DCC_F>
<DCC_N>false</DCC_N>
<VerInfo_Locale>1049</VerInfo_Locale>
<Manifest_File>None</Manifest_File>
<DCC_E>false</DCC_E>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=;CFBundleName=;CFBundleDisplayName=;UIDeviceFamily=;CFBundleIdentifier=;CFBundleVersion=;CFBundlePackageType=;CFBundleSignature=;CFBundleAllowMixedLocalizations=;UISupportedInterfaceOrientations=;CFBundleExecutable=;CFBundleResourceSpecification=;LSRequiresIPhoneOS=;CFBundleInfoDictionaryVersion=;CFBundleDevelopmentRegion=;package=;label=;versionCode=;versionName=;persistent=;restoreAnyVersion=;installLocation=;largeHeap=;theme=</VerInfo_Keys>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Locale>1033</VerInfo_Locale>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
<DCC_DebugInformation>0</DCC_DebugInformation>
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
<DCC_Optimize>false</DCC_Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<Manifest_File>None</Manifest_File>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Locale>1033</VerInfo_Locale>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<BuildConfiguration Include="Debug">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Release">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType/>
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">clsVideoCapture.dpr</Source>
</Source>
<VersionInfo>
<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
<VersionInfo Name="MajorVer">1</VersionInfo>
<VersionInfo Name="MinorVer">0</VersionInfo>
<VersionInfo Name="Release">0</VersionInfo>
<VersionInfo Name="Build">0</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
<VersionInfo Name="Private">False</VersionInfo>
<VersionInfo Name="DLL">False</VersionInfo>
<VersionInfo Name="Locale">1049</VersionInfo>
<VersionInfo Name="CodePage">1251</VersionInfo>
</VersionInfo>
<VersionInfoKeys>
<VersionInfoKeys Name="CompanyName"/>
<VersionInfoKeys Name="FileDescription"/>
<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="InternalName"/>
<VersionInfoKeys Name="LegalCopyright"/>
<VersionInfoKeys Name="LegalTrademarks"/>
<VersionInfoKeys Name="OriginalFilename"/>
<VersionInfoKeys Name="ProductName"/>
<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
<VersionInfoKeys Name="Comments"/>
<VersionInfoKeys Name="CFBundleName"/>
<VersionInfoKeys Name="CFBundleDisplayName"/>
<VersionInfoKeys Name="UIDeviceFamily"/>
<VersionInfoKeys Name="CFBundleIdentifier"/>
<VersionInfoKeys Name="CFBundleVersion"/>
<VersionInfoKeys Name="CFBundlePackageType"/>
<VersionInfoKeys Name="CFBundleSignature"/>
<VersionInfoKeys Name="CFBundleAllowMixedLocalizations"/>
<VersionInfoKeys Name="UISupportedInterfaceOrientations"/>
<VersionInfoKeys Name="CFBundleExecutable"/>
<VersionInfoKeys Name="CFBundleResourceSpecification"/>
<VersionInfoKeys Name="LSRequiresIPhoneOS"/>
<VersionInfoKeys Name="CFBundleInfoDictionaryVersion"/>
<VersionInfoKeys Name="CFBundleDevelopmentRegion"/>
<VersionInfoKeys Name="package"/>
<VersionInfoKeys Name="label"/>
<VersionInfoKeys Name="versionCode"/>
<VersionInfoKeys Name="versionName"/>
<VersionInfoKeys Name="persistent"/>
<VersionInfoKeys Name="restoreAnyVersion"/>
<VersionInfoKeys Name="installLocation"/>
<VersionInfoKeys Name="largeHeap"/>
<VersionInfoKeys Name="theme"/>
</VersionInfoKeys>
<Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dcloffice2k190.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
<Excluded_Packages Name="$(BDSBIN)\dclofficexp190.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
</Excluded_Packages>
</Delphi.Personality>
<Platforms>
<Platform value="Android" ActiveMobileDevice="rsxe5_android">True</Platform>
<Platform value="OSX32">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
</Project>
<!-- EurekaLog First Line
[Exception Log]
EurekaLog Version=7007
Activate=0
DeleteMapAfterCompile=1
Encrypt Password=""
EurekaLog Last Line -->