openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:0e0631af0305 1 /*M///////////////////////////////////////////////////////////////////////////////////////
RyoheiHagimoto 0:0e0631af0305 2 //
RyoheiHagimoto 0:0e0631af0305 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
RyoheiHagimoto 0:0e0631af0305 4 //
RyoheiHagimoto 0:0e0631af0305 5 // By downloading, copying, installing or using the software you agree to this license.
RyoheiHagimoto 0:0e0631af0305 6 // If you do not agree to this license, do not download, install,
RyoheiHagimoto 0:0e0631af0305 7 // copy or use the software.
RyoheiHagimoto 0:0e0631af0305 8 //
RyoheiHagimoto 0:0e0631af0305 9 //
RyoheiHagimoto 0:0e0631af0305 10 // License Agreement
RyoheiHagimoto 0:0e0631af0305 11 // For Open Source Computer Vision Library
RyoheiHagimoto 0:0e0631af0305 12 //
RyoheiHagimoto 0:0e0631af0305 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
RyoheiHagimoto 0:0e0631af0305 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
RyoheiHagimoto 0:0e0631af0305 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
RyoheiHagimoto 0:0e0631af0305 16 // Third party copyrights are property of their respective owners.
RyoheiHagimoto 0:0e0631af0305 17 //
RyoheiHagimoto 0:0e0631af0305 18 // Redistribution and use in source and binary forms, with or without modification,
RyoheiHagimoto 0:0e0631af0305 19 // are permitted provided that the following conditions are met:
RyoheiHagimoto 0:0e0631af0305 20 //
RyoheiHagimoto 0:0e0631af0305 21 // * Redistribution's of source code must retain the above copyright notice,
RyoheiHagimoto 0:0e0631af0305 22 // this list of conditions and the following disclaimer.
RyoheiHagimoto 0:0e0631af0305 23 //
RyoheiHagimoto 0:0e0631af0305 24 // * Redistribution's in binary form must reproduce the above copyright notice,
RyoheiHagimoto 0:0e0631af0305 25 // this list of conditions and the following disclaimer in the documentation
RyoheiHagimoto 0:0e0631af0305 26 // and/or other materials provided with the distribution.
RyoheiHagimoto 0:0e0631af0305 27 //
RyoheiHagimoto 0:0e0631af0305 28 // * The name of the copyright holders may not be used to endorse or promote products
RyoheiHagimoto 0:0e0631af0305 29 // derived from this software without specific prior written permission.
RyoheiHagimoto 0:0e0631af0305 30 //
RyoheiHagimoto 0:0e0631af0305 31 // This software is provided by the copyright holders and contributors "as is" and
RyoheiHagimoto 0:0e0631af0305 32 // any express or implied warranties, including, but not limited to, the implied
RyoheiHagimoto 0:0e0631af0305 33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
RyoheiHagimoto 0:0e0631af0305 34 // In no event shall the Intel Corporation or contributors be liable for any direct,
RyoheiHagimoto 0:0e0631af0305 35 // indirect, incidental, special, exemplary, or consequential damages
RyoheiHagimoto 0:0e0631af0305 36 // (including, but not limited to, procurement of substitute goods or services;
RyoheiHagimoto 0:0e0631af0305 37 // loss of use, data, or profits; or business interruption) however caused
RyoheiHagimoto 0:0e0631af0305 38 // and on any theory of liability, whether in contract, strict liability,
RyoheiHagimoto 0:0e0631af0305 39 // or tort (including negligence or otherwise) arising in any way out of
RyoheiHagimoto 0:0e0631af0305 40 // the use of this software, even if advised of the possibility of such damage.
RyoheiHagimoto 0:0e0631af0305 41 //
RyoheiHagimoto 0:0e0631af0305 42 //M*/
RyoheiHagimoto 0:0e0631af0305 43
RyoheiHagimoto 0:0e0631af0305 44 #ifndef OPENCV_TRACKING_C_H
RyoheiHagimoto 0:0e0631af0305 45 #define OPENCV_TRACKING_C_H
RyoheiHagimoto 0:0e0631af0305 46
RyoheiHagimoto 0:0e0631af0305 47 #include "opencv2/imgproc/types_c.h"
RyoheiHagimoto 0:0e0631af0305 48
RyoheiHagimoto 0:0e0631af0305 49 #ifdef __cplusplus
RyoheiHagimoto 0:0e0631af0305 50 extern "C" {
RyoheiHagimoto 0:0e0631af0305 51 #endif
RyoheiHagimoto 0:0e0631af0305 52
RyoheiHagimoto 0:0e0631af0305 53 /** @addtogroup video_c
RyoheiHagimoto 0:0e0631af0305 54 @{
RyoheiHagimoto 0:0e0631af0305 55 */
RyoheiHagimoto 0:0e0631af0305 56
RyoheiHagimoto 0:0e0631af0305 57 /****************************************************************************************\
RyoheiHagimoto 0:0e0631af0305 58 * Motion Analysis *
RyoheiHagimoto 0:0e0631af0305 59 \****************************************************************************************/
RyoheiHagimoto 0:0e0631af0305 60
RyoheiHagimoto 0:0e0631af0305 61 /************************************ optical flow ***************************************/
RyoheiHagimoto 0:0e0631af0305 62
RyoheiHagimoto 0:0e0631af0305 63 #define CV_LKFLOW_PYR_A_READY 1
RyoheiHagimoto 0:0e0631af0305 64 #define CV_LKFLOW_PYR_B_READY 2
RyoheiHagimoto 0:0e0631af0305 65 #define CV_LKFLOW_INITIAL_GUESSES 4
RyoheiHagimoto 0:0e0631af0305 66 #define CV_LKFLOW_GET_MIN_EIGENVALS 8
RyoheiHagimoto 0:0e0631af0305 67
RyoheiHagimoto 0:0e0631af0305 68 /* It is Lucas & Kanade method, modified to use pyramids.
RyoheiHagimoto 0:0e0631af0305 69 Also it does several iterations to get optical flow for
RyoheiHagimoto 0:0e0631af0305 70 every point at every pyramid level.
RyoheiHagimoto 0:0e0631af0305 71 Calculates optical flow between two images for certain set of points (i.e.
RyoheiHagimoto 0:0e0631af0305 72 it is a "sparse" optical flow, which is opposite to the previous 3 methods) */
RyoheiHagimoto 0:0e0631af0305 73 CVAPI(void) cvCalcOpticalFlowPyrLK( const CvArr* prev, const CvArr* curr,
RyoheiHagimoto 0:0e0631af0305 74 CvArr* prev_pyr, CvArr* curr_pyr,
RyoheiHagimoto 0:0e0631af0305 75 const CvPoint2D32f* prev_features,
RyoheiHagimoto 0:0e0631af0305 76 CvPoint2D32f* curr_features,
RyoheiHagimoto 0:0e0631af0305 77 int count,
RyoheiHagimoto 0:0e0631af0305 78 CvSize win_size,
RyoheiHagimoto 0:0e0631af0305 79 int level,
RyoheiHagimoto 0:0e0631af0305 80 char* status,
RyoheiHagimoto 0:0e0631af0305 81 float* track_error,
RyoheiHagimoto 0:0e0631af0305 82 CvTermCriteria criteria,
RyoheiHagimoto 0:0e0631af0305 83 int flags );
RyoheiHagimoto 0:0e0631af0305 84
RyoheiHagimoto 0:0e0631af0305 85
RyoheiHagimoto 0:0e0631af0305 86 /* Modification of a previous sparse optical flow algorithm to calculate
RyoheiHagimoto 0:0e0631af0305 87 affine flow */
RyoheiHagimoto 0:0e0631af0305 88 CVAPI(void) cvCalcAffineFlowPyrLK( const CvArr* prev, const CvArr* curr,
RyoheiHagimoto 0:0e0631af0305 89 CvArr* prev_pyr, CvArr* curr_pyr,
RyoheiHagimoto 0:0e0631af0305 90 const CvPoint2D32f* prev_features,
RyoheiHagimoto 0:0e0631af0305 91 CvPoint2D32f* curr_features,
RyoheiHagimoto 0:0e0631af0305 92 float* matrices, int count,
RyoheiHagimoto 0:0e0631af0305 93 CvSize win_size, int level,
RyoheiHagimoto 0:0e0631af0305 94 char* status, float* track_error,
RyoheiHagimoto 0:0e0631af0305 95 CvTermCriteria criteria, int flags );
RyoheiHagimoto 0:0e0631af0305 96
RyoheiHagimoto 0:0e0631af0305 97 /* Estimate rigid transformation between 2 images or 2 point sets */
RyoheiHagimoto 0:0e0631af0305 98 CVAPI(int) cvEstimateRigidTransform( const CvArr* A, const CvArr* B,
RyoheiHagimoto 0:0e0631af0305 99 CvMat* M, int full_affine );
RyoheiHagimoto 0:0e0631af0305 100
RyoheiHagimoto 0:0e0631af0305 101 /* Estimate optical flow for each pixel using the two-frame G. Farneback algorithm */
RyoheiHagimoto 0:0e0631af0305 102 CVAPI(void) cvCalcOpticalFlowFarneback( const CvArr* prev, const CvArr* next,
RyoheiHagimoto 0:0e0631af0305 103 CvArr* flow, double pyr_scale, int levels,
RyoheiHagimoto 0:0e0631af0305 104 int winsize, int iterations, int poly_n,
RyoheiHagimoto 0:0e0631af0305 105 double poly_sigma, int flags );
RyoheiHagimoto 0:0e0631af0305 106
RyoheiHagimoto 0:0e0631af0305 107 /********************************* motion templates *************************************/
RyoheiHagimoto 0:0e0631af0305 108
RyoheiHagimoto 0:0e0631af0305 109 /****************************************************************************************\
RyoheiHagimoto 0:0e0631af0305 110 * All the motion template functions work only with single channel images. *
RyoheiHagimoto 0:0e0631af0305 111 * Silhouette image must have depth IPL_DEPTH_8U or IPL_DEPTH_8S *
RyoheiHagimoto 0:0e0631af0305 112 * Motion history image must have depth IPL_DEPTH_32F, *
RyoheiHagimoto 0:0e0631af0305 113 * Gradient mask - IPL_DEPTH_8U or IPL_DEPTH_8S, *
RyoheiHagimoto 0:0e0631af0305 114 * Motion orientation image - IPL_DEPTH_32F *
RyoheiHagimoto 0:0e0631af0305 115 * Segmentation mask - IPL_DEPTH_32F *
RyoheiHagimoto 0:0e0631af0305 116 * All the angles are in degrees, all the times are in milliseconds *
RyoheiHagimoto 0:0e0631af0305 117 \****************************************************************************************/
RyoheiHagimoto 0:0e0631af0305 118
RyoheiHagimoto 0:0e0631af0305 119 /* Updates motion history image given motion silhouette */
RyoheiHagimoto 0:0e0631af0305 120 CVAPI(void) cvUpdateMotionHistory( const CvArr* silhouette, CvArr* mhi,
RyoheiHagimoto 0:0e0631af0305 121 double timestamp, double duration );
RyoheiHagimoto 0:0e0631af0305 122
RyoheiHagimoto 0:0e0631af0305 123 /* Calculates gradient of the motion history image and fills
RyoheiHagimoto 0:0e0631af0305 124 a mask indicating where the gradient is valid */
RyoheiHagimoto 0:0e0631af0305 125 CVAPI(void) cvCalcMotionGradient( const CvArr* mhi, CvArr* mask, CvArr* orientation,
RyoheiHagimoto 0:0e0631af0305 126 double delta1, double delta2,
RyoheiHagimoto 0:0e0631af0305 127 int aperture_size CV_DEFAULT(3));
RyoheiHagimoto 0:0e0631af0305 128
RyoheiHagimoto 0:0e0631af0305 129 /* Calculates average motion direction within a selected motion region
RyoheiHagimoto 0:0e0631af0305 130 (region can be selected by setting ROIs and/or by composing a valid gradient mask
RyoheiHagimoto 0:0e0631af0305 131 with the region mask) */
RyoheiHagimoto 0:0e0631af0305 132 CVAPI(double) cvCalcGlobalOrientation( const CvArr* orientation, const CvArr* mask,
RyoheiHagimoto 0:0e0631af0305 133 const CvArr* mhi, double timestamp,
RyoheiHagimoto 0:0e0631af0305 134 double duration );
RyoheiHagimoto 0:0e0631af0305 135
RyoheiHagimoto 0:0e0631af0305 136 /* Splits a motion history image into a few parts corresponding to separate independent motions
RyoheiHagimoto 0:0e0631af0305 137 (e.g. left hand, right hand) */
RyoheiHagimoto 0:0e0631af0305 138 CVAPI(CvSeq*) cvSegmentMotion( const CvArr* mhi, CvArr* seg_mask,
RyoheiHagimoto 0:0e0631af0305 139 CvMemStorage* storage,
RyoheiHagimoto 0:0e0631af0305 140 double timestamp, double seg_thresh );
RyoheiHagimoto 0:0e0631af0305 141
RyoheiHagimoto 0:0e0631af0305 142 /****************************************************************************************\
RyoheiHagimoto 0:0e0631af0305 143 * Tracking *
RyoheiHagimoto 0:0e0631af0305 144 \****************************************************************************************/
RyoheiHagimoto 0:0e0631af0305 145
RyoheiHagimoto 0:0e0631af0305 146 /* Implements CAMSHIFT algorithm - determines object position, size and orientation
RyoheiHagimoto 0:0e0631af0305 147 from the object histogram back project (extension of meanshift) */
RyoheiHagimoto 0:0e0631af0305 148 CVAPI(int) cvCamShift( const CvArr* prob_image, CvRect window,
RyoheiHagimoto 0:0e0631af0305 149 CvTermCriteria criteria, CvConnectedComp* comp,
RyoheiHagimoto 0:0e0631af0305 150 CvBox2D* box CV_DEFAULT(NULL) );
RyoheiHagimoto 0:0e0631af0305 151
RyoheiHagimoto 0:0e0631af0305 152 /* Implements MeanShift algorithm - determines object position
RyoheiHagimoto 0:0e0631af0305 153 from the object histogram back project */
RyoheiHagimoto 0:0e0631af0305 154 CVAPI(int) cvMeanShift( const CvArr* prob_image, CvRect window,
RyoheiHagimoto 0:0e0631af0305 155 CvTermCriteria criteria, CvConnectedComp* comp );
RyoheiHagimoto 0:0e0631af0305 156
RyoheiHagimoto 0:0e0631af0305 157 /*
RyoheiHagimoto 0:0e0631af0305 158 standard Kalman filter (in G. Welch' and G. Bishop's notation):
RyoheiHagimoto 0:0e0631af0305 159
RyoheiHagimoto 0:0e0631af0305 160 x(k)=A*x(k-1)+B*u(k)+w(k) p(w)~N(0,Q)
RyoheiHagimoto 0:0e0631af0305 161 z(k)=H*x(k)+v(k), p(v)~N(0,R)
RyoheiHagimoto 0:0e0631af0305 162 */
RyoheiHagimoto 0:0e0631af0305 163 typedef struct CvKalman
RyoheiHagimoto 0:0e0631af0305 164 {
RyoheiHagimoto 0:0e0631af0305 165 int MP; /* number of measurement vector dimensions */
RyoheiHagimoto 0:0e0631af0305 166 int DP; /* number of state vector dimensions */
RyoheiHagimoto 0:0e0631af0305 167 int CP; /* number of control vector dimensions */
RyoheiHagimoto 0:0e0631af0305 168
RyoheiHagimoto 0:0e0631af0305 169 /* backward compatibility fields */
RyoheiHagimoto 0:0e0631af0305 170 #if 1
RyoheiHagimoto 0:0e0631af0305 171 float* PosterState; /* =state_pre->data.fl */
RyoheiHagimoto 0:0e0631af0305 172 float* PriorState; /* =state_post->data.fl */
RyoheiHagimoto 0:0e0631af0305 173 float* DynamMatr; /* =transition_matrix->data.fl */
RyoheiHagimoto 0:0e0631af0305 174 float* MeasurementMatr; /* =measurement_matrix->data.fl */
RyoheiHagimoto 0:0e0631af0305 175 float* MNCovariance; /* =measurement_noise_cov->data.fl */
RyoheiHagimoto 0:0e0631af0305 176 float* PNCovariance; /* =process_noise_cov->data.fl */
RyoheiHagimoto 0:0e0631af0305 177 float* KalmGainMatr; /* =gain->data.fl */
RyoheiHagimoto 0:0e0631af0305 178 float* PriorErrorCovariance;/* =error_cov_pre->data.fl */
RyoheiHagimoto 0:0e0631af0305 179 float* PosterErrorCovariance;/* =error_cov_post->data.fl */
RyoheiHagimoto 0:0e0631af0305 180 float* Temp1; /* temp1->data.fl */
RyoheiHagimoto 0:0e0631af0305 181 float* Temp2; /* temp2->data.fl */
RyoheiHagimoto 0:0e0631af0305 182 #endif
RyoheiHagimoto 0:0e0631af0305 183
RyoheiHagimoto 0:0e0631af0305 184 CvMat* state_pre; /* predicted state (x'(k)):
RyoheiHagimoto 0:0e0631af0305 185 x(k)=A*x(k-1)+B*u(k) */
RyoheiHagimoto 0:0e0631af0305 186 CvMat* state_post; /* corrected state (x(k)):
RyoheiHagimoto 0:0e0631af0305 187 x(k)=x'(k)+K(k)*(z(k)-H*x'(k)) */
RyoheiHagimoto 0:0e0631af0305 188 CvMat* transition_matrix; /* state transition matrix (A) */
RyoheiHagimoto 0:0e0631af0305 189 CvMat* control_matrix; /* control matrix (B)
RyoheiHagimoto 0:0e0631af0305 190 (it is not used if there is no control)*/
RyoheiHagimoto 0:0e0631af0305 191 CvMat* measurement_matrix; /* measurement matrix (H) */
RyoheiHagimoto 0:0e0631af0305 192 CvMat* process_noise_cov; /* process noise covariance matrix (Q) */
RyoheiHagimoto 0:0e0631af0305 193 CvMat* measurement_noise_cov; /* measurement noise covariance matrix (R) */
RyoheiHagimoto 0:0e0631af0305 194 CvMat* error_cov_pre; /* priori error estimate covariance matrix (P'(k)):
RyoheiHagimoto 0:0e0631af0305 195 P'(k)=A*P(k-1)*At + Q)*/
RyoheiHagimoto 0:0e0631af0305 196 CvMat* gain; /* Kalman gain matrix (K(k)):
RyoheiHagimoto 0:0e0631af0305 197 K(k)=P'(k)*Ht*inv(H*P'(k)*Ht+R)*/
RyoheiHagimoto 0:0e0631af0305 198 CvMat* error_cov_post; /* posteriori error estimate covariance matrix (P(k)):
RyoheiHagimoto 0:0e0631af0305 199 P(k)=(I-K(k)*H)*P'(k) */
RyoheiHagimoto 0:0e0631af0305 200 CvMat* temp1; /* temporary matrices */
RyoheiHagimoto 0:0e0631af0305 201 CvMat* temp2;
RyoheiHagimoto 0:0e0631af0305 202 CvMat* temp3;
RyoheiHagimoto 0:0e0631af0305 203 CvMat* temp4;
RyoheiHagimoto 0:0e0631af0305 204 CvMat* temp5;
RyoheiHagimoto 0:0e0631af0305 205 } CvKalman;
RyoheiHagimoto 0:0e0631af0305 206
RyoheiHagimoto 0:0e0631af0305 207 /* Creates Kalman filter and sets A, B, Q, R and state to some initial values */
RyoheiHagimoto 0:0e0631af0305 208 CVAPI(CvKalman*) cvCreateKalman( int dynam_params, int measure_params,
RyoheiHagimoto 0:0e0631af0305 209 int control_params CV_DEFAULT(0));
RyoheiHagimoto 0:0e0631af0305 210
RyoheiHagimoto 0:0e0631af0305 211 /* Releases Kalman filter state */
RyoheiHagimoto 0:0e0631af0305 212 CVAPI(void) cvReleaseKalman( CvKalman** kalman);
RyoheiHagimoto 0:0e0631af0305 213
RyoheiHagimoto 0:0e0631af0305 214 /* Updates Kalman filter by time (predicts future state of the system) */
RyoheiHagimoto 0:0e0631af0305 215 CVAPI(const CvMat*) cvKalmanPredict( CvKalman* kalman,
RyoheiHagimoto 0:0e0631af0305 216 const CvMat* control CV_DEFAULT(NULL));
RyoheiHagimoto 0:0e0631af0305 217
RyoheiHagimoto 0:0e0631af0305 218 /* Updates Kalman filter by measurement
RyoheiHagimoto 0:0e0631af0305 219 (corrects state of the system and internal matrices) */
RyoheiHagimoto 0:0e0631af0305 220 CVAPI(const CvMat*) cvKalmanCorrect( CvKalman* kalman, const CvMat* measurement );
RyoheiHagimoto 0:0e0631af0305 221
RyoheiHagimoto 0:0e0631af0305 222 #define cvKalmanUpdateByTime cvKalmanPredict
RyoheiHagimoto 0:0e0631af0305 223 #define cvKalmanUpdateByMeasurement cvKalmanCorrect
RyoheiHagimoto 0:0e0631af0305 224
RyoheiHagimoto 0:0e0631af0305 225 /** @} video_c */
RyoheiHagimoto 0:0e0631af0305 226
RyoheiHagimoto 0:0e0631af0305 227 #ifdef __cplusplus
RyoheiHagimoto 0:0e0631af0305 228 } // extern "C"
RyoheiHagimoto 0:0e0631af0305 229 #endif
RyoheiHagimoto 0:0e0631af0305 230
RyoheiHagimoto 0:0e0631af0305 231
RyoheiHagimoto 0:0e0631af0305 232 #endif // OPENCV_TRACKING_C_H