eyemLib.h 32.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
#pragma once
//
//	eyemLib·标头
//
#ifndef __EYEM_LIB_H
#define __EYEM_LIB_H

#include <Windows.h>
#include <opencv.hpp>


#ifndef EXPORTS
#define EXPORTS __declspec(dllexport)
#endif

#ifndef MAKETYPE
#define MAKETYPE CV_MAKETYPE
#endif

/********************************************************************************************/
/*                                     通用标头                                         */
/********************************************************************************************/

// 一般定义
#define FUNC_OK						0						// 正常
#define FUNC_NOT_ENOUGH_MEM			(-1)					// 工作内存不足
#define FUNC_ILLEGAL_ARGUMENT		(-2)					// 参数不合适
#define FUNC_IMAGE_NOT_EXIST		(-3)					// 图像不存在
#define FUNC_CANNOT_CALC			(-100)					// 不可计算
#define FUNC_CANNOT_USE				(-999)					// 不可用


// 错误代码(矩阵计算)
#define FUNC_DET_EQ_ZERO			(-110)					// 矩阵表达式为零
#define FUNC_FAILED_EIGEN			(-111)					// 特征值和特征向量计算失败
#define FUNC_FAILED_SVD				(-112)					// 奇异值分解计算失败
#define FUNC_FAILED_CHOLESKY		(-113)					// CHOLESKY分解计算失败

// 错误代码(近似计算)
#define FUNC_FAILED_ROBUST			(-130)					// 稳健估计失败
#define FUNC_FAILED_ELLIPSE			(-131)					// 不是椭圆形的
#define FUNC_FAILED_ELLIPSOID		(-132)					// 不是椭圆体
#define FUNC_FAILED_CONE			(-133)					// 不是在锥面

// 错误代码(摄像机校准)
#define FUNC_FAILED_HOMOGRAPHY		(-150)					// 同源矩阵计算失败
#define FUNC_FAILED_CAM_PRM			(-151)					// 摄像机参数计算失败
#define FUNC_FAILED_BUNDLE_ADJ		(-152)					// バンドル調整失敗
#define FUNC_FAILED_UNDISTORT		(-153)					// 失真校正失败


// 常数
#define EPS				1.0e-9								// ε
#define DBL_EPS			DBL_EPSILON							// ε
#define PI				3.1415926535897932384626433832795	// π
#define PI_DEG			180.0								// π(deg)
#define RAD2DEG			(PI_DEG/PI)							// rad→deg变换
#define DEG2RAD			(PI/PI_DEG)							// deg→rad变换
#define TWO_PI			(2.0*PI)							// 2π
#define PI_BY_2			(PI/2.0)							// π/2


#ifndef MIN
#define MIN( a, b ) ( ((a) < (b)) ? (a) : (b) )
#endif
#ifndef MAX
#define MAX( a, b ) ( ((a) > (b)) ? (a) : (b) )
#endif

#ifndef SGN
#define SGN( a ) ( ((a) >= (0)) ? (1) : (-1) )
#endif

#ifndef COMPARE
#define COMPARE( a, b ) ( ((a) > (b)) ? (true) : (false) )
#endif

#define ON				1
#define OFF				0

#ifndef TRUE
#define TRUE			1
#endif

#ifndef FALSE
#define FALSE			0
#endif

#ifndef NULL
#ifdef __cplusplus
#define NULL		0
#else
#define NULL		((void *)0)
#endif
#endif

typedef intptr_t        IntPtr;

// 图像边界处理
#ifndef __EYEM_BORDER
#define __EYEM_BORDER
enum {
	EYEM_BORDER_NONE,										// 不执行边界处理
	EYEM_BORDER_REPLICATE,									// 延长最外周灰度值
	EYEM_BORDER_REFLECT,									// 镜像(相对于最外边缘对称复制)
	EYEM_BORDER_ZERO										// 填充零灰度
};
#endif


// 图像信息
typedef struct {
	void					*vpImage;						// 地址
	int						iWidth;							// 图像内存 x 方向大小
	int						iHeight;						// 图像内存 y 方向大小
	int						iDepth;							// 图像位深度(参见说明)
	int						iChannels;						// 图像通道数
}	EyemImage;


// 矩形定义
typedef struct {
	int						iXs;							// 起始点(左上角) x 坐标
	int						iYs;							// 起始点(左上角) y 坐标
	int						iWidth;							// x 方向大小(宽度)
	int						iHeight;						// y 方向大小(高度)
}	EyemRect;

