2014-10-18 01:12:32 +02:00
|
|
|
(*
|
|
|
|
**************************************************************************************************
|
|
|
|
Project Delphi-OpenCV
|
|
|
|
**************************************************************************************************
|
|
|
|
Contributor:
|
|
|
|
Laentir Valetov
|
|
|
|
email:laex@bk.ru
|
|
|
|
Mikhail Grigorev
|
|
|
|
email:sleuthound@gmail.com
|
|
|
|
**************************************************************************************************
|
|
|
|
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://ocv.org
|
|
|
|
Online docs: http://docs.ocv.org
|
|
|
|
Q&A forum: http://answers.ocv.org
|
|
|
|
Dev zone: http://code.ocv.org
|
|
|
|
**************************************************************************************************
|
|
|
|
Original file:
|
|
|
|
opencv\modules\video\include\opencv2\video\tracking_c.h
|
|
|
|
*************************************************************************************************
|
|
|
|
*)
|
|
|
|
|
2014-05-22 16:23:41 +02:00
|
|
|
unit ocv.tracking_c;
|
2013-04-13 16:59:47 +02:00
|
|
|
|
2016-07-31 18:23:31 +02:00
|
|
|
{$I OpenCV.inc}
|
|
|
|
|
2013-04-13 16:59:47 +02:00
|
|
|
interface
|
|
|
|
|
2014-05-22 16:23:41 +02:00
|
|
|
uses ocv.core.types_c, ocv.imgproc.types_c;
|
2013-04-13 16:59:47 +02:00
|
|
|
|
2014-10-10 21:08:51 +02:00
|
|
|
(* ****************************************************************************************
|
|
|
|
* Motion Analysis *
|
|
|
|
*************************************************************************************** *)
|
|
|
|
|
|
|
|
// ************************************ optical flow ***************************************
|
2013-04-13 16:59:47 +02:00
|
|
|
const
|
2015-10-05 18:46:36 +02:00
|
|
|
CV_LKFLOW_PYR_A_READY = 1;
|
|
|
|
CV_LKFLOW_PYR_B_READY = 2;
|
|
|
|
CV_LKFLOW_INITIAL_GUESSES = 4;
|
2013-04-13 16:59:47 +02:00
|
|
|
CV_LKFLOW_GET_MIN_EIGENVALS = 8;
|
|
|
|
|
2014-10-10 21:08:51 +02:00
|
|
|
(*
|
|
|
|
It is Lucas & Kanade method, modified to use pyramids.
|
|
|
|
Also it does several iterations to get optical flow for
|
|
|
|
every point at every pyramid level.
|
|
|
|
Calculates optical flow between two images for certain set of points (i.e.
|
|
|
|
it is a "sparse" optical flow, which is opposite to the previous 3 methods)
|
|
|
|
|
|
|
|
CVAPI(void) cvCalcOpticalFlowPyrLK( const CvArr* prev, const CvArr* curr,
|
|
|
|
CvArr* prev_pyr, CvArr* curr_pyr,
|
|
|
|
const CvPoint2D32f* prev_features,
|
|
|
|
CvPoint2D32f* curr_features,
|
|
|
|
int count,
|
|
|
|
CvSize win_size,
|
|
|
|
int level,
|
|
|
|
char* status,
|
|
|
|
float* track_error,
|
|
|
|
CvTermCriteria criteria,
|
|
|
|
int flags );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
|
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
|
|
|
Type
|
|
|
|
TcvCalcOpticalFlowPyrLK = procedure(const prev: pIplImage; const curr: pIplImage; prev_pyr: pIplImage; curr_pyr: pIplImage;
|
|
|
|
const prev_features: pCvPoint2D32f; curr_features: pCvPoint2D32f; count: Integer; win_size: TCvSize; level: Integer; status: pCVChar;
|
|
|
|
track_error: PSingle; criteria: TCvTermCriteria; flags: Integer); cdecl;
|
|
|
|
|
|
|
|
Var
|
|
|
|
cvCalcOpticalFlowPyrLK: TcvCalcOpticalFlowPyrLK;
|
|
|
|
{$ELSE}
|
2014-10-10 21:08:51 +02:00
|
|
|
{$EXTERNALSYM cvCalcOpticalFlowPyrLK}
|
2013-05-26 10:50:18 +02:00
|
|
|
procedure cvCalcOpticalFlowPyrLK(const prev: pIplImage; const curr: pIplImage; prev_pyr: pIplImage; curr_pyr: pIplImage;
|
2015-10-05 18:46:36 +02:00
|
|
|
const prev_features: pCvPoint2D32f; curr_features: pCvPoint2D32f; count: Integer; win_size: TCvSize; level: Integer; status: pCVChar;
|
|
|
|
track_error: PSingle; criteria: TCvTermCriteria; flags: Integer); cdecl;
|
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(* Modification of a previous sparse optical flow algorithm to calculate
|
|
|
|
affine flow
|
|
|
|
|
|
|
|
CVAPI(void) cvCalcAffineFlowPyrLK( const CvArr* prev, const CvArr* curr,
|
|
|
|
CvArr* prev_pyr, CvArr* curr_pyr,
|
|
|
|
const CvPoint2D32f* prev_features,
|
|
|
|
CvPoint2D32f* curr_features,
|
|
|
|
float* matrices, int count,
|
|
|
|
CvSize win_size, int level,
|
|
|
|
char* status, float* track_error,
|
|
|
|
CvTermCriteria criteria, int flags );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
2014-10-10 21:08:51 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
Type
|
|
|
|
TcvCalcAffineFlowPyrLK = procedure(const prev: pCvArr; const curr: pCvArr; prev_pyr: pCvArr; curr_pyr: pCvArr; const prev_features: pCvPoint2D32f;
|
|
|
|
var curr_features: TCvPoint2D32f; var matrices: Single; count: Integer; win_size: TCvSize; level: Integer; status: pCVChar;
|
|
|
|
var track_error: Single; criteria: TCvTermCriteria; flags: Integer); cdecl;
|
|
|
|
|
|
|
|
Var
|
|
|
|
cvCalcAffineFlowPyrLK: TcvCalcAffineFlowPyrLK;
|
|
|
|
{$ELSE}
|
|
|
|
{$EXTERNALSYM cvCalcAffineFlowPyrLK}
|
|
|
|
procedure cvCalcAffineFlowPyrLK(const prev: pCvArr; const curr: pCvArr; prev_pyr: pCvArr; curr_pyr: pCvArr; const prev_features: pCvPoint2D32f;
|
|
|
|
var curr_features: TCvPoint2D32f; var matrices: Single; count: Integer; win_size: TCvSize; level: Integer; status: pCVChar; var track_error: Single;
|
|
|
|
criteria: TCvTermCriteria; flags: Integer); cdecl;
|
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(*
|
|
|
|
Estimate rigid transformation between 2 images or 2 point sets
|
|
|
|
|
|
|
|
CVAPI(int) cvEstimateRigidTransform( const CvArr* A, const CvArr* B,
|
|
|
|
CvMat* M, int full_affine );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
2014-10-10 21:08:51 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
Type
|
|
|
|
TcvEstimateRigidTransform = function(const A: pCvArr; const B: pCvArr; var M: TCvMat; full_affine: Integer): Integer; cdecl;
|
2014-10-10 21:08:51 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
var
|
|
|
|
cvEstimateRigidTransform: TcvEstimateRigidTransform;
|
|
|
|
{$ELSE}
|
|
|
|
{$EXTERNALSYM cvEstimateRigidTransform}
|
|
|
|
function cvEstimateRigidTransform(const A: pCvArr; const B: pCvArr; var M: TCvMat; full_affine: Integer): Integer; cdecl;
|
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(*
|
|
|
|
Estimate optical flow for each pixel using the two-frame G. Farneback algorithm
|
|
|
|
|
|
|
|
CVAPI(void) cvCalcOpticalFlowFarneback( const CvArr* prev, const CvArr* next,
|
|
|
|
CvArr* flow, double pyr_scale, int levels,
|
|
|
|
int winsize, int iterations, int poly_n,
|
|
|
|
double poly_sigma, int flags );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
|
|
|
type
|
|
|
|
TcvCalcOpticalFlowFarneback = procedure(const prev: pCvMat; const next: pCvMat; flow: pCvMat; pyr_scale: double; levels: Integer; winsize: Integer;
|
|
|
|
iterations: Integer; poly_n: Integer; poly_sigma: double; flags: Integer); cdecl;
|
2013-05-26 10:50:18 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
var
|
|
|
|
cvCalcOpticalFlowFarneback: TcvCalcOpticalFlowFarneback;
|
|
|
|
{$ELSE}
|
|
|
|
{$EXTERNALSYM cvCalcOpticalFlowFarneback}
|
|
|
|
procedure cvCalcOpticalFlowFarneback(const prev: pCvMat; const next: pCvMat; flow: pCvMat; pyr_scale: double; levels: Integer; winsize: Integer;
|
|
|
|
iterations: Integer; poly_n: Integer; poly_sigma: double; flags: Integer); cdecl;
|
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(* ******************************** motion templates ************************************ *)
|
|
|
|
|
|
|
|
(* *****************************************************************************************
|
|
|
|
* All the motion template functions work only with single channel images. *
|
|
|
|
* Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S *
|
|
|
|
* Motion history image must have depth IPL_DEPTH_32F, *
|
|
|
|
* Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S, *
|
|
|
|
* Motion orientation image - IPL_DEPTH_32F *
|
|
|
|
* Segmentation mask - IPL_DEPTH_32F *
|
|
|
|
* All the angles are in degrees, all the times are in milliseconds *
|
|
|
|
*************************************************************************************** *)
|
|
|
|
|
|
|
|
(*
|
|
|
|
Updates motion history image given motion silhouette
|
|
|
|
|
|
|
|
CVAPI(void) cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
|
|
|
|
double timestamp, double duration );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
|
|
|
Type
|
|
|
|
TcvUpdateMotionHistory = procedure(const silhouette: pCvArr; mhi: pCvArr; timestamp: double; duration: double); cdecl;
|
|
|
|
|
|
|
|
var
|
|
|
|
cvUpdateMotionHistory: TcvUpdateMotionHistory;
|
|
|
|
{$ELSE}
|
2014-10-10 21:08:51 +02:00
|
|
|
{$EXTERNALSYM cvUpdateMotionHistory}
|
2013-04-13 16:59:47 +02:00
|
|
|
procedure cvUpdateMotionHistory(const silhouette: pCvArr; mhi: pCvArr; timestamp: double; duration: double); cdecl;
|
2015-10-05 18:46:36 +02:00
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(*
|
|
|
|
Calculates gradient of the motion history image and fills
|
|
|
|
a mask indicating where the gradient is valid
|
|
|
|
|
|
|
|
CVAPI(void) cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
|
|
|
|
double delta1, double delta2,
|
|
|
|
int aperture_size CV_DEFAULT(3));
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
|
|
|
Type
|
|
|
|
TcvCalcMotionGradient = procedure(const mhi: pCvArr; mask: pCvArr; orientation: pCvArr; delta1: double; delta2: double;
|
|
|
|
aperture_size: Integer = 3); cdecl;
|
|
|
|
|
|
|
|
var
|
|
|
|
cvCalcMotionGradient: TcvCalcMotionGradient;
|
|
|
|
{$ELSE}
|
2014-10-10 21:08:51 +02:00
|
|
|
{$EXTERNALSYM cvCalcMotionGradient}
|
2013-04-13 16:59:47 +02:00
|
|
|
procedure cvCalcMotionGradient(const mhi: pCvArr; mask: pCvArr; orientation: pCvArr; delta1: double; delta2: double;
|
|
|
|
aperture_size: Integer = 3); cdecl;
|
2015-10-05 18:46:36 +02:00
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(* Calculates average motion direction within a selected motion region
|
|
|
|
(region can be selected by setting ROIs and/or by composing a valid gradient mask
|
|
|
|
with the region mask)
|
|
|
|
|
|
|
|
CVAPI(double) cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
|
|
|
|
const CvArr* mhi, double timestamp,
|
|
|
|
double duration );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
|
|
|
type
|
|
|
|
TcvCalcGlobalOrientation = function(const orientation: pCvArr; const mask: pCvArr; const mhi: pCvArr; timestamp: double; duration: double)
|
|
|
|
: double; cdecl;
|
2013-04-13 16:59:47 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
var
|
|
|
|
cvCalcGlobalOrientation: TcvCalcGlobalOrientation;
|
|
|
|
{$ELSE}
|
|
|
|
{$EXTERNALSYM cvCalcGlobalOrientation}
|
|
|
|
function cvCalcGlobalOrientation(const orientation: pCvArr; const mask: pCvArr; const mhi: pCvArr; timestamp: double; duration: double)
|
|
|
|
: double; cdecl;
|
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(* Splits a motion history image into a few parts corresponding to separate independent motions
|
|
|
|
(e.g. left hand, right hand)
|
|
|
|
|
|
|
|
CVAPI(CvSeq* ) cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,
|
|
|
|
CvMemStorage* storage,
|
|
|
|
double timestamp, double seg_thresh );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
|
|
|
type
|
|
|
|
TcvSegmentMotion = function(const mhi: pCvArr; seg_mask: pCvArr; storage: pCvMemStorage; timestamp: double; seg_thresh: double): pCvSeq; cdecl;
|
2013-04-13 16:59:47 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
var
|
|
|
|
cvSegmentMotion: TcvSegmentMotion;
|
|
|
|
{$ELSE}
|
|
|
|
{$EXTERNALSYM cvSegmentMotion}
|
|
|
|
function cvSegmentMotion(const mhi: pCvArr; seg_mask: pCvArr; storage: pCvMemStorage; timestamp: double; seg_thresh: double): pCvSeq; cdecl;
|
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(* ****************************************************************************************
|
|
|
|
* Tracking *
|
|
|
|
*************************************************************************************** *)
|
|
|
|
|
|
|
|
(*
|
|
|
|
Implements CAMSHIFT algorithm - determines object position, size and orientation
|
|
|
|
from the object histogram back project (extension of meanshift)
|
|
|
|
|
|
|
|
CVAPI(int) cvCamShift( const CvArr* prob_image, CvRect window,
|
|
|
|
CvTermCriteria criteria, CvConnectedComp* comp,
|
|
|
|
CvBox2D* box CV_DEFAULT(NULL) );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
2013-05-26 10:50:18 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
type
|
|
|
|
TcvCamShift = function(const prob_image: pIplImage; window: TCvRect; criteria: TCvTermCriteria; comp: pCvConnectedComp; box: pCvBox2D = nil)
|
|
|
|
: Integer; cdecl;
|
|
|
|
|
|
|
|
var
|
|
|
|
cvCamShift: TcvCamShift;
|
|
|
|
{$ELSE}
|
|
|
|
{$EXTERNALSYM cvCamShift}
|
|
|
|
function cvCamShift(const prob_image: pIplImage; window: TCvRect; criteria: TCvTermCriteria; comp: pCvConnectedComp; box: pCvBox2D = nil)
|
|
|
|
: Integer; cdecl;
|
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(* Implements MeanShift algorithm - determines object position
|
|
|
|
from the object histogram back project
|
|
|
|
|
|
|
|
CVAPI(int) cvMeanShift( const CvArr* prob_image, CvRect window,
|
|
|
|
CvTermCriteria criteria, CvConnectedComp* comp );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
|
|
|
type
|
|
|
|
TcvMeanShift = function(const prob_image: pCvArr; window: TCvRect; criteria: TCvTermCriteria; var comp: TCvConnectedComp): Integer; cdecl;
|
|
|
|
|
|
|
|
var
|
|
|
|
cvMeanShift: TcvMeanShift;
|
|
|
|
{$ELSE}
|
2014-10-10 21:08:51 +02:00
|
|
|
{$EXTERNALSYM cvMeanShift}
|
2015-10-05 18:46:36 +02:00
|
|
|
function cvMeanShift(const prob_image: pCvArr; window: TCvRect; criteria: TCvTermCriteria; var comp: TCvConnectedComp): Integer; cdecl;
|
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
|
|
|
|
(*
|
|
|
|
standard Kalman filter (in G. Welch' and G. Bishop's notation):
|
|
|
|
|
|
|
|
x(k)=A*x(k-1)+B*u(k)+w(k) p(w)~N(0,Q)
|
|
|
|
z(k)=H*x(k)+v(k), p(v)~N(0,R)
|
|
|
|
*)
|
|
|
|
Type
|
|
|
|
pCvKalman = ^TCvKalman;
|
|
|
|
|
|
|
|
{$EXTERNALSYM TCvKalman}
|
|
|
|
|
|
|
|
TCvKalman = record
|
|
|
|
MP: Integer; (* number of measurement vector dimensions *)
|
|
|
|
DP: Integer; (* number of state vector dimensions *)
|
|
|
|
CP: Integer; (* number of control vector dimensions *)
|
|
|
|
|
|
|
|
(* backward compatibility fields *)
|
2015-10-05 18:46:36 +02:00
|
|
|
// {$IFDEF 1}
|
2014-10-10 21:08:51 +02:00
|
|
|
PosterState: PSingle; (* =state_pre->data.fl *)
|
|
|
|
PriorState: PSingle; (* =state_post->data.fl *)
|
|
|
|
DynamMatr: PSingle; (* =transition_matrix->data.fl *)
|
|
|
|
MeasurementMatr: PSingle; (* =measurement_matrix->data.fl *)
|
|
|
|
MNCovariance: PSingle; (* =measurement_noise_cov->data.fl *)
|
|
|
|
PNCovariance: PSingle; (* =process_noise_cov->data.fl *)
|
|
|
|
KalmGainMatr: PSingle; (* =gain->data.fl *)
|
|
|
|
PriorErrorCovariance: PSingle; (* =error_cov_pre->data.fl *)
|
|
|
|
PosterErrorCovariance: PSingle; (* =error_cov_post->data.fl *)
|
2015-04-23 00:23:04 +02:00
|
|
|
_Temp1: PSingle; (* temp1->data.fl *)
|
|
|
|
_Temp2: PSingle; (* temp2->data.fl *)
|
2015-10-05 18:46:36 +02:00
|
|
|
// {$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
state_pre: pCvMat; (* predicted state (x'(k)):
|
|
|
|
x(k)=A*x(k-1)+B*u(k) *)
|
|
|
|
state_post: pCvMat; (* corrected state (x(k)):
|
|
|
|
x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) *)
|
|
|
|
transition_matrix: pCvMat; (* state transition matrix (A) *)
|
|
|
|
control_matrix: pCvMat; (* control matrix (B)
|
|
|
|
(it is not used if there is no control) *)
|
|
|
|
measurement_matrix: pCvMat; (* measurement matrix (H) *)
|
|
|
|
process_noise_cov: pCvMat; (* process noise covariance matrix (Q) *)
|
|
|
|
measurement_noise_cov: pCvMat; (* measurement noise covariance matrix (R) *)
|
|
|
|
error_cov_pre: pCvMat; (* priori error estimate covariance matrix (P'(k)):
|
|
|
|
P'(k)=A*P(k-1)*At + Q) *)
|
|
|
|
gain: pCvMat; (* Kalman gain matrix (K(k)):
|
|
|
|
K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R) *)
|
|
|
|
error_cov_post: pCvMat; (* posteriori error estimate covariance matrix (P(k)):
|
|
|
|
P(k)=(I-K(k)*H)*P'(k) *)
|
|
|
|
Temp1: pCvMat; (* temporary matrices *)
|
|
|
|
Temp2: pCvMat;
|
|
|
|
temp3: pCvMat;
|
|
|
|
temp4: pCvMat;
|
|
|
|
temp5: pCvMat;
|
|
|
|
end;
|
|
|
|
//
|
|
|
|
(*
|
|
|
|
Creates Kalman filter and sets A, B, Q, R and state to some initial values
|
|
|
|
|
|
|
|
CVAPI(CvKalman* ) cvCreateKalman( int dynam_params, int measure_params,
|
|
|
|
int control_params CV_DEFAULT(0));
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
2014-10-10 21:08:51 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
type
|
|
|
|
TcvCreateKalman = function(dynam_params: Integer; measure_params: Integer; control_params: Integer = 0): pCvKalman; cdecl;
|
2014-10-10 21:08:51 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
var
|
|
|
|
cvCreateKalman: TcvCreateKalman;
|
|
|
|
{$ELSE}
|
|
|
|
{$EXTERNALSYM cvCreateKalman}
|
|
|
|
function cvCreateKalman(dynam_params: Integer; measure_params: Integer; control_params: Integer = 0): pCvKalman; cdecl;
|
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(*
|
|
|
|
Releases Kalman filter state
|
|
|
|
|
|
|
|
CVAPI(void) cvReleaseKalman( CvKalman** kalman);
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
|
|
|
type
|
|
|
|
TcvReleaseKalman = procedure(var kalman: pCvKalman); cdecl;
|
|
|
|
|
|
|
|
var
|
|
|
|
cvReleaseKalman: TcvReleaseKalman;
|
|
|
|
{$ELSE}
|
2014-10-10 21:08:51 +02:00
|
|
|
{$EXTERNALSYM cvReleaseKalman}
|
|
|
|
procedure cvReleaseKalman(var kalman: pCvKalman); cdecl;
|
2015-10-05 18:46:36 +02:00
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
(*
|
|
|
|
Updates Kalman filter by time (predicts future state of the system)
|
|
|
|
CVAPI(const CvMat* cvKalmanPredict( CvKalman* kalman,
|
|
|
|
const CvMat* control CV_DEFAULT(NULL));
|
2015-10-05 18:46:36 +02:00
|
|
|
|
2015-11-12 16:46:36 +01:00
|
|
|
Updates Kalman filter by measurement
|
2014-10-10 21:08:51 +02:00
|
|
|
(corrects state of the system and internal matrices)
|
|
|
|
CVAPI(const CvMat* ) cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement );
|
|
|
|
*)
|
2015-10-05 18:46:36 +02:00
|
|
|
|
|
|
|
type
|
2015-11-12 16:46:36 +01:00
|
|
|
TcvKalmanPredict = function(var kalman: TCvKalman; const control: pCvMat = nil): pCvMat; cdecl;
|
2015-10-05 18:46:36 +02:00
|
|
|
TcvKalmanCorrect = function(var kalman: TCvKalman; const measurement: pCvMat): pCvMat; cdecl;
|
|
|
|
|
2015-11-12 16:46:36 +01:00
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
var
|
2015-11-12 16:46:36 +01:00
|
|
|
cvKalmanPredict: TcvKalmanPredict;
|
2015-10-05 18:46:36 +02:00
|
|
|
cvKalmanCorrect: TcvKalmanCorrect;
|
|
|
|
{$ELSE}
|
2015-11-12 16:46:36 +01:00
|
|
|
{$EXTERNALSYM cvKalmanPredict}
|
|
|
|
function cvKalmanPredict(var kalman: TCvKalman; const control: pCvMat = nil): pCvMat; cdecl;
|
2014-10-10 21:08:51 +02:00
|
|
|
{$EXTERNALSYM cvKalmanCorrect}
|
|
|
|
function cvKalmanCorrect(var kalman: TCvKalman; const measurement: pCvMat): pCvMat; cdecl;
|
2015-10-05 18:46:36 +02:00
|
|
|
{$ENDIF}
|
2014-10-10 21:08:51 +02:00
|
|
|
|
|
|
|
Var
|
|
|
|
{$EXTERNALSYM cvKalmanUpdateByTime}
|
2015-10-05 18:46:36 +02:00
|
|
|
cvKalmanUpdateByTime: TcvKalmanPredict {$IFNDEF SAFELOADLIB} = cvKalmanPredict {$ENDIF};
|
2014-10-10 21:08:51 +02:00
|
|
|
{$EXTERNALSYM cvKalmanUpdateByMeasurement}
|
2015-10-05 18:46:36 +02:00
|
|
|
cvKalmanUpdateByMeasurement: TcvKalmanCorrect{$IFNDEF SAFELOADLIB} = cvKalmanCorrect{$ENDIF};
|
2013-04-13 16:59:47 +02:00
|
|
|
|
2016-08-05 12:41:08 +02:00
|
|
|
{$IF DEFINED(SAFELOADLIB) AND DEFINED(DEBUG)}
|
|
|
|
procedure Init_opencv_Tracking_lib;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2013-04-13 16:59:47 +02:00
|
|
|
implementation
|
|
|
|
|
2014-05-22 08:53:48 +02:00
|
|
|
uses
|
2014-05-22 16:23:41 +02:00
|
|
|
ocv.lib;
|
2013-04-13 16:59:47 +02:00
|
|
|
|
2015-10-05 18:46:36 +02:00
|
|
|
{$IFDEF SAFELOADLIB}
|
|
|
|
|
|
|
|
Var
|
|
|
|
TrackingDLL: Cardinal;
|
|
|
|
|
|
|
|
procedure Init_opencv_Tracking_lib;
|
|
|
|
begin
|
2015-11-12 16:46:36 +01:00
|
|
|
TrackingDLL := ocvLoadLibrary(tracking_lib);
|
2015-10-05 18:46:36 +02:00
|
|
|
Assert(TrackingDLL <> 0, 'Can not init ' + tracking_lib);
|
|
|
|
|
|
|
|
cvCalcOpticalFlowPyrLK := ocvGetProcAddress('cvCalcOpticalFlowPyrLK', TrackingDLL);
|
|
|
|
cvCalcAffineFlowPyrLK := ocvGetProcAddress('cvCalcAffineFlowPyrLK', TrackingDLL);
|
|
|
|
cvEstimateRigidTransform := ocvGetProcAddress('cvEstimateRigidTransform', TrackingDLL);
|
|
|
|
cvCalcOpticalFlowFarneback := ocvGetProcAddress('cvCalcOpticalFlowFarneback', TrackingDLL);
|
|
|
|
cvUpdateMotionHistory := ocvGetProcAddress('cvUpdateMotionHistory', TrackingDLL);
|
|
|
|
cvCalcMotionGradient := ocvGetProcAddress('cvCalcMotionGradient', TrackingDLL);
|
|
|
|
cvCalcGlobalOrientation := ocvGetProcAddress('cvCalcGlobalOrientation', TrackingDLL);
|
|
|
|
cvSegmentMotion := ocvGetProcAddress('cvSegmentMotion', TrackingDLL);
|
|
|
|
cvCamShift := ocvGetProcAddress('cvCamShift', TrackingDLL);
|
|
|
|
cvMeanShift := ocvGetProcAddress('cvMeanShift', TrackingDLL);
|
|
|
|
cvCreateKalman := ocvGetProcAddress('cvCreateKalman', TrackingDLL);
|
|
|
|
cvReleaseKalman := ocvGetProcAddress('cvReleaseKalman', TrackingDLL);
|
|
|
|
cvKalmanPredict := ocvGetProcAddress('cvKalmanPredict', TrackingDLL);
|
|
|
|
cvKalmanCorrect := ocvGetProcAddress('cvKalmanCorrect', TrackingDLL);
|
|
|
|
cvKalmanUpdateByTime := cvKalmanPredict;
|
|
|
|
cvKalmanUpdateByMeasurement := cvKalmanCorrect;
|
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
2015-11-12 16:46:36 +01:00
|
|
|
Init_opencv_Tracking_lib;
|
2015-10-05 18:46:36 +02:00
|
|
|
|
|
|
|
{$ELSE}
|
2014-05-22 08:53:48 +02:00
|
|
|
function cvCamShift; external tracking_lib;
|
|
|
|
procedure cvCalcOpticalFlowPyrLK; external tracking_lib;
|
|
|
|
procedure cvCalcOpticalFlowFarneback; external tracking_lib;
|
2013-05-26 10:50:18 +02:00
|
|
|
|
2014-05-22 08:53:48 +02:00
|
|
|
procedure cvUpdateMotionHistory; external tracking_lib;
|
|
|
|
procedure cvCalcMotionGradient; external tracking_lib;
|
|
|
|
function cvSegmentMotion; external tracking_lib;
|
|
|
|
function cvCalcGlobalOrientation; external tracking_lib;
|
2014-10-10 21:08:51 +02:00
|
|
|
procedure cvCalcAffineFlowPyrLK; external tracking_lib;
|
|
|
|
function cvEstimateRigidTransform; external tracking_lib;
|
|
|
|
function cvMeanShift; external tracking_lib;
|
|
|
|
function cvCreateKalman; external tracking_lib;
|
|
|
|
function cvKalmanPredict; external tracking_lib;
|
|
|
|
function cvKalmanCorrect; external tracking_lib;
|
|
|
|
procedure cvReleaseKalman; external tracking_lib;
|
2015-10-05 18:46:36 +02:00
|
|
|
{$ENDIF}
|
2013-04-13 16:59:47 +02:00
|
|
|
|
|
|
|
end.
|