cvcompat.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // Intel License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright( C) 2000, Intel Corporation, all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of Intel Corporation may not be used to endorse or promote products
  27. // derived from this software without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors "as is" and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall the Intel Corporation or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. //(including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort(including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. //M*/
  41. /*
  42. A few macros and definitions for backward compatibility
  43. with the previous versions of OpenCV. They are obsolete and
  44. are likely to be removed in future. To check whether your code
  45. uses any of these, define CV_NO_BACKWARD_COMPATIBILITY before
  46. including cv.h.
  47. */
  48. #ifndef _CVCOMPAT_H_
  49. #define _CVCOMPAT_H_
  50. #include <string.h>
  51. #ifdef __cplusplus
  52. #define CV_UNREFERENCED(arg)
  53. #else
  54. #define CV_UNREFERENCED(arg) arg
  55. #endif
  56. #define CvMatType int
  57. #define CvDisMaskType int
  58. #define CvMatArray CvMat
  59. #define CvThreshType int
  60. #define CvAdaptiveThreshMethod int
  61. #define CvCompareMethod int
  62. #define CvFontFace int
  63. #define CvPolyApproxMethod int
  64. #define CvContoursMatchMethod int
  65. #define CvContourTreesMatchMethod int
  66. #define CvCoeffType int
  67. #define CvRodriguesType int
  68. #define CvElementShape int
  69. #define CvMorphOp int
  70. #define CvTemplMatchMethod int
  71. #define CvPoint2D64d CvPoint2D64f
  72. #define CvPoint3D64d CvPoint3D64f
  73. #define CV_MAT32F CV_32FC1
  74. #define CV_MAT3x1_32F CV_32FC1
  75. #define CV_MAT4x1_32F CV_32FC1
  76. #define CV_MAT3x3_32F CV_32FC1
  77. #define CV_MAT4x4_32F CV_32FC1
  78. #define CV_MAT64D CV_64FC1
  79. #define CV_MAT3x1_64D CV_64FC1
  80. #define CV_MAT4x1_64D CV_64FC1
  81. #define CV_MAT3x3_64D CV_64FC1
  82. #define CV_MAT4x4_64D CV_64FC1
  83. #define IPL_GAUSSIAN_5x5 7
  84. #define CvBox2D32f CvBox2D
  85. /* allocation/deallocation macros */
  86. #define cvCreateImageData cvCreateData
  87. #define cvReleaseImageData cvReleaseData
  88. #define cvSetImageData cvSetData
  89. #define cvGetImageRawData cvGetRawData
  90. #define cvmAlloc cvCreateData
  91. #define cvmFree cvReleaseData
  92. #define cvmAllocArray cvCreateData
  93. #define cvmFreeArray cvReleaseData
  94. #define cvIntegralImage cvIntegral
  95. #define cvMatchContours cvMatchShapes
  96. CV_INLINE CvMat cvMatArray( int rows, int cols, int type,
  97. int count, void* data CV_DEFAULT(0))
  98. {
  99. return cvMat( rows*count, cols, type, data );
  100. }
  101. #define cvUpdateMHIByTime cvUpdateMotionHistory
  102. #define cvAccMask cvAcc
  103. #define cvSquareAccMask cvSquareAcc
  104. #define cvMultiplyAccMask cvMultiplyAcc
  105. #define cvRunningAvgMask(imgY, imgU, mask, alpha) cvRunningAvg(imgY, imgU, alpha, mask)
  106. #define cvSetHistThresh cvSetHistBinRanges
  107. #define cvCalcHistMask(img, mask, hist, doNotClear) cvCalcHist(img, hist, doNotClear, mask)
  108. CV_INLINE double cvMean( const CvArr* image, const CvArr* mask CV_DEFAULT(0))
  109. {
  110. CvScalar mean = cvAvg( image, mask );
  111. return mean.val[0];
  112. }
  113. CV_INLINE double cvSumPixels( const CvArr* image )
  114. {
  115. CvScalar scalar = cvSum( image );
  116. return scalar.val[0];
  117. }
  118. CV_INLINE void cvMean_StdDev( const CvArr* image, double* mean, double* sdv,
  119. const CvArr* mask CV_DEFAULT(0))
  120. {
  121. CvScalar _mean, _sdv;
  122. cvAvgSdv( image, &_mean, &_sdv, mask );
  123. if( mean )
  124. *mean = _mean.val[0];
  125. if( sdv )
  126. *sdv = _sdv.val[0];
  127. }
  128. CV_INLINE void cvmPerspectiveProject( const CvMat* mat, const CvArr* src, CvArr* dst )
  129. {
  130. CvMat tsrc, tdst;
  131. cvReshape( src, &tsrc, 3, 0 );
  132. cvReshape( dst, &tdst, 3, 0 );
  133. cvPerspectiveTransform( &tsrc, &tdst, mat );
  134. }
  135. CV_INLINE void cvFillImage( CvArr* mat, double color )
  136. {
  137. cvSet( mat, cvColorToScalar(color, cvGetElemType(mat)), 0 );
  138. }
  139. #define cvCvtPixToPlane cvSplit
  140. #define cvCvtPlaneToPix cvMerge
  141. typedef struct CvRandState
  142. {
  143. CvRNG state; /* RNG state (the current seed and carry)*/
  144. int disttype; /* distribution type */
  145. CvScalar param[2]; /* parameters of RNG */
  146. }
  147. CvRandState;
  148. /* Changes RNG range while preserving RNG state */
  149. CV_INLINE void cvRandSetRange( CvRandState* state, double param1,
  150. double param2, int index CV_DEFAULT(-1))
  151. {
  152. if( !state )
  153. {
  154. cvError( CV_StsNullPtr, "cvRandSetRange", "Null pointer to RNG state", "cvcompat.h", 0 );
  155. return;
  156. }
  157. if( (unsigned)(index + 1) > 4 )
  158. {
  159. cvError( CV_StsOutOfRange, "cvRandSetRange", "index is not in -1..3", "cvcompat.h", 0 );
  160. return;
  161. }
  162. if( index < 0 )
  163. {
  164. state->param[0].val[0] = state->param[0].val[1] =
  165. state->param[0].val[2] = state->param[0].val[3] = param1;
  166. state->param[1].val[0] = state->param[1].val[1] =
  167. state->param[1].val[2] = state->param[1].val[3] = param2;
  168. }
  169. else
  170. {
  171. state->param[0].val[index] = param1;
  172. state->param[1].val[index] = param2;
  173. }
  174. }
  175. CV_INLINE void cvRandInit( CvRandState* state, double param1,
  176. double param2, int seed,
  177. int disttype CV_DEFAULT(CV_RAND_UNI))
  178. {
  179. if( !state )
  180. {
  181. cvError( CV_StsNullPtr, "cvRandInit", "Null pointer to RNG state", "cvcompat.h", 0 );
  182. return;
  183. }
  184. if( disttype != CV_RAND_UNI && disttype != CV_RAND_NORMAL )
  185. {
  186. cvError( CV_StsBadFlag, "cvRandInit", "Unknown distribution type", "cvcompat.h", 0 );
  187. return;
  188. }
  189. state->state = (uint64)(seed ? seed : -1);
  190. state->disttype = disttype;
  191. cvRandSetRange( state, param1, param2, -1 );
  192. }
  193. /* Fills array with random numbers */
  194. CV_INLINE void cvRand( CvRandState* state, CvArr* arr )
  195. {
  196. if( !state )
  197. {
  198. cvError( CV_StsNullPtr, "cvRand", "Null pointer to RNG state", "cvcompat.h", 0 );
  199. return;
  200. }
  201. cvRandArr( &state->state, arr, state->disttype, state->param[0], state->param[1] );
  202. }
  203. #define cvRandNext( _state ) cvRandInt( &(_state)->state )
  204. CV_INLINE void cvbRand( CvRandState* state, float* dst, int len )
  205. {
  206. CvMat mat = cvMat( 1, len, CV_32F, (void*)dst );
  207. cvRand( state, &mat );
  208. }
  209. CV_INLINE void cvbCartToPolar( const float* y, const float* x,
  210. float* magnitude, float* angle, int len )
  211. {
  212. CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
  213. CvMat my = mx;
  214. CvMat mm = mx;
  215. CvMat ma = mx;
  216. my.data.fl = (float*)y;
  217. mm.data.fl = (float*)magnitude;
  218. ma.data.fl = (float*)angle;
  219. cvCartToPolar( &mx, &my, &mm, angle ? &ma : NULL, 1 );
  220. }
  221. CV_INLINE void cvbFastArctan( const float* y, const float* x,
  222. float* angle, int len )
  223. {
  224. CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
  225. CvMat my = mx;
  226. CvMat ma = mx;
  227. my.data.fl = (float*)y;
  228. ma.data.fl = (float*)angle;
  229. cvCartToPolar( &mx, &my, NULL, &ma, 1 );
  230. }
  231. CV_INLINE void cvbSqrt( const float* x, float* y, int len )
  232. {
  233. CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
  234. CvMat my = mx;
  235. my.data.fl = (float*)y;
  236. cvPow( &mx, &my, 0.5 );
  237. }
  238. CV_INLINE void cvbInvSqrt( const float* x, float* y, int len )
  239. {
  240. CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
  241. CvMat my = mx;
  242. my.data.fl = (float*)y;
  243. cvPow( &mx, &my, -0.5 );
  244. }
  245. CV_INLINE void cvbReciprocal( const float* x, float* y, int len )
  246. {
  247. CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
  248. CvMat my = mx;
  249. my.data.fl = (float*)y;
  250. cvPow( &mx, &my, -1 );
  251. }
  252. CV_INLINE void cvbFastExp( const float* x, double* y, int len )
  253. {
  254. CvMat mx = cvMat( 1, len, CV_32F, (void*)x );
  255. CvMat my = cvMat( 1, len, CV_64F, y );
  256. cvExp( &mx, &my );
  257. }
  258. CV_INLINE void cvbFastLog( const double* x, float* y, int len )
  259. {
  260. CvMat mx = cvMat( 1, len, CV_64F, (void*)x );
  261. CvMat my = cvMat( 1, len, CV_32F, y );
  262. cvLog( &mx, &my );
  263. }
  264. CV_INLINE CvRect cvContourBoundingRect( void* point_set, int update CV_DEFAULT(0))
  265. {
  266. return cvBoundingRect( point_set, update );
  267. }
  268. CV_INLINE double cvPseudoInverse( const CvArr* src, CvArr* dst )
  269. {
  270. return cvInvert( src, dst, CV_SVD );
  271. }
  272. #define cvPseudoInv cvPseudoInverse
  273. #define cvContourMoments( contour, moments ) \
  274. cvMoments( contour, moments, 0 )
  275. #define cvGetPtrAt cvPtr2D
  276. #define cvGetAt cvGet2D
  277. #define cvSetAt(arr,val,y,x) cvSet2D((arr),(y),(x),(val))
  278. #define cvMeanMask cvMean
  279. #define cvMean_StdDevMask(img,mask,mean,sdv) cvMean_StdDev(img,mean,sdv,mask)
  280. #define cvNormMask(imgA,imgB,mask,normType) cvNorm(imgA,imgB,normType,mask)
  281. #define cvMinMaxLocMask(img, mask, min_val, max_val, min_loc, max_loc) \
  282. cvMinMaxLoc(img, min_val, max_val, min_loc, max_loc, mask)
  283. #define cvRemoveMemoryManager cvSetMemoryManager
  284. #define cvmSetZero( mat ) cvSetZero( mat )
  285. #define cvmSetIdentity( mat ) cvSetIdentity( mat )
  286. #define cvmAdd( src1, src2, dst ) cvAdd( src1, src2, dst, 0 )
  287. #define cvmSub( src1, src2, dst ) cvSub( src1, src2, dst, 0 )
  288. #define cvmCopy( src, dst ) cvCopy( src, dst, 0 )
  289. #define cvmMul( src1, src2, dst ) cvMatMulAdd( src1, src2, 0, dst )
  290. #define cvmTranspose( src, dst ) cvT( src, dst )
  291. #define cvmInvert( src, dst ) cvInv( src, dst )
  292. #define cvmMahalanobis(vec1, vec2, mat) cvMahalanobis( vec1, vec2, mat )
  293. #define cvmDotProduct( vec1, vec2 ) cvDotProduct( vec1, vec2 )
  294. #define cvmCrossProduct(vec1, vec2,dst) cvCrossProduct( vec1, vec2, dst )
  295. #define cvmTrace( mat ) (cvTrace( mat )).val[0]
  296. #define cvmMulTransposed( src, dst, order ) cvMulTransposed( src, dst, order )
  297. #define cvmEigenVV( mat, evec, eval, eps) cvEigenVV( mat, evec, eval, eps )
  298. #define cvmDet( mat ) cvDet( mat )
  299. #define cvmScale( src, dst, scale ) cvScale( src, dst, scale )
  300. #define cvCopyImage( src, dst ) cvCopy( src, dst, 0 )
  301. #define cvReleaseMatHeader cvReleaseMat
  302. /* Calculates exact convex hull of 2d point set */
  303. CV_INLINE void cvConvexHull( CvPoint* points, int num_points,
  304. CvRect* CV_UNREFERENCED(bound_rect),
  305. int orientation, int* hull, int* hullsize )
  306. {
  307. CvMat points1 = cvMat( 1, num_points, CV_32SC2, points );
  308. CvMat hull1 = cvMat( 1, num_points, CV_32SC1, hull );
  309. cvConvexHull2( &points1, &hull1, orientation, 0 );
  310. *hullsize = hull1.cols;
  311. }
  312. /* Calculates exact convex hull of 2d point set stored in a sequence */
  313. #define cvContourConvexHull( contour, orientation, storage ) \
  314. cvConvexHull2( contour, storage, orientation )
  315. /* Calculates approximate convex hull of 2d point set */
  316. #define cvConvexHullApprox( points, num_points, bound_rect, bandwidth, \
  317. orientation, hull, hullsize ) \
  318. cvConvexHull( points, num_points, bound_rect, orientation, hull, hullsize )
  319. /* Calculates approximate convex hull of 2d point set stored in a sequence */
  320. #define cvContourConvexHullApprox( contour, bandwidth, orientation, storage ) \
  321. cvConvexHull2( contour, storage, orientation )
  322. CV_INLINE void cvMinAreaRect( CvPoint* points, int n,
  323. int CV_UNREFERENCED(left), int CV_UNREFERENCED(bottom),
  324. int CV_UNREFERENCED(right), int CV_UNREFERENCED(top),
  325. CvPoint2D32f* anchor,
  326. CvPoint2D32f* vect1,
  327. CvPoint2D32f* vect2 )
  328. {
  329. CvMat mat = cvMat( 1, n, CV_32SC2, points );
  330. CvBox2D box = cvMinAreaRect2( &mat, 0 );
  331. CvPoint2D32f pt[4];
  332. cvBoxPoints( box, pt );
  333. *anchor = pt[0];
  334. vect1->x = pt[1].x - pt[0].x;
  335. vect1->y = pt[1].y - pt[0].y;
  336. vect2->x = pt[3].x - pt[0].x;
  337. vect2->y = pt[3].y - pt[0].y;
  338. CV_UNREFERENCED( (left, bottom, right, top) );
  339. }
  340. typedef int CvDisType;
  341. typedef int CvChainApproxMethod;
  342. typedef int CvContourRetrievalMode;
  343. CV_INLINE void cvFitLine3D( CvPoint3D32f* points, int count, int dist,
  344. void *param, float reps, float aeps, float* line )
  345. {
  346. CvMat mat = cvMat( 1, count, CV_32FC3, points );
  347. float _param = param != NULL ? *(float*)param : 0.f;
  348. assert( dist != CV_DIST_USER );
  349. cvFitLine( &mat, dist, _param, reps, aeps, line );
  350. }
  351. /* Fits a line into set of 2d points in a robust way (M-estimator technique) */
  352. CV_INLINE void cvFitLine2D( CvPoint2D32f* points, int count, int dist,
  353. void *param, float reps, float aeps, float* line )
  354. {
  355. CvMat mat = cvMat( 1, count, CV_32FC2, points );
  356. float _param = param != NULL ? *(float*)param : 0.f;
  357. assert( dist != CV_DIST_USER );
  358. cvFitLine( &mat, dist, _param, reps, aeps, line );
  359. }
  360. CV_INLINE void cvFitEllipse( const CvPoint2D32f* points, int count, CvBox2D* box )
  361. {
  362. CvMat mat = cvMat( 1, count, CV_32FC2, (void*)points );
  363. *box = cvFitEllipse2( &mat );
  364. }
  365. /* Projects 2d points to one of standard coordinate planes
  366. (i.e. removes one of coordinates) */
  367. CV_INLINE void cvProject3D( CvPoint3D32f* points3D, int count,
  368. CvPoint2D32f* points2D,
  369. int xIndx CV_DEFAULT(0),
  370. int yIndx CV_DEFAULT(1))
  371. {
  372. CvMat src = cvMat( 1, count, CV_32FC3, points3D );
  373. CvMat dst = cvMat( 1, count, CV_32FC2, points2D );
  374. float m[6] = {0,0,0,0,0,0};
  375. CvMat M = cvMat( 2, 3, CV_32F, m );
  376. assert( (unsigned)xIndx < 3 && (unsigned)yIndx < 3 );
  377. m[xIndx] = m[yIndx+3] = 1.f;
  378. cvTransform( &src, &dst, &M, NULL );
  379. }
  380. /* Retrieves value of the particular bin
  381. of x-dimensional (x=1,2,3,...) histogram */
  382. #define cvQueryHistValue_1D( hist, idx0 ) \
  383. ((float)cvGetReal1D( (hist)->bins, (idx0)))
  384. #define cvQueryHistValue_2D( hist, idx0, idx1 ) \
  385. ((float)cvGetReal2D( (hist)->bins, (idx0), (idx1)))
  386. #define cvQueryHistValue_3D( hist, idx0, idx1, idx2 ) \
  387. ((float)cvGetReal3D( (hist)->bins, (idx0), (idx1), (idx2)))
  388. #define cvQueryHistValue_nD( hist, idx ) \
  389. ((float)cvGetRealND( (hist)->bins, (idx)))
  390. /* Returns pointer to the particular bin of x-dimesional histogram.
  391. For sparse histogram the bin is created if it didn't exist before */
  392. #define cvGetHistValue_1D( hist, idx0 ) \
  393. ((float*)cvPtr1D( (hist)->bins, (idx0), 0))
  394. #define cvGetHistValue_2D( hist, idx0, idx1 ) \
  395. ((float*)cvPtr2D( (hist)->bins, (idx0), (idx1), 0))
  396. #define cvGetHistValue_3D( hist, idx0, idx1, idx2 ) \
  397. ((float*)cvPtr3D( (hist)->bins, (idx0), (idx1), (idx2), 0))
  398. #define cvGetHistValue_nD( hist, idx ) \
  399. ((float*)cvPtrND( (hist)->bins, (idx), 0))
  400. #define CV_IS_SET_ELEM_EXISTS CV_IS_SET_ELEM
  401. CV_INLINE int cvHoughLines( CvArr* image, double rho,
  402. double theta, int threshold,
  403. float* lines, int linesNumber )
  404. {
  405. CvMat linesMat = cvMat( 1, linesNumber, CV_32FC2, lines );
  406. cvHoughLines2( image, &linesMat, CV_HOUGH_STANDARD,
  407. rho, theta, threshold, 0, 0 );
  408. return linesMat.cols;
  409. }
  410. CV_INLINE int cvHoughLinesP( CvArr* image, double rho,
  411. double theta, int threshold,
  412. int lineLength, int lineGap,
  413. int* lines, int linesNumber )
  414. {
  415. CvMat linesMat = cvMat( 1, linesNumber, CV_32SC4, lines );
  416. cvHoughLines2( image, &linesMat, CV_HOUGH_PROBABILISTIC,
  417. rho, theta, threshold, lineLength, lineGap );
  418. return linesMat.cols;
  419. }
  420. CV_INLINE int cvHoughLinesSDiv( CvArr* image, double rho, int srn,
  421. double theta, int stn, int threshold,
  422. float* lines, int linesNumber )
  423. {
  424. CvMat linesMat = cvMat( 1, linesNumber, CV_32FC2, lines );
  425. cvHoughLines2( image, &linesMat, CV_HOUGH_MULTI_SCALE,
  426. rho, theta, threshold, srn, stn );
  427. return linesMat.cols;
  428. }
  429. /* Find fundamental matrix */
  430. CV_INLINE void cvFindFundamentalMatrix( int* points1, int* points2,
  431. int numpoints, int CV_UNREFERENCED(method), float* matrix )
  432. {
  433. CvMat* pointsMat1;
  434. CvMat* pointsMat2;
  435. CvMat fundMatr = cvMat(3,3,CV_32F,matrix);
  436. int i, curr = 0;
  437. pointsMat1 = cvCreateMat(3,numpoints,CV_64F);
  438. pointsMat2 = cvCreateMat(3,numpoints,CV_64F);
  439. for( i = 0; i < numpoints; i++ )
  440. {
  441. cvmSet(pointsMat1,0,i,points1[curr]);//x
  442. cvmSet(pointsMat1,1,i,points1[curr+1]);//y
  443. cvmSet(pointsMat1,2,i,1.0);
  444. cvmSet(pointsMat2,0,i,points2[curr]);//x
  445. cvmSet(pointsMat2,1,i,points2[curr+1]);//y
  446. cvmSet(pointsMat2,2,i,1.0);
  447. curr += 2;
  448. }
  449. cvFindFundamentalMat(pointsMat1,pointsMat2,&fundMatr,CV_FM_RANSAC,1,0.99,0);
  450. cvReleaseMat(&pointsMat1);
  451. cvReleaseMat(&pointsMat2);
  452. }
  453. CV_INLINE int
  454. cvFindChessBoardCornerGuesses( const void* arr, void* CV_UNREFERENCED(thresharr),
  455. CvMemStorage * CV_UNREFERENCED(storage),
  456. CvSize pattern_size, CvPoint2D32f * corners,
  457. int *corner_count )
  458. {
  459. return cvFindChessboardCorners( arr, pattern_size, corners,
  460. corner_count, CV_CALIB_CB_ADAPTIVE_THRESH );
  461. }
  462. /* Calibrates camera using multiple views of calibration pattern */
  463. CV_INLINE void cvCalibrateCamera( int image_count, int* _point_counts,
  464. CvSize image_size, CvPoint2D32f* _image_points, CvPoint3D32f* _object_points,
  465. float* _distortion_coeffs, float* _camera_matrix, float* _translation_vectors,
  466. float* _rotation_matrices, int flags )
  467. {
  468. int i, total = 0;
  469. CvMat point_counts = cvMat( image_count, 1, CV_32SC1, _point_counts );
  470. CvMat image_points, object_points;
  471. CvMat dist_coeffs = cvMat( 4, 1, CV_32FC1, _distortion_coeffs );
  472. CvMat camera_matrix = cvMat( 3, 3, CV_32FC1, _camera_matrix );
  473. CvMat rotation_matrices = cvMat( image_count, 9, CV_32FC1, _rotation_matrices );
  474. CvMat translation_vectors = cvMat( image_count, 3, CV_32FC1, _translation_vectors );
  475. for( i = 0; i < image_count; i++ )
  476. total += _point_counts[i];
  477. image_points = cvMat( total, 1, CV_32FC2, _image_points );
  478. object_points = cvMat( total, 1, CV_32FC3, _object_points );
  479. cvCalibrateCamera2( &object_points, &image_points, &point_counts, image_size,
  480. &camera_matrix, &dist_coeffs, &rotation_matrices, &translation_vectors,
  481. flags );
  482. }
  483. CV_INLINE void cvCalibrateCamera_64d( int image_count, int* _point_counts,
  484. CvSize image_size, CvPoint2D64f* _image_points, CvPoint3D64f* _object_points,
  485. double* _distortion_coeffs, double* _camera_matrix, double* _translation_vectors,
  486. double* _rotation_matrices, int flags )
  487. {
  488. int i, total = 0;
  489. CvMat point_counts = cvMat( image_count, 1, CV_32SC1, _point_counts );
  490. CvMat image_points, object_points;
  491. CvMat dist_coeffs = cvMat( 4, 1, CV_64FC1, _distortion_coeffs );
  492. CvMat camera_matrix = cvMat( 3, 3, CV_64FC1, _camera_matrix );
  493. CvMat rotation_matrices = cvMat( image_count, 9, CV_64FC1, _rotation_matrices );
  494. CvMat translation_vectors = cvMat( image_count, 3, CV_64FC1, _translation_vectors );
  495. for( i = 0; i < image_count; i++ )
  496. total += _point_counts[i];
  497. image_points = cvMat( total, 1, CV_64FC2, _image_points );
  498. object_points = cvMat( total, 1, CV_64FC3, _object_points );
  499. cvCalibrateCamera2( &object_points, &image_points, &point_counts, image_size,
  500. &camera_matrix, &dist_coeffs, &rotation_matrices, &translation_vectors,
  501. flags );
  502. }
  503. /* Find 3d position of object given intrinsic camera parameters,
  504. 3d model of the object and projection of the object into view plane */
  505. CV_INLINE void cvFindExtrinsicCameraParams( int point_count,
  506. CvSize CV_UNREFERENCED(image_size), CvPoint2D32f* _image_points,
  507. CvPoint3D32f* _object_points, float* focal_length,
  508. CvPoint2D32f principal_point, float* _distortion_coeffs,
  509. float* _rotation_vector, float* _translation_vector )
  510. {
  511. CvMat image_points = cvMat( point_count, 1, CV_32FC2, _image_points );
  512. CvMat object_points = cvMat( point_count, 1, CV_32FC3, _object_points );
  513. CvMat dist_coeffs = cvMat( 4, 1, CV_32FC1, _distortion_coeffs );
  514. float a[9];
  515. CvMat camera_matrix = cvMat( 3, 3, CV_32FC1, a );
  516. CvMat rotation_vector = cvMat( 1, 1, CV_32FC3, _rotation_vector );
  517. CvMat translation_vector = cvMat( 1, 1, CV_32FC3, _translation_vector );
  518. a[0] = focal_length[0]; a[4] = focal_length[1];
  519. a[2] = principal_point.x; a[5] = principal_point.y;
  520. a[1] = a[3] = a[6] = a[7] = 0.f;
  521. a[8] = 1.f;
  522. cvFindExtrinsicCameraParams2( &object_points, &image_points, &camera_matrix,
  523. &dist_coeffs, &rotation_vector, &translation_vector );
  524. }
  525. /* Variant of the previous function that takes double-precision parameters */
  526. CV_INLINE void cvFindExtrinsicCameraParams_64d( int point_count,
  527. CvSize CV_UNREFERENCED(image_size), CvPoint2D64f* _image_points,
  528. CvPoint3D64f* _object_points, double* focal_length,
  529. CvPoint2D64f principal_point, double* _distortion_coeffs,
  530. double* _rotation_vector, double* _translation_vector )
  531. {
  532. CvMat image_points = cvMat( point_count, 1, CV_64FC2, _image_points );
  533. CvMat object_points = cvMat( point_count, 1, CV_64FC3, _object_points );
  534. CvMat dist_coeffs = cvMat( 4, 1, CV_64FC1, _distortion_coeffs );
  535. double a[9];
  536. CvMat camera_matrix = cvMat( 3, 3, CV_64FC1, a );
  537. CvMat rotation_vector = cvMat( 1, 1, CV_64FC3, _rotation_vector );
  538. CvMat translation_vector = cvMat( 1, 1, CV_64FC3, _translation_vector );
  539. a[0] = focal_length[0]; a[4] = focal_length[1];
  540. a[2] = principal_point.x; a[5] = principal_point.y;
  541. a[1] = a[3] = a[6] = a[7] = 0.;
  542. a[8] = 1.;
  543. cvFindExtrinsicCameraParams2( &object_points, &image_points, &camera_matrix,
  544. &dist_coeffs, &rotation_vector, &translation_vector );
  545. }
  546. /* Rodrigues transform */
  547. #define CV_RODRIGUES_M2V 0
  548. #define CV_RODRIGUES_V2M 1
  549. /* Converts rotation_matrix matrix to rotation_matrix vector or vice versa */
  550. CV_INLINE void cvRodrigues( CvMat* rotation_matrix, CvMat* rotation_vector,
  551. CvMat* jacobian, int conv_type )
  552. {
  553. if( conv_type == CV_RODRIGUES_V2M )
  554. cvRodrigues2( rotation_vector, rotation_matrix, jacobian );
  555. else
  556. cvRodrigues2( rotation_matrix, rotation_vector, jacobian );
  557. }
  558. /* Does reprojection of 3d object points to the view plane */
  559. CV_INLINE void cvProjectPoints( int point_count, CvPoint3D64f* _object_points,
  560. double* _rotation_vector, double* _translation_vector,
  561. double* focal_length, CvPoint2D64f principal_point,
  562. double* _distortion, CvPoint2D64f* _image_points,
  563. double* _deriv_points_rotation_matrix,
  564. double* _deriv_points_translation_vect,
  565. double* _deriv_points_focal,
  566. double* _deriv_points_principal_point,
  567. double* _deriv_points_distortion_coeffs )
  568. {
  569. CvMat object_points = cvMat( point_count, 1, CV_64FC3, _object_points );
  570. CvMat image_points = cvMat( point_count, 1, CV_64FC2, _image_points );
  571. CvMat rotation_vector = cvMat( 3, 1, CV_64FC1, _rotation_vector );
  572. CvMat translation_vector = cvMat( 3, 1, CV_64FC1, _translation_vector );
  573. double a[9];
  574. CvMat camera_matrix = cvMat( 3, 3, CV_64FC1, a );
  575. CvMat dist_coeffs = cvMat( 4, 1, CV_64FC1, _distortion );
  576. CvMat dpdr = cvMat( 2*point_count, 3, CV_64FC1, _deriv_points_rotation_matrix );
  577. CvMat dpdt = cvMat( 2*point_count, 3, CV_64FC1, _deriv_points_translation_vect );
  578. CvMat dpdf = cvMat( 2*point_count, 2, CV_64FC1, _deriv_points_focal );
  579. CvMat dpdc = cvMat( 2*point_count, 2, CV_64FC1, _deriv_points_principal_point );
  580. CvMat dpdk = cvMat( 2*point_count, 4, CV_64FC1, _deriv_points_distortion_coeffs );
  581. a[0] = focal_length[0]; a[4] = focal_length[1];
  582. a[2] = principal_point.x; a[5] = principal_point.y;
  583. a[1] = a[3] = a[6] = a[7] = 0.;
  584. a[8] = 1.;
  585. cvProjectPoints2( &object_points, &rotation_vector, &translation_vector,
  586. &camera_matrix, &dist_coeffs, &image_points,
  587. &dpdr, &dpdt, &dpdf, &dpdc, &dpdk );
  588. }
  589. /* Simpler version of the previous function */
  590. CV_INLINE void cvProjectPointsSimple( int point_count, CvPoint3D64f* _object_points,
  591. double* _rotation_matrix, double* _translation_vector,
  592. double* _camera_matrix, double* _distortion, CvPoint2D64f* _image_points )
  593. {
  594. CvMat object_points = cvMat( point_count, 1, CV_64FC3, _object_points );
  595. CvMat image_points = cvMat( point_count, 1, CV_64FC2, _image_points );
  596. CvMat rotation_matrix = cvMat( 3, 3, CV_64FC1, _rotation_matrix );
  597. CvMat translation_vector = cvMat( 3, 1, CV_64FC1, _translation_vector );
  598. CvMat camera_matrix = cvMat( 3, 3, CV_64FC1, _camera_matrix );
  599. CvMat dist_coeffs = cvMat( 4, 1, CV_64FC1, _distortion );
  600. cvProjectPoints2( &object_points, &rotation_matrix, &translation_vector,
  601. &camera_matrix, &dist_coeffs, &image_points,
  602. 0, 0, 0, 0, 0 );
  603. }
  604. CV_INLINE void cvUnDistortOnce( const CvArr* src, CvArr* dst,
  605. const float* intrinsic_matrix,
  606. const float* distortion_coeffs,
  607. int CV_UNREFERENCED(interpolate) )
  608. {
  609. CvMat _a = cvMat( 3, 3, CV_32F, (void*)intrinsic_matrix );
  610. CvMat _k = cvMat( 4, 1, CV_32F, (void*)distortion_coeffs );
  611. cvUndistort2( src, dst, &_a, &_k );
  612. }
  613. /* the two functions below have quite hackerish implementations, use with care
  614. (or, which is better, switch to cvUndistortInitMap and cvRemap instead */
  615. CV_INLINE void cvUnDistortInit( const CvArr* CV_UNREFERENCED(src),
  616. CvArr* undistortion_map,
  617. const float* A, const float* k,
  618. int CV_UNREFERENCED(interpolate) )
  619. {
  620. union { uchar* ptr; float* fl; } data;
  621. CvSize sz;
  622. cvGetRawData( undistortion_map, &data.ptr, 0, &sz );
  623. assert( sz.width >= 8 );
  624. /* just save the intrinsic parameters to the map */
  625. data.fl[0] = A[0]; data.fl[1] = A[4];
  626. data.fl[2] = A[2]; data.fl[3] = A[5];
  627. data.fl[4] = k[0]; data.fl[5] = k[1];
  628. data.fl[6] = k[2]; data.fl[7] = k[3];
  629. }
  630. CV_INLINE void cvUnDistort( const CvArr* src, CvArr* dst,
  631. const CvArr* undistortion_map,
  632. int CV_UNREFERENCED(interpolate) )
  633. {
  634. union { uchar* ptr; float* fl; } data;
  635. float a[] = {0,0,0,0,0,0,0,0,1};
  636. CvSize sz;
  637. cvGetRawData( undistortion_map, &data.ptr, 0, &sz );
  638. assert( sz.width >= 8 );
  639. a[0] = data.fl[0]; a[4] = data.fl[1];
  640. a[2] = data.fl[2]; a[5] = data.fl[3];
  641. cvUnDistortOnce( src, dst, a, data.fl + 4, 1 );
  642. }
  643. CV_INLINE float cvCalcEMD( const float* signature1, int size1,
  644. const float* signature2, int size2,
  645. int dims, int dist_type CV_DEFAULT(CV_DIST_L2),
  646. CvDistanceFunction dist_func CV_DEFAULT(0),
  647. float* lower_bound CV_DEFAULT(0),
  648. void* user_param CV_DEFAULT(0))
  649. {
  650. CvMat sign1 = cvMat( size1, dims + 1, CV_32FC1, (void*)signature1 );
  651. CvMat sign2 = cvMat( size2, dims + 1, CV_32FC1, (void*)signature2 );
  652. return cvCalcEMD2( &sign1, &sign2, dist_type, dist_func, 0, 0, lower_bound, user_param );
  653. }
  654. CV_INLINE void cvKMeans( int num_clusters, float** samples,
  655. int num_samples, int vec_size,
  656. CvTermCriteria termcrit, int* cluster_idx )
  657. {
  658. CvMat* samples_mat = cvCreateMat( num_samples, vec_size, CV_32FC1 );
  659. CvMat cluster_idx_mat = cvMat( num_samples, 1, CV_32SC1, cluster_idx );
  660. int i;
  661. for( i = 0; i < num_samples; i++ )
  662. memcpy( samples_mat->data.fl + i*vec_size, samples[i], vec_size*sizeof(float));
  663. cvKMeans2( samples_mat, num_clusters, &cluster_idx_mat, termcrit );
  664. cvReleaseMat( &samples_mat );
  665. }
  666. CV_INLINE void cvStartScanGraph( CvGraph* graph, CvGraphScanner* scanner,
  667. CvGraphVtx* vtx CV_DEFAULT(NULL),
  668. int mask CV_DEFAULT(CV_GRAPH_ALL_ITEMS))
  669. {
  670. CvGraphScanner* temp_scanner;
  671. if( !scanner )
  672. cvError( CV_StsNullPtr, "cvStartScanGraph", "Null scanner pointer", "cvcompat.h", 0 );
  673. temp_scanner = cvCreateGraphScanner( graph, vtx, mask );
  674. *scanner = *temp_scanner;
  675. cvFree( &temp_scanner );
  676. }
  677. CV_INLINE void cvEndScanGraph( CvGraphScanner* scanner )
  678. {
  679. if( !scanner )
  680. cvError( CV_StsNullPtr, "cvEndScanGraph", "Null scanner pointer", "cvcompat.h", 0 );
  681. if( scanner->stack )
  682. {
  683. CvGraphScanner* temp_scanner = (CvGraphScanner*)cvAlloc( sizeof(*temp_scanner) );
  684. *temp_scanner = *scanner;
  685. cvReleaseGraphScanner( &temp_scanner );
  686. memset( scanner, 0, sizeof(*scanner) );
  687. }
  688. }
  689. #define cvKalmanUpdateByTime cvKalmanPredict
  690. #define cvKalmanUpdateByMeasurement cvKalmanCorrect
  691. /* old drawing functions */
  692. CV_INLINE void cvLineAA( CvArr* img, CvPoint pt1, CvPoint pt2,
  693. double color, int scale CV_DEFAULT(0))
  694. {
  695. cvLine( img, pt1, pt2, cvColorToScalar(color, cvGetElemType(img)), 1, CV_AA, scale );
  696. }
  697. CV_INLINE void cvCircleAA( CvArr* img, CvPoint center, int radius,
  698. double color, int scale CV_DEFAULT(0) )
  699. {
  700. cvCircle( img, center, radius, cvColorToScalar(color, cvGetElemType(img)), 1, CV_AA, scale );
  701. }
  702. CV_INLINE void cvEllipseAA( CvArr* img, CvPoint center, CvSize axes,
  703. double angle, double start_angle,
  704. double end_angle, double color,
  705. int scale CV_DEFAULT(0) )
  706. {
  707. cvEllipse( img, center, axes, angle, start_angle, end_angle,
  708. cvColorToScalar(color, cvGetElemType(img)), 1, CV_AA, scale );
  709. }
  710. CV_INLINE void cvPolyLineAA( CvArr* img, CvPoint** pts, int* npts, int contours,
  711. int is_closed, double color, int scale CV_DEFAULT(0) )
  712. {
  713. cvPolyLine( img, pts, npts, contours, is_closed,
  714. cvColorToScalar(color, cvGetElemType(img)),
  715. 1, CV_AA, scale );
  716. }
  717. #define cvMake2DPoints cvConvertPointsHomogenious
  718. #define cvMake3DPoints cvConvertPointsHomogenious
  719. #define cvWarpPerspectiveQMatrix cvGetPerspectiveTransform
  720. /****************************************************************************************\
  721. * Pixel Access Macros *
  722. \****************************************************************************************/
  723. typedef struct _CvPixelPosition8u
  724. {
  725. unsigned char* currline; /* pointer to the start of the current pixel line */
  726. unsigned char* topline; /* pointer to the start of the top pixel line */
  727. unsigned char* bottomline; /* pointer to the start of the first line */
  728. /* which is below the image */
  729. int x; /* current x coordinate ( in pixels ) */
  730. int width; /* width of the image ( in pixels ) */
  731. int height; /* height of the image ( in pixels ) */
  732. int step; /* distance between lines ( in elements of single */
  733. /* plane ) */
  734. int step_arr[3]; /* array: ( 0, -step, step ). It is used for */
  735. /* vertical moving */
  736. } CvPixelPosition8u;
  737. /* this structure differs from the above only in data type */
  738. typedef struct _CvPixelPosition8s
  739. {
  740. char* currline;
  741. char* topline;
  742. char* bottomline;
  743. int x;
  744. int width;
  745. int height;
  746. int step;
  747. int step_arr[3];
  748. } CvPixelPosition8s;
  749. /* this structure differs from the CvPixelPosition8u only in data type */
  750. typedef struct _CvPixelPosition32f
  751. {
  752. float* currline;
  753. float* topline;
  754. float* bottomline;
  755. int x;
  756. int width;
  757. int height;
  758. int step;
  759. int step_arr[3];
  760. } CvPixelPosition32f;
  761. /* Initialize one of the CvPixelPosition structures. */
  762. /* pos - initialized structure */
  763. /* origin - pointer to the left-top corner of the ROI */
  764. /* step - width of the whole image in bytes */
  765. /* roi - width & height of the ROI */
  766. /* x, y - initial position */
  767. #define CV_INIT_PIXEL_POS(pos, origin, _step, roi, _x, _y, orientation) \
  768. ( \
  769. (pos).step = (_step)/sizeof((pos).currline[0]) * (orientation ? -1 : 1), \
  770. (pos).width = (roi).width, \
  771. (pos).height = (roi).height, \
  772. (pos).bottomline = (origin) + (pos).step*(pos).height, \
  773. (pos).topline = (origin) - (pos).step, \
  774. (pos).step_arr[0] = 0, \
  775. (pos).step_arr[1] = -(pos).step, \
  776. (pos).step_arr[2] = (pos).step, \
  777. (pos).x = (_x), \
  778. (pos).currline = (origin) + (pos).step*(_y) )
  779. /* Move to specified point ( absolute shift ) */
  780. /* pos - position structure */
  781. /* x, y - coordinates of the new position */
  782. /* cs - number of the image channels */
  783. #define CV_MOVE_TO( pos, _x, _y, cs ) \
  784. ((pos).currline = (_y) >= 0 && (_y) < (pos).height ? (pos).topline + ((_y)+1)*(pos).step : 0, \
  785. (pos).x = (_x) >= 0 && (_x) < (pos).width ? (_x) : 0, (pos).currline + (_x) * (cs) )
  786. /* Get current coordinates */
  787. /* pos - position structure */
  788. /* x, y - coordinates of the new position */
  789. /* cs - number of the image channels */
  790. #define CV_GET_CURRENT( pos, cs ) ((pos).currline + (pos).x * (cs))
  791. /* Move by one pixel relatively to current position */
  792. /* pos - position structure */
  793. /* cs - number of the image channels */
  794. /* left */
  795. #define CV_MOVE_LEFT( pos, cs ) \
  796. ( --(pos).x >= 0 ? (pos).currline + (pos).x*(cs) : 0 )
  797. /* right */
  798. #define CV_MOVE_RIGHT( pos, cs ) \
  799. ( ++(pos).x < (pos).width ? (pos).currline + (pos).x*(cs) : 0 )
  800. /* up */
  801. #define CV_MOVE_UP( pos, cs ) \
  802. (((pos).currline -= (pos).step) != (pos).topline ? (pos).currline + (pos).x*(cs) : 0 )
  803. /* down */
  804. #define CV_MOVE_DOWN( pos, cs ) \
  805. (((pos).currline += (pos).step) != (pos).bottomline ? (pos).currline + (pos).x*(cs) : 0 )
  806. /* left up */
  807. #define CV_MOVE_LU( pos, cs ) ( CV_MOVE_LEFT(pos, cs), CV_MOVE_UP(pos, cs))
  808. /* right up */
  809. #define CV_MOVE_RU( pos, cs ) ( CV_MOVE_RIGHT(pos, cs), CV_MOVE_UP(pos, cs))
  810. /* left down */
  811. #define CV_MOVE_LD( pos, cs ) ( CV_MOVE_LEFT(pos, cs), CV_MOVE_DOWN(pos, cs))
  812. /* right down */
  813. #define CV_MOVE_RD( pos, cs ) ( CV_MOVE_RIGHT(pos, cs), CV_MOVE_DOWN(pos, cs))
  814. /* Move by one pixel relatively to current position with wrapping when the position */
  815. /* achieves image boundary */
  816. /* pos - position structure */
  817. /* cs - number of the image channels */
  818. /* left */
  819. #define CV_MOVE_LEFT_WRAP( pos, cs ) \
  820. ((pos).currline + ( --(pos).x >= 0 ? (pos).x : ((pos).x = (pos).width-1))*(cs))
  821. /* right */
  822. #define CV_MOVE_RIGHT_WRAP( pos, cs ) \
  823. ((pos).currline + ( ++(pos).x < (pos).width ? (pos).x : ((pos).x = 0))*(cs) )
  824. /* up */
  825. #define CV_MOVE_UP_WRAP( pos, cs ) \
  826. ((((pos).currline -= (pos).step) != (pos).topline ? \
  827. (pos).currline : ((pos).currline = (pos).bottomline - (pos).step)) + (pos).x*(cs) )
  828. /* down */
  829. #define CV_MOVE_DOWN_WRAP( pos, cs ) \
  830. ((((pos).currline += (pos).step) != (pos).bottomline ? \
  831. (pos).currline : ((pos).currline = (pos).topline + (pos).step)) + (pos).x*(cs) )
  832. /* left up */
  833. #define CV_MOVE_LU_WRAP( pos, cs ) ( CV_MOVE_LEFT_WRAP(pos, cs), CV_MOVE_UP_WRAP(pos, cs))
  834. /* right up */
  835. #define CV_MOVE_RU_WRAP( pos, cs ) ( CV_MOVE_RIGHT_WRAP(pos, cs), CV_MOVE_UP_WRAP(pos, cs))
  836. /* left down */
  837. #define CV_MOVE_LD_WRAP( pos, cs ) ( CV_MOVE_LEFT_WRAP(pos, cs), CV_MOVE_DOWN_WRAP(pos, cs))
  838. /* right down */
  839. #define CV_MOVE_RD_WRAP( pos, cs ) ( CV_MOVE_RIGHT_WRAP(pos, cs), CV_MOVE_DOWN_WRAP(pos, cs))
  840. /* Numeric constants which used for moving in arbitrary direction */
  841. #define CV_SHIFT_NONE 2
  842. #define CV_SHIFT_LEFT 1
  843. #define CV_SHIFT_RIGHT 3
  844. #define CV_SHIFT_UP 6
  845. #define CV_SHIFT_DOWN 10
  846. #define CV_SHIFT_LU 5
  847. #define CV_SHIFT_RU 7
  848. #define CV_SHIFT_LD 9
  849. #define CV_SHIFT_RD 11
  850. /* Move by one pixel in specified direction */
  851. /* pos - position structure */
  852. /* shift - direction ( it's value must be one of the CV_SHIFT_?constants ) */
  853. /* cs - number of the image channels */
  854. #define CV_MOVE_PARAM( pos, shift, cs ) \
  855. ( (pos).currline += (pos).step_arr[(shift)>>2], (pos).x += ((shift)&3)-2, \
  856. ((pos).currline != (pos).topline && (pos).currline != (pos).bottomline && \
  857. (pos).x >= 0 && (pos).x < (pos).width) ? (pos).currline + (pos).x*(cs) : 0 )
  858. /* Move by one pixel in specified direction with wrapping when the */
  859. /* position achieves image boundary */
  860. /* pos - position structure */
  861. /* shift - direction ( it's value must be one of the CV_SHIFT_?constants ) */
  862. /* cs - number of the image channels */
  863. #define CV_MOVE_PARAM_WRAP( pos, shift, cs ) \
  864. ( (pos).currline += (pos).step_arr[(shift)>>2], \
  865. (pos).currline = ((pos).currline == (pos).topline ? \
  866. (pos).bottomline - (pos).step : \
  867. (pos).currline == (pos).bottomline ? \
  868. (pos).topline + (pos).step : (pos).currline), \
  869. \
  870. (pos).x += ((shift)&3)-2, \
  871. (pos).x = ((pos).x < 0 ? (pos).width-1 : (pos).x >= (pos).width ? 0 : (pos).x), \
  872. \
  873. (pos).currline + (pos).x*(cs) )
  874. #endif/*_CVCOMPAT_H_*/