typedef struct {
	int						iXs;							// 起始点(左上角) x 坐标
	int						iYs;							// 起始点(左上角) y 坐标
	int						iXe;							// 端点(右下) x 坐标
	int						iYe;							// 端点(右下) y 坐标
}	EyemRect2;

// 矩形定义
typedef struct {
	int						iXs;							// 起始点(左上角) x 坐标
	int						iYs;							// 起始点(左上角) y 坐标
	int						iWidth;							// x 方向大小(宽度)
	int						iHeight;						// y 方向大小(高度)
	double					dVar;							// 可能会使用的值
}	EyemRect3;


///////////////////////////////////////////////////////////////////////////////
// Orthogonal Coordinate System

/////////////////////
// int type
//
typedef struct {
	int						iX;								// X坐标
	int						iY;								// Y坐标
}	EyemOcsIXY;

typedef struct {
	int						iX;								// X坐标
	int						iY;								// Y坐标
	int						iZ;								// Z坐标
}	EyemOcsIXYZ;

typedef struct {
	int						iX;								// X坐标
	int						iY;								// Y坐标
	int						iQ;								// θ
}	EyemOcsIXYQ;

typedef struct {
	int						iX;								// X坐标
	int						iY;								// Y坐标
	int						iR;								// 半径
}	EyemOcsIXYR;											// 用于表示圆

typedef struct {
	int						iA;								// a
	int						iB;								// b
	int						iC;								// c
}	EyemOcsIABC;											// 用于表示直线(一般形式)

typedef struct {
	int						iR;								// ρ
	int						iQ;								// θ
}	EyemOcsIRQ;												// 用于表示直线(黑森标准形式)或矢量

typedef struct {
	int						iX;								// X坐标(単位:像素)
	int						iY;								// Y坐标(単位:像素)
	int						iQ;								// 斜率(単位:rad)
	int						iS;								// 刻度
}	EyemOcsIXYQS;


/////////////////////
// float type
//
typedef struct {
	float					fX;								// X坐标
	float					fY;								// Y坐标
}	EyemOcsFXY;

typedef struct {
	float					fX;								// X坐标
	float					fY;								// Y坐标
	float					fZ;								// Z坐标
}	EyemOcsFXYZ;

typedef struct {
	float					fX;								// X坐标
	float					fY;								// Y坐标
	float					fQ;								// θ
}	EyemOcsFXYQ;

typedef struct {
	float					fX;								// X坐标
	float					fY;								// Y坐标
	float					fR;								// 半径
}	EyemOcsFXYR;											// 用于表示圆

typedef struct {
	float					fA;								// a
	float					fB;								// b
	float					fC;								// c
}	EyemOcsFABC;											// 用于表示直线(一般形式)

typedef struct {
	float					fR;								// ρ
	float					fQ;								// θ
}	EyemOcsFRQ;												// 用于表示直线(黑森标准形式)或矢量

typedef struct {
	float					fX;								// X坐标(単位:像素)
	float					fY;								// Y坐标(単位:像素)
	float					fQ;								// 斜率(単位:rad)
	float					fS;								// 刻度
}	EyemOcsFXYQS;


/////////////////////
// double type
//
typedef struct {
	double					dX;								// X坐标
	double					dY;								// Y坐标
}	EyemOcsDXY;

typedef struct {
	double					dX;								// X坐标
	double					dY;								// Y坐标
	double					dZ;								// Z坐标
}	EyemOcsDXYZ;

typedef struct {
	double					dX;								// X坐标
	double					dY;								// Y坐标
	double					dQ;								// θ
}	EyemOcsDXYQ;

typedef struct {
	double					dX;								// 中心的X坐标
	double					dY;								// 中心のY坐标
	double					dR;								// 半径
}	EyemOcsDXYR;											// 円の表現に使用

typedef struct {
	double					dA;								// a
	double					dB;								// b
	double					dC;								// c
}	EyemOcsDABC;											// 直線(一般形)の表現に使用

typedef struct {
	double					dR;								// ρ
	double					dQ;								// θ
}	EyemOcsDRQ;												// 直線(ヘッセの標準形)やベクトルの表現に使用

typedef struct {
	double					dX;								// X座標
	double					dY;								// Y座標
	double					dQ;								// 回転角(単位:rad)
	double					dS;								// スケール
}	EyemOcsDXYQS;

typedef struct {
	double					dA;								// a
	double					dB;								// b
	double					dC;								// c
	double					dD;								// d
}	EyemOcsDABCD;											// 平面(一般形)の表現に使用

