Cinder

  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

include/OpenCV/cvcompat.h

Go to the documentation of this file.
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 //                        Intel License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright( C) 2000, Intel Corporation, all rights reserved.
00014 // Third party copyrights are property of their respective owners.
00015 //
00016 // Redistribution and use in source and binary forms, with or without modification,
00017 // are permitted provided that the following conditions are met:
00018 //
00019 //   * Redistribution's of source code must retain the above copyright notice,
00020 //     this list of conditions and the following disclaimer.
00021 //
00022 //   * Redistribution's in binary form must reproduce the above copyright notice,
00023 //     this list of conditions and the following disclaimer in the documentation
00024 //     and/or other materials provided with the distribution.
00025 //
00026 //   * The name of Intel Corporation may not be used to endorse or promote products
00027 //     derived from this software without specific prior written permission.
00028 //
00029 // This software is provided by the copyright holders and contributors "as is" and
00030 // any express or implied warranties, including, but not limited to, the implied
00031 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00032 // In no event shall the Intel Corporation or contributors be liable for any direct,
00033 // indirect, incidental, special, exemplary, or consequential damages
00034 //(including, but not limited to, procurement of substitute goods or services;
00035 // loss of use, data, or profits; or business interruption) however caused
00036 // and on any theory of liability, whether in contract, strict liability,
00037 // or tort(including negligence or otherwise) arising in any way out of
00038 // the use of this software, even if advised of the possibility of such damage.
00039 //
00040 //M*/
00041 
00042 /*
00043    A few macros and definitions for backward compatibility
00044    with the previous versions of OpenCV. They are obsolete and
00045    are likely to be removed in future. To check whether your code
00046    uses any of these, define CV_NO_BACKWARD_COMPATIBILITY before
00047    including cv.h.
00048 */
00049 
00050 #ifndef __OPENCV_COMPATIBILITY_H__
00051 #define __OPENCV_COMPATIBILITY_H__
00052 
00053 #include <string.h>
00054 
00055 #ifdef __cplusplus
00056     #define CV_UNREFERENCED(arg)
00057 #else
00058     #define CV_UNREFERENCED(arg) arg
00059 #endif
00060 
00061 #define CvMatType int
00062 #define CvDisMaskType int
00063 #define CvMatArray CvMat
00064 
00065 #define CvThreshType int
00066 #define CvAdaptiveThreshMethod int
00067 #define CvCompareMethod int
00068 #define CvFontFace int
00069 #define CvPolyApproxMethod int
00070 #define CvContoursMatchMethod int
00071 #define CvContourTreesMatchMethod int
00072 #define CvCoeffType int
00073 #define CvRodriguesType int
00074 #define CvElementShape int
00075 #define CvMorphOp int
00076 #define CvTemplMatchMethod int
00077 
00078 #define CvPoint2D64d CvPoint2D64f
00079 #define CvPoint3D64d CvPoint3D64f
00080 
00081 #define  CV_MAT32F      CV_32FC1
00082 #define  CV_MAT3x1_32F  CV_32FC1
00083 #define  CV_MAT4x1_32F  CV_32FC1
00084 #define  CV_MAT3x3_32F  CV_32FC1
00085 #define  CV_MAT4x4_32F  CV_32FC1
00086 
00087 #define  CV_MAT64D      CV_64FC1
00088 #define  CV_MAT3x1_64D  CV_64FC1
00089 #define  CV_MAT4x1_64D  CV_64FC1
00090 #define  CV_MAT3x3_64D  CV_64FC1
00091 #define  CV_MAT4x4_64D  CV_64FC1
00092 
00093 #define  IPL_GAUSSIAN_5x5   7
00094 #define  CvBox2D32f     CvBox2D
00095 
00096 /* allocation/deallocation macros */
00097 #define cvCreateImageData   cvCreateData
00098 #define cvReleaseImageData  cvReleaseData
00099 #define cvSetImageData      cvSetData
00100 #define cvGetImageRawData   cvGetRawData
00101 
00102 #define cvmAlloc            cvCreateData
00103 #define cvmFree             cvReleaseData
00104 #define cvmAllocArray       cvCreateData
00105 #define cvmFreeArray        cvReleaseData
00106 
00107 #define cvIntegralImage     cvIntegral
00108 #define cvMatchContours     cvMatchShapes
00109 
00110 CV_INLINE CvMat cvMatArray( int rows, int cols, int type,
00111                             int count, void* data CV_DEFAULT(0))
00112 {
00113     return cvMat( rows*count, cols, type, data );
00114 }
00115 
00116 #define cvUpdateMHIByTime  cvUpdateMotionHistory
00117 
00118 #define cvAccMask cvAcc
00119 #define cvSquareAccMask cvSquareAcc
00120 #define cvMultiplyAccMask cvMultiplyAcc
00121 #define cvRunningAvgMask(imgY, imgU, mask, alpha) cvRunningAvg(imgY, imgU, alpha, mask)
00122 
00123 #define cvSetHistThresh  cvSetHistBinRanges
00124 #define cvCalcHistMask(img, mask, hist, doNotClear) cvCalcHist(img, hist, doNotClear, mask)
00125 
00126 CV_INLINE double cvMean( const CvArr* image, const CvArr* mask CV_DEFAULT(0))
00127 {
00128     CvScalar mean = cvAvg( image, mask );
00129     return mean.val[0];
00130 }
00131 
00132 
00133 CV_INLINE double  cvSumPixels( const CvArr* image )
00134 {
00135     CvScalar scalar = cvSum( image );
00136     return scalar.val[0];
00137 }
00138 
00139 CV_INLINE void  cvMean_StdDev( const CvArr* image, double* mean, double* sdv,
00140                                const CvArr* mask CV_DEFAULT(0))
00141 {
00142     CvScalar _mean, _sdv;
00143     cvAvgSdv( image, &_mean, &_sdv, mask );
00144 
00145     if( mean )
00146         *mean = _mean.val[0];
00147 
00148     if( sdv )
00149         *sdv = _sdv.val[0];
00150 }
00151 
00152 
00153 CV_INLINE void cvmPerspectiveProject( const CvMat* mat, const CvArr* src, CvArr* dst )
00154 {
00155     CvMat tsrc, tdst;
00156 
00157     cvReshape( src, &tsrc, 3, 0 );
00158     cvReshape( dst, &tdst, 3, 0 );
00159 
00160     cvPerspectiveTransform( &tsrc, &tdst, mat );
00161 }
00162 
00163 
00164 CV_INLINE void cvFillImage( CvArr* mat, double color )
00165 {
00166     cvSet( mat, cvColorToScalar(color, cvGetElemType(mat)), 0 );
00167 }
00168 
00169 
00170 #define cvCvtPixToPlane cvSplit
00171 #define cvCvtPlaneToPix cvMerge
00172 
00173 typedef struct CvRandState
00174 {
00175     CvRNG     state;    /* RNG state (the current seed and carry)*/
00176     int       disttype; /* distribution type */
00177     CvScalar  param[2]; /* parameters of RNG */
00178 }
00179 CvRandState;
00180 
00181 
00182 /* Changes RNG range while preserving RNG state */
00183 CV_INLINE  void  cvRandSetRange( CvRandState* state, double param1,
00184                                  double param2, int index CV_DEFAULT(-1))
00185 {
00186     if( !state )
00187     {
00188         cvError( CV_StsNullPtr, "cvRandSetRange", "Null pointer to RNG state", "cvcompat.h", 0 );
00189         return;
00190     }
00191 
00192     if( (unsigned)(index + 1) > 4 )
00193     {
00194         cvError( CV_StsOutOfRange, "cvRandSetRange", "index is not in -1..3", "cvcompat.h", 0 );
00195         return;
00196     }
00197 
00198     if( index < 0 )
00199     {
00200         state->param[0].val[0] = state->param[0].val[1] =
00201         state->param[0].val[2] = state->param[0].val[3] = param1;
00202         state->param[1].val[0] = state->param[1].val[1] =
00203         state->param[1].val[2] = state->param[1].val[3] = param2;
00204     }
00205     else
00206     {
00207         state->param[0].val[index] = param1;
00208         state->param[1].val[index] = param2;
00209     }
00210 }
00211 
00212 
00213 CV_INLINE  void  cvRandInit( CvRandState* state, double param1,
00214                              double param2, int seed,
00215                              int disttype CV_DEFAULT(CV_RAND_UNI))
00216 {
00217     if( !state )
00218     {
00219         cvError( CV_StsNullPtr, "cvRandInit", "Null pointer to RNG state", "cvcompat.h", 0 );
00220         return;
00221     }
00222 
00223     if( disttype != CV_RAND_UNI && disttype != CV_RAND_NORMAL )
00224     {
00225         cvError( CV_StsBadFlag, "cvRandInit", "Unknown distribution type", "cvcompat.h", 0 );
00226         return;
00227     }
00228 
00229     state->state = (uint64)(seed ? seed : -1);
00230     state->disttype = disttype;
00231     cvRandSetRange( state, param1, param2, -1 );
00232 }
00233 
00234 
00235 /* Fills array with random numbers */
00236 CV_INLINE void cvRand( CvRandState* state, CvArr* arr )
00237 {
00238     if( !state )
00239     {
00240         cvError( CV_StsNullPtr, "cvRand", "Null pointer to RNG state", "cvcompat.h", 0 );
00241         return;
00242     }
00243     cvRandArr( &state->state, arr, state->disttype, state->param[0], state->param[1] );
00244 }
00245 
00246 #define cvRandNext( _state ) cvRandInt( &(_state)->state )
00247 
00248 CV_INLINE void cvbRand( CvRandState* state, float* dst, int len )
00249 {
00250     CvMat mat = cvMat( 1, len, CV_32F, (void*)dst );
00251     cvRand( state, &mat );
00252 }
00253 
00254 
00255 CV_INLINE void  cvbCartToPolar( const float* y, const float* x,
00256                                 float* magnitude, float* angle, int len )
00257 {
00258     CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
00259     CvMat my = mx;
00260     CvMat mm = mx;
00261     CvMat ma = mx;
00262 
00263     my.data.fl = (float*)y;
00264     mm.data.fl = (float*)magnitude;
00265     ma.data.fl = (float*)angle;
00266 
00267     cvCartToPolar( &mx, &my, &mm, angle ? &ma : NULL, 1 );
00268 }
00269 
00270 
00271 CV_INLINE void  cvbFastArctan( const float* y, const float* x,
00272                                float* angle, int len )
00273 {
00274     CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
00275     CvMat my = mx;
00276     CvMat ma = mx;
00277 
00278     my.data.fl = (float*)y;
00279     ma.data.fl = (float*)angle;
00280 
00281     cvCartToPolar( &mx, &my, NULL, &ma, 1 );
00282 }
00283 
00284 
00285 CV_INLINE  void  cvbSqrt( const float* x, float* y, int len )
00286 {
00287     CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
00288     CvMat my = mx;
00289     my.data.fl = (float*)y;
00290 
00291     cvPow( &mx, &my, 0.5 );
00292 }
00293 
00294 
00295 CV_INLINE  void  cvbInvSqrt( const float* x, float* y, int len )
00296 {
00297     CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
00298     CvMat my = mx;
00299     my.data.fl = (float*)y;
00300 
00301     cvPow( &mx, &my, -0.5 );
00302 }
00303 
00304 
00305 CV_INLINE  void  cvbReciprocal( const float* x, float* y, int len )
00306 {
00307     CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
00308     CvMat my = mx;
00309     my.data.fl = (float*)y;
00310 
00311     cvPow( &mx, &my, -1 );
00312 }
00313 
00314 
00315 CV_INLINE  void  cvbFastExp( const float* x, double* y, int len )
00316 {
00317     CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
00318     CvMat my = cvMat( 1, len, CV_64F, y );
00319     cvExp( &mx, &my );
00320 }
00321 
00322 
00323 CV_INLINE  void  cvbFastLog( const double* x, float* y, int len )
00324 {
00325     CvMat mx = cvMat( 1, len, CV_64F, (void*)x );
00326     CvMat my = cvMat( 1, len, CV_32F, y );
00327     cvLog( &mx, &my );
00328 }
00329 
00330 
00331 CV_INLINE  CvRect  cvContourBoundingRect( void* point_set, int update CV_DEFAULT(0))
00332 {
00333     return cvBoundingRect( point_set, update );
00334 }
00335 
00336 
00337 CV_INLINE double cvPseudoInverse( const CvArr* src, CvArr* dst )
00338 {
00339     return cvInvert( src, dst, CV_SVD );
00340 }
00341 
00342 #define cvPseudoInv cvPseudoInverse
00343 
00344 #define cvContourMoments( contour, moments ) \
00345     cvMoments( contour, moments, 0 )
00346 
00347 #define cvGetPtrAt              cvPtr2D
00348 #define cvGetAt                 cvGet2D
00349 #define cvSetAt(arr,val,y,x)    cvSet2D((arr),(y),(x),(val))
00350 
00351 #define cvMeanMask  cvMean
00352 #define cvMean_StdDevMask(img,mask,mean,sdv) cvMean_StdDev(img,mean,sdv,mask)
00353 
00354 #define cvNormMask(imgA,imgB,mask,normType) cvNorm(imgA,imgB,normType,mask)
00355 
00356 #define cvMinMaxLocMask(img, mask, min_val, max_val, min_loc, max_loc) \
00357         cvMinMaxLoc(img, min_val, max_val, min_loc, max_loc, mask)
00358 
00359 #define cvRemoveMemoryManager  cvSetMemoryManager
00360 
00361 #define cvmSetZero( mat )               cvSetZero( mat )
00362 #define cvmSetIdentity( mat )           cvSetIdentity( mat )
00363 #define cvmAdd( src1, src2, dst )       cvAdd( src1, src2, dst, 0 )
00364 #define cvmSub( src1, src2, dst )       cvSub( src1, src2, dst, 0 )
00365 #define cvmCopy( src, dst )             cvCopy( src, dst, 0 )
00366 #define cvmMul( src1, src2, dst )       cvMatMulAdd( src1, src2, 0, dst )
00367 #define cvmTranspose( src, dst )        cvT( src, dst )
00368 #define cvmInvert( src, dst )           cvInv( src, dst )
00369 #define cvmMahalanobis(vec1, vec2, mat) cvMahalanobis( vec1, vec2, mat )
00370 #define cvmDotProduct( vec1, vec2 )     cvDotProduct( vec1, vec2 )
00371 #define cvmCrossProduct(vec1, vec2,dst) cvCrossProduct( vec1, vec2, dst )
00372 #define cvmTrace( mat )                 (cvTrace( mat )).val[0]
00373 #define cvmMulTransposed( src, dst, order ) cvMulTransposed( src, dst, order )
00374 #define cvmEigenVV( mat, evec, eval, eps)   cvEigenVV( mat, evec, eval, eps )
00375 #define cvmDet( mat )                   cvDet( mat )
00376 #define cvmScale( src, dst, scale )     cvScale( src, dst, scale )
00377 
00378 #define cvCopyImage( src, dst )         cvCopy( src, dst, 0 )
00379 #define cvReleaseMatHeader              cvReleaseMat
00380 
00381 /* Calculates exact convex hull of 2d point set */
00382 CV_INLINE void cvConvexHull( CvPoint* points, int num_points,
00383                              CvRect* CV_UNREFERENCED(bound_rect),
00384                              int orientation, int* hull, int* hullsize )
00385 {
00386     CvMat points1 = cvMat( 1, num_points, CV_32SC2, points );
00387     CvMat hull1 = cvMat( 1, num_points, CV_32SC1, hull );
00388 
00389     cvConvexHull2( &points1, &hull1, orientation, 0 );
00390     *hullsize = hull1.cols;
00391 }
00392 
00393 /* Calculates exact convex hull of 2d point set stored in a sequence */
00394 #define cvContourConvexHull( contour, orientation, storage ) \
00395     cvConvexHull2( contour, storage, orientation )
00396 
00397 /* Calculates approximate convex hull of 2d point set */
00398 #define cvConvexHullApprox( points, num_points, bound_rect, bandwidth,      \
00399                             orientation, hull, hullsize )                   \
00400 cvConvexHull( points, num_points, bound_rect, orientation, hull, hullsize )
00401 
00402 /* Calculates approximate convex hull of 2d point set stored in a sequence */
00403 #define cvContourConvexHullApprox( contour, bandwidth, orientation, storage )   \
00404     cvConvexHull2( contour, storage, orientation )
00405 
00406 
00407 CV_INLINE void cvMinAreaRect( CvPoint* points, int n,
00408                               int CV_UNREFERENCED(left), int CV_UNREFERENCED(bottom),
00409                               int CV_UNREFERENCED(right), int CV_UNREFERENCED(top),
00410                               CvPoint2D32f* anchor,
00411                               CvPoint2D32f* vect1,
00412                               CvPoint2D32f* vect2 )
00413 {
00414     CvMat mat = cvMat( 1, n, CV_32SC2, points );
00415     CvBox2D box = cvMinAreaRect2( &mat, 0 );
00416     CvPoint2D32f pt[4];
00417 
00418     cvBoxPoints( box, pt );
00419     *anchor = pt[0];
00420     vect1->x = pt[1].x - pt[0].x;
00421     vect1->y = pt[1].y - pt[0].y;
00422     vect2->x = pt[3].x - pt[0].x;
00423     vect2->y = pt[3].y - pt[0].y;
00424 
00425     CV_UNREFERENCED( (left, bottom, right, top) );
00426 }
00427 
00428 typedef int CvDisType;
00429 typedef int CvChainApproxMethod;
00430 typedef int CvContourRetrievalMode;
00431 
00432 CV_INLINE  void  cvFitLine3D( CvPoint3D32f* points, int count, int dist,
00433                               void *param, float reps, float aeps, float* line )
00434 {
00435     CvMat mat = cvMat( 1, count, CV_32FC3, points );
00436     float _param = param != NULL ? *(float*)param : 0.f;
00437     assert( dist != CV_DIST_USER );
00438     cvFitLine( &mat, dist, _param, reps, aeps, line );
00439 }
00440 
00441 /* Fits a line into set of 2d points in a robust way (M-estimator technique) */
00442 CV_INLINE  void  cvFitLine2D( CvPoint2D32f* points, int count, int dist,
00443                               void *param, float reps, float aeps, float* line )
00444 {
00445     CvMat mat = cvMat( 1, count, CV_32FC2, points );
00446     float _param = param != NULL ? *(float*)param : 0.f;
00447     assert( dist != CV_DIST_USER );
00448     cvFitLine( &mat, dist, _param, reps, aeps, line );
00449 }
00450 
00451 
00452 CV_INLINE  void cvFitEllipse( const CvPoint2D32f* points, int count, CvBox2D* box )
00453 {
00454     CvMat mat = cvMat( 1, count, CV_32FC2, (void*)points );
00455     *box = cvFitEllipse2( &mat );
00456 }
00457 
00458 /* Projects 2d points to one of standard coordinate planes
00459    (i.e. removes one of coordinates) */
00460 CV_INLINE  void  cvProject3D( CvPoint3D32f* points3D, int count,
00461                               CvPoint2D32f* points2D,
00462                               int xIndx CV_DEFAULT(0),
00463                               int yIndx CV_DEFAULT(1))
00464 {
00465     CvMat src = cvMat( 1, count, CV_32FC3, points3D );
00466     CvMat dst = cvMat( 1, count, CV_32FC2, points2D );
00467     float m[6] = {0,0,0,0,0,0};
00468     CvMat M = cvMat( 2, 3, CV_32F, m );
00469 
00470     assert( (unsigned)xIndx < 3 && (unsigned)yIndx < 3 );
00471     m[xIndx] = m[yIndx+3] = 1.f;
00472 
00473     cvTransform( &src, &dst, &M, NULL );
00474 }
00475 
00476 
00477 /* Retrieves value of the particular bin
00478    of x-dimensional (x=1,2,3,...) histogram */
00479 #define cvQueryHistValue_1D( hist, idx0 ) \
00480     ((float)cvGetReal1D( (hist)->bins, (idx0)))
00481 #define cvQueryHistValue_2D( hist, idx0, idx1 ) \
00482     ((float)cvGetReal2D( (hist)->bins, (idx0), (idx1)))
00483 #define cvQueryHistValue_3D( hist, idx0, idx1, idx2 ) \
00484     ((float)cvGetReal3D( (hist)->bins, (idx0), (idx1), (idx2)))
00485 #define cvQueryHistValue_nD( hist, idx ) \
00486     ((float)cvGetRealND( (hist)->bins, (idx)))
00487 
00488 /* Returns pointer to the particular bin of x-dimesional histogram.
00489    For sparse histogram the bin is created if it didn't exist before */
00490 #define cvGetHistValue_1D( hist, idx0 ) \
00491     ((float*)cvPtr1D( (hist)->bins, (idx0), 0))
00492 #define cvGetHistValue_2D( hist, idx0, idx1 ) \
00493     ((float*)cvPtr2D( (hist)->bins, (idx0), (idx1), 0))
00494 #define cvGetHistValue_3D( hist, idx0, idx1, idx2 ) \
00495     ((float*)cvPtr3D( (hist)->bins, (idx0), (idx1), (idx2), 0))
00496 #define cvGetHistValue_nD( hist, idx ) \
00497     ((float*)cvPtrND( (hist)->bins, (idx), 0))
00498 
00499 
00500 #define CV_IS_SET_ELEM_EXISTS CV_IS_SET_ELEM
00501 
00502 
00503 CV_INLINE  int  cvHoughLines( CvArr* image, double rho,
00504                               double theta, int threshold,
00505                               float* lines, int linesNumber )
00506 {
00507     CvMat linesMat = cvMat( 1, linesNumber, CV_32FC2, lines );
00508     cvHoughLines2( image, &linesMat, CV_HOUGH_STANDARD,
00509                    rho, theta, threshold, 0, 0 );
00510 
00511     return linesMat.cols;
00512 }
00513 
00514 
00515 CV_INLINE  int  cvHoughLinesP( CvArr* image, double rho,
00516                                double theta, int threshold,
00517                                int lineLength, int lineGap,
00518                                int* lines, int linesNumber )
00519 {
00520     CvMat linesMat = cvMat( 1, linesNumber, CV_32SC4, lines );
00521     cvHoughLines2( image, &linesMat, CV_HOUGH_PROBABILISTIC,
00522                    rho, theta, threshold, lineLength, lineGap );
00523 
00524     return linesMat.cols;
00525 }
00526 
00527 
00528 CV_INLINE  int  cvHoughLinesSDiv( CvArr* image, double rho, int srn,
00529                                   double theta, int stn, int threshold,
00530                                   float* lines, int linesNumber )
00531 {
00532     CvMat linesMat = cvMat( 1, linesNumber, CV_32FC2, lines );
00533     cvHoughLines2( image, &linesMat, CV_HOUGH_MULTI_SCALE,
00534                    rho, theta, threshold, srn, stn );
00535 
00536     return linesMat.cols;
00537 }
00538 
00539 
00540 /* Find fundamental matrix */
00541 CV_INLINE  void  cvFindFundamentalMatrix( int* points1, int* points2,
00542                             int numpoints, int CV_UNREFERENCED(method), float* matrix )
00543 {
00544     CvMat* pointsMat1;
00545     CvMat* pointsMat2;
00546     CvMat fundMatr = cvMat(3,3,CV_32F,matrix);
00547     int i, curr = 0;
00548 
00549     pointsMat1 = cvCreateMat(3,numpoints,CV_64F);
00550     pointsMat2 = cvCreateMat(3,numpoints,CV_64F);
00551 
00552     for( i = 0; i < numpoints; i++ )
00553     {
00554         cvmSet(pointsMat1,0,i,points1[curr]);//x
00555         cvmSet(pointsMat1,1,i,points1[curr+1]);//y
00556         cvmSet(pointsMat1,2,i,1.0);
00557 
00558         cvmSet(pointsMat2,0,i,points2[curr]);//x
00559         cvmSet(pointsMat2,1,i,points2[curr+1]);//y
00560         cvmSet(pointsMat2,2,i,1.0);
00561         curr += 2;
00562     }
00563 
00564     cvFindFundamentalMat(pointsMat1,pointsMat2,&fundMatr,CV_FM_RANSAC,1,0.99,0);
00565 
00566     cvReleaseMat(&pointsMat1);
00567     cvReleaseMat(&pointsMat2);
00568 }
00569 
00570 
00571 
00572 CV_INLINE int
00573 cvFindChessBoardCornerGuesses( const void* arr, void* CV_UNREFERENCED(thresharr),
00574                                CvMemStorage * CV_UNREFERENCED(storage),
00575                                CvSize pattern_size, CvPoint2D32f * corners,
00576                                int *corner_count )
00577 {
00578     return cvFindChessboardCorners( arr, pattern_size, corners,
00579                                     corner_count, CV_CALIB_CB_ADAPTIVE_THRESH );
00580 }
00581 
00582 
00583 /* Calibrates camera using multiple views of calibration pattern */
00584 CV_INLINE void cvCalibrateCamera( int image_count, int* _point_counts,
00585     CvSize image_size, CvPoint2D32f* _image_points, CvPoint3D32f* _object_points,
00586     float* _distortion_coeffs, float* _camera_matrix, float* _translation_vectors,
00587     float* _rotation_matrices, int flags )
00588 {
00589     int i, total = 0;
00590     CvMat point_counts = cvMat( image_count, 1, CV_32SC1, _point_counts );
00591     CvMat image_points, object_points;
00592     CvMat dist_coeffs = cvMat( 4, 1, CV_32FC1, _distortion_coeffs );
00593     CvMat camera_matrix = cvMat( 3, 3, CV_32FC1, _camera_matrix );
00594     CvMat rotation_matrices = cvMat( image_count, 9, CV_32FC1, _rotation_matrices );
00595     CvMat translation_vectors = cvMat( image_count, 3, CV_32FC1, _translation_vectors );
00596 
00597     for( i = 0; i < image_count; i++ )
00598         total += _point_counts[i];
00599 
00600     image_points = cvMat( total, 1, CV_32FC2, _image_points );
00601     object_points = cvMat( total, 1, CV_32FC3, _object_points );
00602 
00603     cvCalibrateCamera2( &object_points, &image_points, &point_counts, image_size,
00604         &camera_matrix, &dist_coeffs, &rotation_matrices, &translation_vectors,
00605         flags );
00606 }
00607 
00608 
00609 CV_INLINE void cvCalibrateCamera_64d( int image_count, int* _point_counts,
00610     CvSize image_size, CvPoint2D64f* _image_points, CvPoint3D64f* _object_points,
00611     double* _distortion_coeffs, double* _camera_matrix, double* _translation_vectors,
00612     double* _rotation_matrices, int flags )
00613 {
00614     int i, total = 0;
00615     CvMat point_counts = cvMat( image_count, 1, CV_32SC1, _point_counts );
00616     CvMat image_points, object_points;
00617     CvMat dist_coeffs = cvMat( 4, 1, CV_64FC1, _distortion_coeffs );
00618     CvMat camera_matrix = cvMat( 3, 3, CV_64FC1, _camera_matrix );
00619     CvMat rotation_matrices = cvMat( image_count, 9, CV_64FC1, _rotation_matrices );
00620     CvMat translation_vectors = cvMat( image_count, 3, CV_64FC1, _translation_vectors );
00621 
00622     for( i = 0; i < image_count; i++ )
00623         total += _point_counts[i];
00624 
00625     image_points = cvMat( total, 1, CV_64FC2, _image_points );
00626     object_points = cvMat( total, 1, CV_64FC3, _object_points );
00627 
00628     cvCalibrateCamera2( &object_points, &image_points, &point_counts, image_size,
00629         &camera_matrix, &dist_coeffs, &rotation_matrices, &translation_vectors,
00630         flags );
00631 }
00632 
00633 
00634 
00635 /* Find 3d position of object given intrinsic camera parameters,
00636    3d model of the object and projection of the object into view plane */
00637 CV_INLINE void cvFindExtrinsicCameraParams( int point_count,
00638     CvSize CV_UNREFERENCED(image_size), CvPoint2D32f* _image_points,
00639     CvPoint3D32f* _object_points, float* focal_length,
00640     CvPoint2D32f principal_point, float* _distortion_coeffs,
00641     float* _rotation_vector, float* _translation_vector )
00642 {
00643     CvMat image_points = cvMat( point_count, 1, CV_32FC2, _image_points );
00644     CvMat object_points = cvMat( point_count, 1, CV_32FC3, _object_points );
00645     CvMat dist_coeffs = cvMat( 4, 1, CV_32FC1, _distortion_coeffs );
00646     float a[9];
00647     CvMat camera_matrix = cvMat( 3, 3, CV_32FC1, a );
00648     CvMat rotation_vector = cvMat( 1, 1, CV_32FC3, _rotation_vector );
00649     CvMat translation_vector = cvMat( 1, 1, CV_32FC3, _translation_vector );
00650 
00651     a[0] = focal_length[0]; a[4] = focal_length[1];
00652     a[2] = principal_point.x; a[5] = principal_point.y;
00653     a[1] = a[3] = a[6] = a[7] = 0.f;
00654     a[8] = 1.f;
00655 
00656     cvFindExtrinsicCameraParams2( &object_points, &image_points, &camera_matrix,
00657         &dist_coeffs, &rotation_vector, &translation_vector, 0 );
00658 }
00659 
00660 
00661 /* Variant of the previous function that takes double-precision parameters */
00662 CV_INLINE void cvFindExtrinsicCameraParams_64d( int point_count,
00663     CvSize CV_UNREFERENCED(image_size), CvPoint2D64f* _image_points,
00664     CvPoint3D64f* _object_points, double* focal_length,
00665     CvPoint2D64f principal_point, double* _distortion_coeffs,
00666     double* _rotation_vector, double* _translation_vector )
00667 {
00668     CvMat image_points = cvMat( point_count, 1, CV_64FC2, _image_points );
00669     CvMat object_points = cvMat( point_count, 1, CV_64FC3, _object_points );
00670     CvMat dist_coeffs = cvMat( 4, 1, CV_64FC1, _distortion_coeffs );
00671     double a[9];
00672     CvMat camera_matrix = cvMat( 3, 3, CV_64FC1, a );
00673     CvMat rotation_vector = cvMat( 1, 1, CV_64FC3, _rotation_vector );
00674     CvMat translation_vector = cvMat( 1, 1, CV_64FC3, _translation_vector );
00675 
00676     a[0] = focal_length[0]; a[4] = focal_length[1];
00677     a[2] = principal_point.x; a[5] = principal_point.y;
00678     a[1] = a[3] = a[6] = a[7] = 0.;
00679     a[8] = 1.;
00680 
00681     cvFindExtrinsicCameraParams2( &object_points, &image_points, &camera_matrix,
00682         &dist_coeffs, &rotation_vector, &translation_vector, 0 );
00683 }
00684 
00685 
00686 /* Rodrigues transform */
00687 #define CV_RODRIGUES_M2V  0
00688 #define CV_RODRIGUES_V2M  1
00689 
00690 /* Converts rotation_matrix matrix to rotation_matrix vector or vice versa */
00691 CV_INLINE void  cvRodrigues( CvMat* rotation_matrix, CvMat* rotation_vector,
00692                              CvMat* jacobian, int conv_type )
00693 {
00694     if( conv_type == CV_RODRIGUES_V2M )
00695         cvRodrigues2( rotation_vector, rotation_matrix, jacobian );
00696     else
00697         cvRodrigues2( rotation_matrix, rotation_vector, jacobian );
00698 }
00699 
00700 
00701 /* Does reprojection of 3d object points to the view plane */
00702 CV_INLINE void  cvProjectPoints( int point_count, CvPoint3D64f* _object_points,
00703     double* _rotation_vector, double*  _translation_vector,
00704     double* focal_length, CvPoint2D64f principal_point,
00705     double* _distortion, CvPoint2D64f* _image_points,
00706     double* _deriv_points_rotation_matrix,
00707     double* _deriv_points_translation_vect,
00708     double* _deriv_points_focal,
00709     double* _deriv_points_principal_point,
00710     double* _deriv_points_distortion_coeffs )
00711 {
00712     CvMat object_points = cvMat( point_count, 1, CV_64FC3, _object_points );
00713     CvMat image_points = cvMat( point_count, 1, CV_64FC2, _image_points );
00714     CvMat rotation_vector = cvMat( 3, 1, CV_64FC1, _rotation_vector );
00715     CvMat translation_vector = cvMat( 3, 1, CV_64FC1, _translation_vector );
00716     double a[9];
00717     CvMat camera_matrix = cvMat( 3, 3, CV_64FC1, a );
00718     CvMat dist_coeffs = cvMat( 4, 1, CV_64FC1, _distortion );
00719     CvMat dpdr = cvMat( 2*point_count, 3, CV_64FC1, _deriv_points_rotation_matrix );
00720     CvMat dpdt = cvMat( 2*point_count, 3, CV_64FC1, _deriv_points_translation_vect );
00721     CvMat dpdf = cvMat( 2*point_count, 2, CV_64FC1, _deriv_points_focal );
00722     CvMat dpdc = cvMat( 2*point_count, 2, CV_64FC1, _deriv_points_principal_point );
00723     CvMat dpdk = cvMat( 2*point_count, 4, CV_64FC1, _deriv_points_distortion_coeffs );
00724 
00725     a[0] = focal_length[0]; a[4] = focal_length[1];
00726     a[2] = principal_point.x; a[5] = principal_point.y;
00727     a[1] = a[3] = a[6] = a[7] = 0.;
00728     a[8] = 1.;
00729 
00730     cvProjectPoints2( &object_points, &rotation_vector, &translation_vector,
00731                       &camera_matrix, &dist_coeffs, &image_points,
00732                       &dpdr, &dpdt, &dpdf, &dpdc, &dpdk, 0 );
00733 }
00734 
00735 
00736 /* Simpler version of the previous function */
00737 CV_INLINE void  cvProjectPointsSimple( int point_count, CvPoint3D64f* _object_points,
00738     double* _rotation_matrix, double*  _translation_vector,
00739     double* _camera_matrix, double* _distortion, CvPoint2D64f* _image_points )
00740 {
00741     CvMat object_points = cvMat( point_count, 1, CV_64FC3, _object_points );
00742     CvMat image_points = cvMat( point_count, 1, CV_64FC2, _image_points );
00743     CvMat rotation_matrix = cvMat( 3, 3, CV_64FC1, _rotation_matrix );
00744     CvMat translation_vector = cvMat( 3, 1, CV_64FC1, _translation_vector );
00745     CvMat camera_matrix = cvMat( 3, 3, CV_64FC1, _camera_matrix );
00746     CvMat dist_coeffs = cvMat( 4, 1, CV_64FC1, _distortion );
00747 
00748     cvProjectPoints2( &object_points, &rotation_matrix, &translation_vector,
00749                       &camera_matrix, &dist_coeffs, &image_points,
00750                       0, 0, 0, 0, 0, 0 );
00751 }
00752 
00753 
00754 CV_INLINE void cvUnDistortOnce( const CvArr* src, CvArr* dst,
00755                                 const float* intrinsic_matrix,
00756                                 const float* distortion_coeffs,
00757                                 int CV_UNREFERENCED(interpolate) )
00758 {
00759     CvMat _a = cvMat( 3, 3, CV_32F, (void*)intrinsic_matrix );
00760     CvMat _k = cvMat( 4, 1, CV_32F, (void*)distortion_coeffs );
00761     cvUndistort2( src, dst, &_a, &_k, 0 );
00762 }
00763 
00764 
00765 /* the two functions below have quite hackerish implementations, use with care
00766    (or, which is better, switch to cvUndistortInitMap and cvRemap instead */
00767 CV_INLINE void cvUnDistortInit( const CvArr* CV_UNREFERENCED(src),
00768                                 CvArr* undistortion_map,
00769                                 const float* A, const float* k,
00770                                 int CV_UNREFERENCED(interpolate) )
00771 {
00772     union { uchar* ptr; float* fl; } data;
00773     CvSize sz;
00774     cvGetRawData( undistortion_map, &data.ptr, 0, &sz );
00775     assert( sz.width >= 8 );
00776     /* just save the intrinsic parameters to the map */
00777     data.fl[0] = A[0]; data.fl[1] = A[4];
00778     data.fl[2] = A[2]; data.fl[3] = A[5];
00779     data.fl[4] = k[0]; data.fl[5] = k[1];
00780     data.fl[6] = k[2]; data.fl[7] = k[3];
00781 }
00782 
00783 CV_INLINE void  cvUnDistort( const CvArr* src, CvArr* dst,
00784                              const CvArr* undistortion_map,
00785                              int CV_UNREFERENCED(interpolate) )
00786 {
00787     union { uchar* ptr; float* fl; } data;
00788     float a[] = {0,0,0,0,0,0,0,0,1};
00789     CvSize sz;
00790     cvGetRawData( undistortion_map, &data.ptr, 0, &sz );
00791     assert( sz.width >= 8 );
00792     a[0] = data.fl[0]; a[4] = data.fl[1];
00793     a[2] = data.fl[2]; a[5] = data.fl[3];
00794     cvUnDistortOnce( src, dst, a, data.fl + 4, 1 );
00795 }
00796 
00797 
00798 CV_INLINE  float  cvCalcEMD( const float* signature1, int size1,
00799                              const float* signature2, int size2,
00800                              int dims, int dist_type CV_DEFAULT(CV_DIST_L2),
00801                              CvDistanceFunction dist_func CV_DEFAULT(0),
00802                              float* lower_bound CV_DEFAULT(0),
00803                              void* user_param CV_DEFAULT(0))
00804 {
00805     CvMat sign1 = cvMat( size1, dims + 1, CV_32FC1, (void*)signature1 );
00806     CvMat sign2 = cvMat( size2, dims + 1, CV_32FC1, (void*)signature2 );
00807 
00808     return cvCalcEMD2( &sign1, &sign2, dist_type, dist_func, 0, 0, lower_bound, user_param );
00809 }
00810 
00811 
00812 CV_INLINE  void  cvKMeans( int num_clusters, float** samples,
00813                            int num_samples, int vec_size,
00814                            CvTermCriteria termcrit, int* cluster_idx )
00815 {
00816     CvMat* samples_mat = cvCreateMat( num_samples, vec_size, CV_32FC1 );
00817     CvMat cluster_idx_mat = cvMat( num_samples, 1, CV_32SC1, cluster_idx );
00818     int i;
00819     for( i = 0; i < num_samples; i++ )
00820         memcpy( samples_mat->data.fl + i*vec_size, samples[i], vec_size*sizeof(float));
00821     cvKMeans2( samples_mat, num_clusters, &cluster_idx_mat, termcrit, 1, 0, 0, 0, 0 );
00822     cvReleaseMat( &samples_mat );
00823 }
00824 
00825 
00826 CV_INLINE void  cvStartScanGraph( CvGraph* graph, CvGraphScanner* scanner,
00827                                   CvGraphVtx* vtx CV_DEFAULT(NULL),
00828                                   int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS))
00829 {
00830     CvGraphScanner* temp_scanner;
00831 
00832     if( !scanner )
00833         cvError( CV_StsNullPtr, "cvStartScanGraph", "Null scanner pointer", "cvcompat.h", 0 );
00834 
00835     temp_scanner = cvCreateGraphScanner( graph, vtx, mask );
00836     *scanner = *temp_scanner;
00837     cvFree( &temp_scanner );
00838 }
00839 
00840 
00841 CV_INLINE  void  cvEndScanGraph( CvGraphScanner* scanner )
00842 {
00843     if( !scanner )
00844         cvError( CV_StsNullPtr, "cvEndScanGraph", "Null scanner pointer", "cvcompat.h", 0 );
00845 
00846     if( scanner->stack )
00847     {
00848         CvGraphScanner* temp_scanner = (CvGraphScanner*)cvAlloc( sizeof(*temp_scanner) );
00849         *temp_scanner = *scanner;
00850         cvReleaseGraphScanner( &temp_scanner );
00851         memset( scanner, 0, sizeof(*scanner) );
00852     }
00853 }
00854 
00855 
00856 #define cvKalmanUpdateByTime  cvKalmanPredict
00857 #define cvKalmanUpdateByMeasurement cvKalmanCorrect
00858 
00859 /* old drawing functions */
00860 CV_INLINE  void  cvLineAA( CvArr* img, CvPoint pt1, CvPoint pt2,
00861                            double color, int scale CV_DEFAULT(0))
00862 {
00863     cvLine( img, pt1, pt2, cvColorToScalar(color, cvGetElemType(img)), 1, CV_AA, scale );
00864 }
00865 
00866 CV_INLINE  void  cvCircleAA( CvArr* img, CvPoint center, int radius,
00867                              double color, int scale CV_DEFAULT(0) )
00868 {
00869     cvCircle( img, center, radius, cvColorToScalar(color, cvGetElemType(img)), 1, CV_AA, scale );
00870 }
00871 
00872 CV_INLINE  void  cvEllipseAA( CvArr* img, CvPoint center, CvSize axes,
00873                               double angle, double start_angle,
00874                               double end_angle, double color,
00875                               int scale CV_DEFAULT(0) )
00876 {
00877     cvEllipse( img, center, axes, angle, start_angle, end_angle,
00878                cvColorToScalar(color, cvGetElemType(img)), 1, CV_AA, scale );
00879 }
00880 
00881 CV_INLINE  void  cvPolyLineAA( CvArr* img, CvPoint** pts, int* npts, int contours,
00882                                int is_closed, double color, int scale CV_DEFAULT(0) )
00883 {
00884     cvPolyLine( img, pts, npts, contours, is_closed,
00885                 cvColorToScalar(color, cvGetElemType(img)),
00886                 1, CV_AA, scale );
00887 }
00888 
00889 
00890 #define cvMake2DPoints cvConvertPointsHomogeneous
00891 #define cvMake3DPoints cvConvertPointsHomogeneous
00892 
00893 #define cvWarpPerspectiveQMatrix cvGetPerspectiveTransform
00894 
00895 #define cvConvertPointsHomogenious cvConvertPointsHomogeneous
00896 
00897 /****************************************************************************************\
00898 *                                   Pixel Access Macros                                  *
00899 \****************************************************************************************/
00900 
00901 typedef struct _CvPixelPosition8u
00902 {
00903     uchar*  currline;      /* pointer to the start of the current pixel line   */
00904     uchar*  topline;       /* pointer to the start of the top pixel line       */
00905     uchar*  bottomline;    /* pointer to the start of the first line           */
00906                                     /* which is below the image                         */
00907     int     x;                      /* current x coordinate ( in pixels )               */
00908     int     width;                  /* width of the image  ( in pixels )                */
00909     int     height;                 /* height of the image  ( in pixels )               */
00910     int     step;                   /* distance between lines ( in elements of single   */
00911                                     /* plane )                                          */
00912     int     step_arr[3];            /* array: ( 0, -step, step ). It is used for        */
00913                                     /* vertical moving                                  */
00914 } CvPixelPosition8u;
00915 
00916 /* this structure differs from the above only in data type */
00917 typedef struct _CvPixelPosition8s
00918 {
00919     schar*  currline;
00920     schar*  topline;
00921     schar*  bottomline;
00922     int     x;
00923     int     width;
00924     int     height;
00925     int     step;
00926     int     step_arr[3];
00927 } CvPixelPosition8s;
00928 
00929 /* this structure differs from the CvPixelPosition8u only in data type */
00930 typedef struct _CvPixelPosition32f
00931 {
00932     float*  currline;
00933     float*  topline;
00934     float*  bottomline;
00935     int     x;
00936     int     width;
00937     int     height;
00938     int     step;
00939     int     step_arr[3];
00940 } CvPixelPosition32f;
00941 
00942 
00943 /* Initialize one of the CvPixelPosition structures.   */
00944 /*  pos    - initialized structure                     */
00945 /*  origin - pointer to the left-top corner of the ROI */
00946 /*  step   - width of the whole image in bytes         */
00947 /*  roi    - width & height of the ROI                 */
00948 /*  x, y   - initial position                          */
00949 #define CV_INIT_PIXEL_POS(pos, origin, _step, roi, _x, _y, orientation)    \
00950     (                                                                        \
00951     (pos).step = (_step)/sizeof((pos).currline[0]) * (orientation ? -1 : 1), \
00952     (pos).width = (roi).width,                                               \
00953     (pos).height = (roi).height,                                             \
00954     (pos).bottomline = (origin) + (pos).step*(pos).height,                   \
00955     (pos).topline = (origin) - (pos).step,                                   \
00956     (pos).step_arr[0] = 0,                                                   \
00957     (pos).step_arr[1] = -(pos).step,                                         \
00958     (pos).step_arr[2] = (pos).step,                                          \
00959     (pos).x = (_x),                                                          \
00960     (pos).currline = (origin) + (pos).step*(_y) )
00961 
00962 
00963 /* Move to specified point ( absolute shift ) */
00964 /*  pos    - position structure               */
00965 /*  x, y   - coordinates of the new position  */
00966 /*  cs     - number of the image channels     */
00967 #define CV_MOVE_TO( pos, _x, _y, cs )                                                   \
00968 ((pos).currline = (_y) >= 0 && (_y) < (pos).height ? (pos).topline + ((_y)+1)*(pos).step : 0, \
00969  (pos).x = (_x) >= 0 && (_x) < (pos).width ? (_x) : 0, (pos).currline + (_x) * (cs) )
00970 
00971 /* Get current coordinates                    */
00972 /*  pos    - position structure               */
00973 /*  x, y   - coordinates of the new position  */
00974 /*  cs     - number of the image channels     */
00975 #define CV_GET_CURRENT( pos, cs )  ((pos).currline + (pos).x * (cs))
00976 
00977 /* Move by one pixel relatively to current position */
00978 /*  pos    - position structure                     */
00979 /*  cs     - number of the image channels           */
00980 
00981 /* left */
00982 #define CV_MOVE_LEFT( pos, cs ) \
00983  ( --(pos).x >= 0 ? (pos).currline + (pos).x*(cs) : 0 )
00984 
00985 /* right */
00986 #define CV_MOVE_RIGHT( pos, cs ) \
00987  ( ++(pos).x < (pos).width ? (pos).currline + (pos).x*(cs) : 0 )
00988 
00989 /* up */
00990 #define CV_MOVE_UP( pos, cs ) \
00991  (((pos).currline -= (pos).step) != (pos).topline ? (pos).currline + (pos).x*(cs) : 0 )
00992 
00993 /* down */
00994 #define CV_MOVE_DOWN( pos, cs ) \
00995  (((pos).currline += (pos).step) != (pos).bottomline ? (pos).currline + (pos).x*(cs) : 0 )
00996 
00997 /* left up */
00998 #define CV_MOVE_LU( pos, cs ) ( CV_MOVE_LEFT(pos, cs), CV_MOVE_UP(pos, cs))
00999 
01000 /* right up */
01001 #define CV_MOVE_RU( pos, cs ) ( CV_MOVE_RIGHT(pos, cs), CV_MOVE_UP(pos, cs))
01002 
01003 /* left down */
01004 #define CV_MOVE_LD( pos, cs ) ( CV_MOVE_LEFT(pos, cs), CV_MOVE_DOWN(pos, cs))
01005 
01006 /* right down */
01007 #define CV_MOVE_RD( pos, cs ) ( CV_MOVE_RIGHT(pos, cs), CV_MOVE_DOWN(pos, cs))
01008 
01009 
01010 
01011 /* Move by one pixel relatively to current position with wrapping when the position     */
01012 /* achieves image boundary                                                              */
01013 /*  pos    - position structure                                                         */
01014 /*  cs     - number of the image channels                                               */
01015 
01016 /* left */
01017 #define CV_MOVE_LEFT_WRAP( pos, cs ) \
01018  ((pos).currline + ( --(pos).x >= 0 ? (pos).x : ((pos).x = (pos).width-1))*(cs))
01019 
01020 /* right */
01021 #define CV_MOVE_RIGHT_WRAP( pos, cs ) \
01022  ((pos).currline + ( ++(pos).x < (pos).width ? (pos).x : ((pos).x = 0))*(cs) )
01023 
01024 /* up */
01025 #define CV_MOVE_UP_WRAP( pos, cs ) \
01026     ((((pos).currline -= (pos).step) != (pos).topline ? \
01027     (pos).currline : ((pos).currline = (pos).bottomline - (pos).step)) + (pos).x*(cs) )
01028 
01029 /* down */
01030 #define CV_MOVE_DOWN_WRAP( pos, cs ) \
01031     ((((pos).currline += (pos).step) != (pos).bottomline ? \
01032     (pos).currline : ((pos).currline = (pos).topline + (pos).step)) + (pos).x*(cs) )
01033 
01034 /* left up */
01035 #define CV_MOVE_LU_WRAP( pos, cs ) ( CV_MOVE_LEFT_WRAP(pos, cs), CV_MOVE_UP_WRAP(pos, cs))
01036 /* right up */
01037 #define CV_MOVE_RU_WRAP( pos, cs ) ( CV_MOVE_RIGHT_WRAP(pos, cs), CV_MOVE_UP_WRAP(pos, cs))
01038 /* left down */
01039 #define CV_MOVE_LD_WRAP( pos, cs ) ( CV_MOVE_LEFT_WRAP(pos, cs), CV_MOVE_DOWN_WRAP(pos, cs))
01040 /* right down */
01041 #define CV_MOVE_RD_WRAP( pos, cs ) ( CV_MOVE_RIGHT_WRAP(pos, cs), CV_MOVE_DOWN_WRAP(pos, cs))
01042 
01043 /* Numeric constants which used for moving in arbitrary direction  */
01044 #define CV_SHIFT_NONE   2
01045 #define CV_SHIFT_LEFT   1
01046 #define CV_SHIFT_RIGHT  3
01047 #define CV_SHIFT_UP     6
01048 #define CV_SHIFT_DOWN  10
01049 #define CV_SHIFT_LU     5
01050 #define CV_SHIFT_RU     7
01051 #define CV_SHIFT_LD     9
01052 #define CV_SHIFT_RD    11
01053 
01054 /* Move by one pixel in specified direction                                     */
01055 /*  pos    - position structure                                                 */
01056 /*  shift  - direction ( it's value must be one of the CV_SHIFT_… constants ) */
01057 /*  cs     - number of the image channels                                       */
01058 #define CV_MOVE_PARAM( pos, shift, cs )                                             \
01059     ( (pos).currline += (pos).step_arr[(shift)>>2], (pos).x += ((shift)&3)-2,       \
01060     ((pos).currline != (pos).topline && (pos).currline != (pos).bottomline &&       \
01061     (pos).x >= 0 && (pos).x < (pos).width) ? (pos).currline + (pos).x*(cs) : 0 )
01062 
01063 /* Move by one pixel in specified direction with wrapping when the               */
01064 /* position achieves image boundary                                              */
01065 /*  pos    - position structure                                                  */
01066 /*  shift  - direction ( it's value must be one of the CV_SHIFT_… constants )  */
01067 /*  cs     - number of the image channels                                        */
01068 #define CV_MOVE_PARAM_WRAP( pos, shift, cs )                                        \
01069     ( (pos).currline += (pos).step_arr[(shift)>>2],                                 \
01070     (pos).currline = ((pos).currline == (pos).topline ?                             \
01071     (pos).bottomline - (pos).step :                                                 \
01072     (pos).currline == (pos).bottomline ?                                            \
01073     (pos).topline + (pos).step : (pos).currline),                                   \
01074                                                                                     \
01075     (pos).x += ((shift)&3)-2,                                                       \
01076     (pos).x = ((pos).x < 0 ? (pos).width-1 : (pos).x >= (pos).width ? 0 : (pos).x), \
01077                                                                                     \
01078     (pos).currline + (pos).x*(cs) )
01079 
01080 #endif