Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/calib3d/src/precomp.hpp
16339 views
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
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
19
//
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
22
//
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
26
//
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
29
//
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
40
//
41
//M*/
42
#ifndef __OPENCV_PRECOMP_H__
43
#define __OPENCV_PRECOMP_H__
44
45
#include "opencv2/core/utility.hpp"
46
47
#include "opencv2/core/private.hpp"
48
49
#include "opencv2/calib3d.hpp"
50
#include "opencv2/imgproc.hpp"
51
#include "opencv2/features2d.hpp"
52
53
54
#include "opencv2/core/ocl.hpp"
55
56
#define GET_OPTIMIZED(func) (func)
57
58
59
namespace cv
60
{
61
62
/**
63
* Compute the number of iterations given the confidence, outlier ratio, number
64
* of model points and the maximum iteration number.
65
*
66
* @param p confidence value
67
* @param ep outlier ratio
68
* @param modelPoints number of model points required for estimation
69
* @param maxIters maximum number of iterations
70
* @return
71
* \f[
72
* \frac{\ln(1-p)}{\ln\left(1-(1-ep)^\mathrm{modelPoints}\right)}
73
* \f]
74
*
75
* If the computed number of iterations is larger than maxIters, then maxIters is returned.
76
*/
77
int RANSACUpdateNumIters( double p, double ep, int modelPoints, int maxIters );
78
79
class CV_EXPORTS LMSolver : public Algorithm
80
{
81
public:
82
class CV_EXPORTS Callback
83
{
84
public:
85
virtual ~Callback() {}
86
virtual bool compute(InputArray param, OutputArray err, OutputArray J) const = 0;
87
};
88
89
virtual void setCallback(const Ptr<LMSolver::Callback>& cb) = 0;
90
virtual int run(InputOutputArray _param0) const = 0;
91
};
92
93
CV_EXPORTS Ptr<LMSolver> createLMSolver(const Ptr<LMSolver::Callback>& cb, int maxIters);
94
95
class CV_EXPORTS PointSetRegistrator : public Algorithm
96
{
97
public:
98
class CV_EXPORTS Callback
99
{
100
public:
101
virtual ~Callback() {}
102
virtual int runKernel(InputArray m1, InputArray m2, OutputArray model) const = 0;
103
virtual void computeError(InputArray m1, InputArray m2, InputArray model, OutputArray err) const = 0;
104
virtual bool checkSubset(InputArray, InputArray, int) const { return true; }
105
};
106
107
virtual void setCallback(const Ptr<PointSetRegistrator::Callback>& cb) = 0;
108
virtual bool run(InputArray m1, InputArray m2, OutputArray model, OutputArray mask) const = 0;
109
};
110
111
CV_EXPORTS Ptr<PointSetRegistrator> createRANSACPointSetRegistrator(const Ptr<PointSetRegistrator::Callback>& cb,
112
int modelPoints, double threshold,
113
double confidence=0.99, int maxIters=1000 );
114
115
CV_EXPORTS Ptr<PointSetRegistrator> createLMeDSPointSetRegistrator(const Ptr<PointSetRegistrator::Callback>& cb,
116
int modelPoints, double confidence=0.99, int maxIters=1000 );
117
118
template<typename T> inline int compressElems( T* ptr, const uchar* mask, int mstep, int count )
119
{
120
int i, j;
121
for( i = j = 0; i < count; i++ )
122
if( mask[i*mstep] )
123
{
124
if( i > j )
125
ptr[j] = ptr[i];
126
j++;
127
}
128
return j;
129
}
130
131
static inline bool haveCollinearPoints( const Mat& m, int count )
132
{
133
int j, k, i = count-1;
134
const Point2f* ptr = m.ptr<Point2f>();
135
136
// check that the i-th selected point does not belong
137
// to a line connecting some previously selected points
138
// also checks that points are not too close to each other
139
for( j = 0; j < i; j++ )
140
{
141
double dx1 = ptr[j].x - ptr[i].x;
142
double dy1 = ptr[j].y - ptr[i].y;
143
for( k = 0; k < j; k++ )
144
{
145
double dx2 = ptr[k].x - ptr[i].x;
146
double dy2 = ptr[k].y - ptr[i].y;
147
if( fabs(dx2*dy1 - dy2*dx1) <= FLT_EPSILON*(fabs(dx1) + fabs(dy1) + fabs(dx2) + fabs(dy2)))
148
return true;
149
}
150
}
151
return false;
152
}
153
154
} // namespace cv
155
156
int checkChessboard(const cv::Mat & img, const cv::Size & size);
157
int checkChessboardBinary(const cv::Mat & img, const cv::Size & size);
158
159
#endif
160
161