typedef struct {
	double					dXo;							// 中心のX座標
	double					dYo;							// 中心のY座標
	double					dL;								// 長軸半径
	double					dS;								// 短軸半径
	double					dQ;								// 長軸の傾き(単位:rad)
}	EyemOcsDXYLSQ;											// 楕円の表現に使用

typedef struct {
	EyemOcsDXYZ				tP;								// 直線上の1点の座標
	EyemOcsDXYZ				tV;								// 直線の方向ベクトル
}	EyemOcsDPV;												// 3次元空間内の直線の表現に使用


typedef struct {
	EyemOcsDXYZ				tC;								// 楕円体の中心
	EyemOcsDXYZ				tR;								// 軸の半径(dX:長軸, dY:中軸, dZ:短軸)
	double					dU;								// 長軸のXY平面への射影がX軸となす角(単位:rad)
	double					dV;								// 長軸のXY平面とのなす角(単位:rad)
	double					dW;								// 長軸まわりの回転角(単位:rad)
}	EyemOcsDCRUVW;											// 楕円体の表現に使用


/********************************************************************************************/
/*                             每个特定于源的标头                                 */
/********************************************************************************************/

//////////////////////////////////////////////////////////////////////////////////////////////
// 数学计算实用程序(eyemMath.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif

	double	eyemMathCalcInnerProduct(int, double[], double[]);
	void	eyemMathCalcOuterProduct(double[], double[], double[]);
	int		eyemMathCalcAngle(int, double[], double[], double *);
	double	eyemMathCalcNorm(int, double[]);
	double	eyemMathCalcArgument(double[]);
	int		eyemMathNormalization(int, double[]);
	int		eyemMathStat(int, double[], double *, double *, double *);
	double	eyemMathMedianI(int, int *);
	double	eyemMathMedianD(int, double *);
	int		eyemMathOtsuThreshold1d(int, double[], double *);
	double	eyemMathAreaTriangle(double, double, double, double, double, double);
	double	eyemMathSignAreaTriangle(double, double, double, double, double, double);
	void	eyemMathRotatePoint(double, double, double, double, double, double *, double *);
	void	eyemMathCreateTransParam(int, double, double, double, double, double *, double *, double *);
	void	eyemMathTransCoordOfPoint(double, double, double, double, double, double *, double *);
	void	eyemMathInvTransCoordOfPoint(double, double, double, double, double, double *, double *);
	void	eyemMathComposeCoord(double, double, double, double, double, double, double *, double *, double *);
	double	eyemMathInvMatrixOfSyn3X3(double[][3], double[][3]);
	void	eyemMathInvCoord(double, double, double, double *, double *, double *);
	double  eyemMathGetDistFromPointToPoint(double, double, double, double);
	double	eyemMathGetDistFromPointToLine(double, double, double, double, double);
	double	eyemMathGetDistAndCrossPointFromPointToLine(double, double, double, double, double, double *, double *);
	double	eyemMathGetDistFromPointToCircle(double, double, double, double, double, double *, double *);
	int		eyemMathGetDistFromPointToEllipse(double, double, double, double, double, double, double, double *, double *, double *);
	int		eyemMathCrossPoint(double, double, double, double, double, double, double *, double *);
	void	eyemMathTransAbcToRq(double, double, double, double *, double *);
	double	eyemMathCrossAngle(double, double, double, double, double, double);
	int		eyemMathGetLineFrom2Points(double, double, double, double, double *, double *, double *);
	void	eyemMathGetOrthogonalLineFromLineAndPoint(double, double, double, double, double *, double *, double *);
	int		eyemMathCheckAngle(double, double, double);
	double	eyemMathAddAngle(int, int, double, double);
	double	eyemMathPrimeAngle(int, int, double);
	double	eyemMathExtremumOfQuadraticCurves(double, double, double, double *);
	double	eyemMathExtremumOfQuadraticSurface(double, double, double, double, double, double, double *, double *);
	double	eyemMathCrossCorrelation(int, double[], double[]);
	int		eyemMathAutoCorrelation(int, double[], int, double[]);
	double	eyemMathNormCorrelation(int, double[], double[]);
	int		eyemMathNormAutoCorrelation(int, double[], int, double[]);
	int		eyemMathSearchOf1DWithNormCorrelation(int, double[], int, double[], int *, double *);
	int		eyemMathQuadraticRoots(double[], double[]);
	int		eyemMathCubicRoots(double[], double[]);
	int		eyemMathQuarticRoots(double[], double[]);
	double	eyemMathHorner(int, double[], double);
	void	eyemMathTransCoord(double, double, double, double, double, double *, double *);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 矩阵计算实用程序(eyemMat.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	//EXPORTS CvMat			*eyemMatMallocMatrix(int iRows, int iCols, void *vpData);
	//EXPORTS void			eyemMatFreeMatrix(CvMat *dpMat);
	//EXPORTS void			eyemMatZero(CvMat *vpA);
	//EXPORTS void			eyemMatCopy(CvMat *vpDst, CvMat	*vpSrc);
	//EXPORTS void			eyemMatAdd(CvMat *vpA, CvMat *vpB, CvMat *vpC);
	EXPORTS void			eyemMatSub(int, int, void *, void *, void *);
	EXPORTS void			eyemMatMulScalar(double, int, int, void *, void *);
	EXPORTS int				eyemMatMul(int, int, void *, int, int, void *, void *);
	EXPORTS int				eyemMatGenMul(double, int, int, void *, int, int, void	*, double, void	*, void	*);
	EXPORTS void			eyemMatMulTransposed(int, int, int, void	*, void	*);
	EXPORTS int				eyemMatMulTransposed2(int, int, int, void *, int, int, void *, void *);
	EXPORTS void			eyemMatTranspose(int, int, void *, void *);
	EXPORTS double			eyemMatTrace(int, void	*);
	EXPORTS int				eyemMatInvert(int, void *, void *);
	EXPORTS int				eyemMatSolveLU(int, void *, double[], double[]);
	EXPORTS int				eyemMatSolveSVD(int, int, void	*, double[], double[]);
	EXPORTS int				eyemMatJacobiEigen(int, void *, double[], void *);
	EXPORTS int				eyemMatQrEigen(int, void *, double[], void *);
	EXPORTS int				eyemMatSVD(int, int, void *, void *, double[], void *);
	EXPORTS int				eyemMatCholeskyDecomp(int, void *, void *);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 近似计算(稳健估计)(eyemFit.cpp)
//

//稳健估计方法
enum
{
	EYEM_DIST_USER = -1,			/**< User defined distance */
	EYEM_DIST_L1 = 1,				/**< distance = |x1-x2| + |y1-y2| */
	EYEM_DIST_L12 = 2,				/**< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1)) */
	EYEM_DIST_FAIR = 3,				/**< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998 */
	EYEM_DIST_WELSCH = 4,			/**< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846 */
	EYEM_DIST_HUBER = 5,			/**< distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 */
	EYEM_DIST_TUKEY = 6,			/**< distance = di<= c ?(1-(di/c)^2)^2 : 0, c=2.718  di=|yi-(axi+b)|*/
	EYEM_DIST_CAUCHY = 7,			/**< distance = c^2(|x|/c-log(1+|x|/c)), c = 2.385 */
	EYEM_DIST_LOGISTIC = 8,			/**< distance w = tanh(r) ./ r  c = 1.205*/
	EYEM_DIST_ANDREWS = 9,			/**< w = (abs(r)<pi) .* sin(r) ./ r c= 1.339*/
	EYEM_DIST_ATLWORTH = 10			/**< w = 1 * (abs(r)<1) c=2.975*/
};

#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	EXPORTS int				eyemFitLine(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, int numToIgnore, EyemOcsDABC &tpLine);
	EXPORTS int				eyemRobustFitLine(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDABC &tpLine);
	EXPORTS int				eyemFitPlane(int, EyemOcsDXYZ[], int, double, EyemOcsDABCD *);
	EXPORTS int				eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, int numToIgnore, EyemOcsDXYR &tpCircle);
	EXPORTS int				eyemFitEllipse(int, EyemOcsDXY[], int, double, EyemOcsDXYLSQ *);
	EXPORTS int				eyemFitEllipseC(int, EyemOcsDXY[], int, double, double[]);
	EXPORTS int				eyemFitConics(int, EyemOcsDXY[], int, double, double[]);
	EXPORTS int				eyemFitParabola(int, EyemOcsDXY[], int, double, EyemOcsDABC *);
	EXPORTS int				eyemFitEllipsoid(int, EyemOcsDXYZ[], int, double, EyemOcsDCRUVW *);
	EXPORTS int				eyemFitCone(int, EyemOcsDXYZ[], int, double, double[]);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 二维几何计算(二维卡尺)(eyemClp2d.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	EXPORTS void			eyemClp2dDistanceTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, double &tpDist);
	EXPORTS void			eyemClp2dCenterTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY &tpCenter);
	EXPORTS int				eyemClp2dLineTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC &tpLine);
	EXPORTS int				eyemClp2dMidperpendicularTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC &tpLine);
	EXPORTS int				eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, EyemOcsDABC &tpVertical);
	EXPORTS void			eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, EyemOcsDABC &tpLine);
	EXPORTS int				eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDXY &tpPoint);
	EXPORTS int				eyemClp2dAngleTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, double &dpAngle);
	EXPORTS int				eyemClp2dCenterLineOfTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDABC &tpLineC);
	EXPORTS int				eyemClp2dDistancePointToLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, double &dpDist);
	EXPORTS int				eyemClp2dTranslationOfLine(EyemOcsDABC tpSrcL, EyemOcsDXY tpTrans, EyemOcsDABC &tpDstL);
	EXPORTS void			eyemClp2dAreaTriangle(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY tpPoint3, double &dpArea);
	EXPORTS int				eyemClp2dCircleThreePoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDXY tpPoint3, EyemOcsDXYR &tpCircle);
	EXPORTS int				eyemClp2dIntersectionLineAndCircle(EyemOcsDABC tpLine, EyemOcsDXYR tpCircle, EyemOcsDXY &tpPoint1, EyemOcsDXY &tpPoint2);
	EXPORTS int				eyemClp2dTangentPointToCircle(EyemOcsDXY tpPoint, EyemOcsDXYR tpCircle, EyemOcsDABC &tpTangent1, EyemOcsDXY &tpContact1, EyemOcsDABC &tpTangent2, EyemOcsDXY &tpContact2);
	EXPORTS int				eyemClp2dClosestToCircle(EyemOcsDXY tpPoint, EyemOcsDXYR tpCircle, EyemOcsDXY &tpClosest, double &dpDist);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 3D 几何计算(3D 卡尺)(eyemClp3d.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	void	eyemClp3dDistanceTwoPoints(EyemOcsDXYZ *, EyemOcsDXYZ *, double *);
	void	eyemClp3dCenterTwoPoints(EyemOcsDXYZ *, EyemOcsDXYZ *, EyemOcsDXYZ	*);
	int		eyemClp3dLineTwoPoints(EyemOcsDXYZ	*, EyemOcsDXYZ *, EyemOcsDPV *);
	int		eyemClp3dFootOfPerpendicularToLine(EyemOcsDXYZ *, EyemOcsDPV	*, EyemOcsDXYZ *);
	int		eyemClp3dVerticalLinePointAndLine(EyemOcsDXYZ	*, EyemOcsDPV *, EyemOcsDPV	*);
	int		eyemClp3dDistancePointToLine(EyemOcsDXYZ *, EyemOcsDPV *, double *);
	int		eyemClp3dDistanceTwoLines(EyemOcsDPV *, EyemOcsDPV *, double *);
	int		eyemClp3dPlaneThreePoints(EyemOcsDXYZ *, EyemOcsDXYZ *, EyemOcsDXYZ *, EyemOcsDABCD *);
	int		eyemClp3dVerticalPlanePointAndVector(EyemOcsDXYZ *, EyemOcsDXYZ *, EyemOcsDABCD *);
	int		eyemClp3dVerticalLinePointAndPlane(EyemOcsDXYZ *, EyemOcsDABCD	*, EyemOcsDPV *);
	int		eyemClp3dDistancePointToPlane(EyemOcsDXYZ *, EyemOcsDABCD *, double *);
	int		eyemClp3dIntersectionLineAndPlane(EyemOcsDPV *, EyemOcsDABCD *, EyemOcsDXYZ *);
	int		eyemClp3dAngleLineAndPlane(EyemOcsDPV *, EyemOcsDABCD *, double *);
	int		eyemClp3dFootOfPerpendicularToPlane(EyemOcsDXYZ *, EyemOcsDABCD *, EyemOcsDXYZ *);
	int		eyemClp3dIntersectionTwoPlanes(EyemOcsDABCD	*, EyemOcsDABCD	*, EyemOcsDPV *);
	int		eyemClp3dAngleTwoPlanes(EyemOcsDABCD *, EyemOcsDABCD *, double *);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 计算几何(eyemCg.cpp)
//

// 线交叉状态
enum {
	EYEM_CG_NOT_INTERSECTION,								// 未相交
	EYEM_CG_INTERSECTION,									// 相交(彼此交叉)
};


// 点位置状态
enum {
	EYEM_CG_OUTER,											// 在外部
	EYEM_CG_INNER,											// 在内部
	EYEM_CG_BORDER											// 在边界上
};


#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	int		eyemCgSortByArgument(int n, EyemOcsDXY taSrcPt[], EyemOcsDXY taDstPt[]);
	int		eyemCgConvexHull(int, EyemOcsDXY[], int *, EyemOcsDXY[]);
	int		eyemCgSmallestEnclosingCircle(int, EyemOcsDXY[], EyemOcsDXY *, double *);
	int		eyemCgIntersectionOfTwoSegments(EyemOcsDXY *, EyemOcsDXY *, EyemOcsDXY *, EyemOcsDXY *, int *, EyemOcsDXY *);
	int		eyemCgPointInConvexPolygon(int, EyemOcsDXY[], EyemOcsDXY *, int *);
	int		eyemCgIntersectionLineAndConvexPolygon(int, EyemOcsDXY[], EyemOcsDABC *, EyemOcsDXY[]);
	int		eyemCgIntersectionSegmentAndConvexPolygon(int, EyemOcsDXY[], EyemOcsDXY *, EyemOcsDXY *, EyemOcsDXY[]);
	int		eyemCgPointInPolygon(int, EyemOcsDXY[], EyemOcsDXY *, int *);
	int		eyemCgAreaOfPolygon(int, EyemOcsDXY[], double *);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 2 值 blob 分析(eyemBin.cpp)
//
enum {
	EYEM_BIN_BLACK,											// 黒
	EYEM_BIN_WHITE											// 白
};

//全局阈值2值化方法
enum {
	HUANG,
	ISODATA,
	LI,
	MAXENTROPY,
	MEAN,
	MOMENTS,
	OTSU,
	PERCENTILE,
	RENYIENTROPY,
	SHANBHAG,
	TRIANGLE,
	YEN
};

//动态阈值2值化方法
enum {
	LIGHT,
	DARK,
	EQUAL,
	NOT_EQUAL
};


// 局部阈值2值化方法
enum
{
	BINARIZATION_NIBLACK,
	BINARIZATION_WOLF,
	BINARIZATION_NICK,
	BINARIZATION_SAUVOLA
};


// Blob 分析结果
typedef struct {
	int				iLabel;									// 标签
	int				iArea;									// 面积
	double			dCenterX;								// 重心x坐标
	double			dCenterY;								// 重心y坐标
	int				iXs, iYs, iXe, iYe;						// 外接矩形(始点,终点)
	int				iWidth, iHeight;						// 外接矩形(x 方向大小(宽度),y 方向大小(高度))
	double			dTheta;									// 主轴倾斜角(rad)
}	EyemBinBlob;

typedef struct {
	int				iLabel;									// 标签
	double			dX;										// x坐标
	double			dY;										// y坐标
	double			dVx, dVy;								// 向量
}	EyemChainCode;


#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	EXPORTS int		   eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double dMaxVal, EyemImage *tpDstImg);
	EXPORTS int		   eyemBinAutoThreshold(EyemImage tpSrcImg, double dSigma, int iLightDark, int binMethod, EyemImage *tpDstImg);
	EXPORTS int		   eyemBinNiBlack(EyemImage tpSrcImg, EyemImage *tpDstImg, int iType, int iWinSize, double dK, int binarizationMethod, double dR);
	EXPORTS int		   eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, int iOffset, int iLightDark, EyemImage *tpDstImg);
	EXPORTS int		   eyemBinDilation(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
	EXPORTS int		   eyemBinErosion(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
	EXPORTS int		   eyemBinOpening(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
	EXPORTS int		   eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDstImg);
	EXPORTS int		   eyemBinBlob(EyemImage tpImage, IntPtr *hObject, int iAreaThrs, EyemBinBlob **tpResult, int *ipNum, EyemImage *tpDstImg);
	EXPORTS int		   eyemBinBlobFilterByArea(IntPtr hObject, int iMinArea, int iMaxArea);
	EXPORTS int		   eyemBinBlobFilterByLabel(IntPtr hObject, int iLabel);
	EXPORTS int		   eyemBinBlobRender(EyemImage tpImage, IntPtr hObject, EyemImage *tpDstImg);
	EXPORTS bool	   eyemBinFree(IntPtr hObject);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 一维边缘提取(eyemEdge1d.cpp)
//


#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	EXPORTS int		eyemEdge1dGenMeasureRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, const char *ccSubType, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject);
	EXPORTS int		eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject);
	EXPORTS int		eyemEdge1dFitLine(IntPtr hObject, int iClippingEndPoints, int iMaxIterations, double dRobustCoef, EyemOcsDABC *tpLine);
	EXPORTS int		eyemEdge1dFitCircle(IntPtr hObject, int iClippingEndPoints, int iMaxIterations, double dRobustCoef, EyemOcsDXYR *tpCircle);
	EXPORTS int		eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, IntPtr *hObject);
	EXPORTS bool	eyemEdge1dGenMeasureFree(IntPtr hObject);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 二维边缘提取(eyemEdge.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	EXPORTS int		eyemEdgesPixel(EyemImage tpImage, double dThresh);
	EXPORTS int		eyemEdgesSubpixel(EyemImage tpImage, IntPtr *hObject, EyemOcsDXY **tpEdges, int iFilter, int iLow, int iHigh);
	EXPORTS int		eyemSkeleton(EyemImage tpImage, cv::Mat &skeleton);
	EXPORTS int		eyemSobelAmp(EyemImage tpImage, EyemImage &ImaAmp);
	EXPORTS int		eyemAutoCanny(EyemImage tpImage, float dSigma = 0.33);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 点云匹配(eyemMatch.cpp)
//

// 处理类型
enum {
	EYEM_MATCH_LSQ,											// 最小二乗法
	EYEM_MATCH_LSQ_S,										// 加权最小二乗法
	EYEM_MATCH_ROBUST,										// 稳健估计・无比例估计
	EYEM_MATCH_ROBUST_S,									// 稳健估计・带比例估计
	EYEM_MATCH_MINMAX,										// MINMAX方法・无比例估计
	EYEM_MATCH_MINMAX_S										// MINMAX方法・带比例估计
};


#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	int		eyemMatchBasic(int, EyemOcsDXY[], EyemOcsDXY[], EyemOcsDXYQ *, int, double, EyemOcsDXYQS *);
	int		eyemMatchDelta(EyemOcsDXYQ *, EyemOcsDXYQS *, double *, double *, double *, double *);
	int		eyemMatchPoints(int, EyemOcsDXY[], EyemOcsDXY[], EyemOcsDXYQ *, EyemOcsDXYQS *, EyemOcsDXY[], double[]);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 摄像机校准(eyemCalib.cpp)
//

// 模式数据
typedef struct {
	int				iPtnRefN;								// 图案参考点数
	EyemOcsDXY		*tpObjPt;								// 阵列参考点的实际坐标(単位:mm)
	EyemOcsDXY		*tpImgPt;								// 图案参考点的图像坐标(単位:像素)
}	EyemCalibPtn;


// 同源矩阵
typedef struct {
	double			daH[3][3];								// 同源矩阵 H
	double			daInvH[3][3];							// 矩阵 H 的逆矩阵
}	EyemCalibHom;


// 摄像机的内参数(intrinsic parameter)
typedef struct {
	double			daA[3][3];								// 内参数矩阵
	double			dK1, dK2;								// 径向失真系数
	double			dK3, dK4, dK5;							// 径向失真系数
	double			daInvA[3][3];							// 内参数矩阵的逆矩阵
}	EyemCalibInt;


// 摄像机外部参数(extrinsic parameter)
typedef struct {
	double			daR[3][3];								// 旋转矩阵
	double			daT[3];									// 平移矢量
	double			daRdr[3];								// 旋转矢量(罗德里格斯表示)
}	EyemCalibExt;


#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	int		eyemCalibCameraCalibrate(int, EyemCalibPtn[], double, EyemCalibInt *, EyemCalibExt[], double *, int);
	int		eyemCalibCalcHomography(int, void *, void *, double, void *);
	int		eyemCalibRodrigues(int, double[3], double[3][3]);
	int		eyemCalibUnDistortPoint(EyemCalibInt *, double, double, double *, double *);
	int		eyemCalibUnDistortMat(EyemCalibInt *, double, double, double *, double *);
	int		eyemCalibChange3Dto2D(EyemOcsDXYZ *, EyemCalibInt *, EyemCalibExt *, EyemOcsDXY *, int);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 图像平滑滤镜(eyemSmooth.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	EXPORTS int		eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstImg);
	EXPORTS int		eyemSmoothGaussian(EyemImage tpImage, int kSizew, int kSizeh, double dSigmaX, double dSigmaY, EyemImage *tpDstImg);
	EXPORTS int		eyemSmoothMedian(EyemImage tpImage, int kSize, EyemImage *tpDstImg);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 图像线段检测器(eyemEDLinesDetector.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	//EXPORTS int		eyemEDLinesDetector(EyemImage tpImage, int _gradThresh, int _anchorThresh, int _scanInterval, int _minPathLen, double _sigma, bool _sumFlag, double _line_error, int _min_line_len, double _max_distance_between_two_lines, double _max_error, EyemImage *tpDstImg);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 图像通用处理(eyemGeneric.cpp)
//
#ifdef __cplusplus
extern "C" {
#endif

	// 函数接口
	EXPORTS int				eyemImageRead(const char *filename, int iFalgs, EyemImage *ucpImage);
	EXPORTS int				eyemVideoCapture(const char *fileName, IntPtr *hObject, EyemImage **tpImages, int *ipNum);
	EXPORTS int				eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, EyemImage *tpImage);
	EXPORTS int				eyemImageMalloc(int iWidth, int iHeight, int iChannels, const char *ccSubType, EyemImage *tpImage);
	EXPORTS int				eyemImageCopy(EyemImage tpSrcImg, EyemImage &tpDstImg);
	EXPORTS	int				eyemCvtImageColor(EyemImage tpImage, int iCCodes, EyemImage &tpDstImg);
	EXPORTS	int				eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, double beta, EyemImage &tpDstImg);
	EXPORTS int				eyemImageAdd(EyemImage tpImage1, EyemImage tpImage2, EyemImage &tpDstImg);
	EXPORTS int				eyemImageSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage &tpDstImg);
	EXPORTS int				eyemImageDiv(EyemImage tpImage1, EyemImage tpImage2, EyemImage &tpDstImg);
	EXPORTS int				eyemImageAbs(EyemImage tpImage, EyemImage &tpDstImg);
	EXPORTS void			eyemOpenWindow(const char *winname);
	EXPORTS void			eyemCloseWindow(const char *winname);
	EXPORTS void		    eyemImageFree(EyemImage &ipImage);
	EXPORTS bool			eyemVideoCaptureFree(IntPtr hObject);

