opencv on mbed

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers tracking_c.h Source File

tracking_c.h

00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                          License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
00016 // Third party copyrights are property of their respective owners.
00017 //
00018 // Redistribution and use in source and binary forms, with or without modification,
00019 // are permitted provided that the following conditions are met:
00020 //
00021 //   * Redistribution's of source code must retain the above copyright notice,
00022 //     this list of conditions and the following disclaimer.
00023 //
00024 //   * Redistribution's in binary form must reproduce the above copyright notice,
00025 //     this list of conditions and the following disclaimer in the documentation
00026 //     and/or other materials provided with the distribution.
00027 //
00028 //   * The name of the copyright holders may not be used to endorse or promote products
00029 //     derived from this software without specific prior written permission.
00030 //
00031 // This software is provided by the copyright holders and contributors "as is" and
00032 // any express or implied warranties, including, but not limited to, the implied
00033 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00034 // In no event shall the Intel Corporation or contributors be liable for any direct,
00035 // indirect, incidental, special, exemplary, or consequential damages
00036 // (including, but not limited to, procurement of substitute goods or services;
00037 // loss of use, data, or profits; or business interruption) however caused
00038 // and on any theory of liability, whether in contract, strict liability,
00039 // or tort (including negligence or otherwise) arising in any way out of
00040 // the use of this software, even if advised of the possibility of such damage.
00041 //
00042 //M*/
00043 
00044 #ifndef __OPENCV_TRACKING_C_H__
00045 #define __OPENCV_TRACKING_C_H__
00046 
00047 #include "opencv2/imgproc/types_c.h"
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 /** @addtogroup video_c
00054   @{
00055 */
00056 
00057 /****************************************************************************************\
00058 *                                  Motion Analysis                                       *
00059 \****************************************************************************************/
00060 
00061 /************************************ optical flow ***************************************/
00062 
00063 #define CV_LKFLOW_PYR_A_READY       1
00064 #define CV_LKFLOW_PYR_B_READY       2
00065 #define CV_LKFLOW_INITIAL_GUESSES   4
00066 #define CV_LKFLOW_GET_MIN_EIGENVALS 8
00067 
00068 /* It is Lucas & Kanade method, modified to use pyramids.
00069    Also it does several iterations to get optical flow for
00070    every point at every pyramid level.
00071    Calculates optical flow between two images for certain set of points (i.e.
00072    it is a "sparse" optical flow, which is opposite to the previous 3 methods) */
00073 CVAPI(void)  cvCalcOpticalFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
00074                                      CvArr*  prev_pyr, CvArr*  curr_pyr,
00075                                      const CvPoint2D32f* prev_features,
00076                                      CvPoint2D32f* curr_features,
00077                                      int       count,
00078                                      CvSize    win_size,
00079                                      int       level,
00080                                      char*     status,
00081                                      float*    track_error,
00082                                      CvTermCriteria  criteria,
00083                                      int       flags );
00084 
00085 
00086 /* Modification of a previous sparse optical flow algorithm to calculate
00087    affine flow */
00088 CVAPI(void)  cvCalcAffineFlowPyrLK( const CvArr*  prev, const CvArr*  curr,
00089                                     CvArr*  prev_pyr, CvArr*  curr_pyr,
00090                                     const CvPoint2D32f* prev_features,
00091                                     CvPoint2D32f* curr_features,
00092                                     float* matrices, int  count,
00093                                     CvSize win_size, int  level,
00094                                     char* status, float* track_error,
00095                                     CvTermCriteria  criteria, int flags );
00096 
00097 /* Estimate rigid transformation between 2 images or 2 point sets */
00098 CVAPI(int)  cvEstimateRigidTransform( const CvArr* A, const CvArr* B,
00099                                       CvMat* M, int full_affine );
00100 
00101 /* Estimate optical flow for each pixel using the two-frame G. Farneback algorithm */
00102 CVAPI(void) cvCalcOpticalFlowFarneback( const CvArr* prev, const CvArr* next,
00103                                         CvArr* flow, double pyr_scale, int levels,
00104                                         int winsize, int iterations, int poly_n,
00105                                         double poly_sigma, int flags );
00106 
00107 /********************************* motion templates *************************************/
00108 
00109 /****************************************************************************************\
00110 *        All the motion template functions work only with single channel images.         *
00111 *        Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S                   *
00112 *        Motion history image must have depth IPL_DEPTH_32F,                             *
00113 *        Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S,                                   *
00114 *        Motion orientation image - IPL_DEPTH_32F                                        *
00115 *        Segmentation mask - IPL_DEPTH_32F                                               *
00116 *        All the angles are in degrees, all the times are in milliseconds                *
00117 \****************************************************************************************/
00118 
00119 /* Updates motion history image given motion silhouette */
00120 CVAPI(void)    cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
00121                                       double timestamp, double duration );
00122 
00123 /* Calculates gradient of the motion history image and fills
00124    a mask indicating where the gradient is valid */
00125 CVAPI(void)    cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
00126                                      double delta1, double delta2,
00127                                      int aperture_size CV_DEFAULT(3));
00128 
00129 /* Calculates average motion direction within a selected motion region
00130    (region can be selected by setting ROIs and/or by composing a valid gradient mask
00131    with the region mask) */
00132 CVAPI(double)  cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
00133                                         const CvArr* mhi, double timestamp,
00134                                         double duration );
00135 
00136 /* Splits a motion history image into a few parts corresponding to separate independent motions
00137    (e.g. left hand, right hand) */
00138 CVAPI(CvSeq*)  cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,
00139                                 CvMemStorage* storage,
00140                                 double timestamp, double seg_thresh );
00141 
00142 /****************************************************************************************\
00143 *                                       Tracking                                         *
00144 \****************************************************************************************/
00145 
00146 /* Implements CAMSHIFT algorithm - determines object position, size and orientation
00147    from the object histogram back project (extension of meanshift) */
00148 CVAPI(int)  cvCamShift( const CvArr* prob_image, CvRect   window,
00149                         CvTermCriteria  criteria, CvConnectedComp* comp,
00150                         CvBox2D * box CV_DEFAULT(NULL) );
00151 
00152 /* Implements MeanShift algorithm - determines object position
00153    from the object histogram back project */
00154 CVAPI(int)  cvMeanShift( const CvArr* prob_image, CvRect   window,
00155                          CvTermCriteria  criteria, CvConnectedComp* comp );
00156 
00157 /*
00158 standard Kalman filter (in G. Welch' and G. Bishop's notation):
00159 
00160   x(k)=A*x(k-1)+B*u(k)+w(k)  p(w)~N(0,Q)
00161   z(k)=H*x(k)+v(k),   p(v)~N(0,R)
00162 */
00163 typedef struct CvKalman
00164 {
00165     int MP;                     /* number of measurement vector dimensions */
00166     int DP;                     /* number of state vector dimensions */
00167     int CP;                     /* number of control vector dimensions */
00168 
00169     /* backward compatibility fields */
00170 #if 1
00171     float* PosterState;         /* =state_pre->data.fl */
00172     float* PriorState;          /* =state_post->data.fl */
00173     float* DynamMatr;           /* =transition_matrix->data.fl */
00174     float* MeasurementMatr;     /* =measurement_matrix->data.fl */
00175     float* MNCovariance;        /* =measurement_noise_cov->data.fl */
00176     float* PNCovariance;        /* =process_noise_cov->data.fl */
00177     float* KalmGainMatr;        /* =gain->data.fl */
00178     float* PriorErrorCovariance;/* =error_cov_pre->data.fl */
00179     float* PosterErrorCovariance;/* =error_cov_post->data.fl */
00180     float* Temp1;               /* temp1->data.fl */
00181     float* Temp2;               /* temp2->data.fl */
00182 #endif
00183 
00184     CvMat* state_pre;           /* predicted state (x'(k)):
00185                                     x(k)=A*x(k-1)+B*u(k) */
00186     CvMat* state_post;          /* corrected state (x(k)):
00187                                     x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) */
00188     CvMat* transition_matrix;   /* state transition matrix (A) */
00189     CvMat* control_matrix;      /* control matrix (B)
00190                                    (it is not used if there is no control)*/
00191     CvMat* measurement_matrix;  /* measurement matrix (H) */
00192     CvMat* process_noise_cov;   /* process noise covariance matrix (Q) */
00193     CvMat* measurement_noise_cov; /* measurement noise covariance matrix (R) */
00194     CvMat* error_cov_pre;       /* priori error estimate covariance matrix (P'(k)):
00195                                     P'(k)=A*P(k-1)*At + Q)*/
00196     CvMat* gain;                /* Kalman gain matrix (K(k)):
00197                                     K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)*/
00198     CvMat* error_cov_post;      /* posteriori error estimate covariance matrix (P(k)):
00199                                     P(k)=(I-K(k)*H)*P'(k) */
00200     CvMat* temp1;               /* temporary matrices */
00201     CvMat* temp2;
00202     CvMat* temp3;
00203     CvMat* temp4;
00204     CvMat* temp5;
00205 } CvKalman;
00206 
00207 /* Creates Kalman filter and sets A, B, Q, R and state to some initial values */
00208 CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params,
00209                                  int control_params CV_DEFAULT(0));
00210 
00211 /* Releases Kalman filter state */
00212 CVAPI(void)  cvReleaseKalman( CvKalman** kalman);
00213 
00214 /* Updates Kalman filter by time (predicts future state of the system) */
00215 CVAPI(const CvMat*)  cvKalmanPredict( CvKalman* kalman,
00216                                       const CvMat* control CV_DEFAULT(NULL));
00217 
00218 /* Updates Kalman filter by measurement
00219    (corrects state of the system and internal matrices) */
00220 CVAPI(const CvMat*)  cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement );
00221 
00222 #define cvKalmanUpdateByTime  cvKalmanPredict
00223 #define cvKalmanUpdateByMeasurement cvKalmanCorrect
00224 
00225 /** @} video_c */
00226 
00227 #ifdef __cplusplus
00228 } // extern "C"
00229 #endif
00230 
00231 
00232 #endif // __OPENCV_TRACKING_C_H__
00233