#ifdef __cplusplus
}
#endif


//////////////////////////////////////////////////////////////////////////////////////////////
// 其他工具(eyemMisc.cpp)
//

// 条码 解码结果
typedef struct {
	double				dAngle;								// 角度
	int					iCenterX;							// y坐标
	int					iCenterY;							// y坐标
	LPSTR				lpszType;							// 码类型
	LPSTR				lpszText;							// 码内容
}	EyemBarCode;

typedef struct {
	void					*vpImage;						// 地址
	int						iXs;							// 图像X坐标
	int						iYs;							// 图像Y坐标
	int						iWidth;							// 图像内存X方向大小
	int						iHeight;						// 图像内存Y方向大小
	double					dMatchDeg;						// 匹配度
	LPSTR					lpszName;						// 名称
}	EyemModelID;


#ifdef __cplusplus
extern "C" {
#endif
	EXPORTS int				eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileName, const char *ccCodeType, IntPtr *hObject, EyemBarCode **tpResult, int *ipNum, bool bUseNiBlack, int iBlockSize, const int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown = 0.5, double dToleErr = 0.5, double dMinorStep = 1.0);
	EXPORTS bool			eyemDetectAndDecodeFree(IntPtr hObject);
	EXPORTS int				eyemCountObject(EyemImage tpImage, EyemRect tpRoi, const char *fileName, double dOffset, int iMinArea, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
	EXPORTS int				eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, LPSTR *lpszNumObj, EyemImage *tpDstImg);
	EXPORTS int				eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char *fileName, double dOffset, const char * ccSubType, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
	EXPORTS int				eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, const char *ccTplName, IntPtr hModelID, LPSTR *lpszReelNum, EyemImage *tpDstImg);
	EXPORTS int				eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg);
	EXPORTS int				eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, const char *ccTplName);
	EXPORTS int				eyemMatchTemplateModel(EyemImage tpImage, IntPtr hModelID, LPSTR *lpszTplName);
	EXPORTS int				eyemInitModel(const char *ccTplName, IntPtr *hModelID);
	EXPORTS int				eyemAchvModelByName(const char *ccTplName, IntPtr hModelID, EyemModelID &tpModelID);
	EXPORTS int				eyemInsertModel(IntPtr &hModelID, const char *ccTplName);
	EXPORTS int				eyemRemoveModelByName(IntPtr &hModelID, const char *ccTplName);
	EXPORTS int				eyemReleaseModel(IntPtr &hModelID);
	EXPORTS int				eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum, int *ipResults);
	EXPORTS int				eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum);

#ifdef __cplusplus
}
#endif


#endif/* __EYEM_LIB_H */