9 # include <vcl_msvc_warnings.h> 12 #include <vnl/vnl_least_squares_function.h> 13 #include <vnl/algo/vnl_levenberg_marquardt.h> 14 #include <vnl/vnl_double_2x2.h> 23 #ifndef DOXYGEN_SHOULD_SKIP_THIS 24 class XXX :
public vnl_least_squares_function
28 const std::vector<double> &z1,z2;
30 XXX(
const std::vector<double> &z1_,std::vector<double> z2_)
31 : vnl_least_squares_function(3, z1_.size(), no_gradient)
33 , z1(z1_) , z2(std::move(z2_))
36 std::cerr <<
"N=" << N <<
'\n';
38 assert(N == z1.size());
39 assert(N == z2.size());
41 ~XXX()
override { N=0; }
43 void boo(
const vnl_vector<double> &x) {
45 std::cerr << std::showpos << std::fixed;
47 for (
unsigned i=0;i<N;i++) {
49 y=(z+x[0])/(x[1]*z+1+x[2]);
50 std::cerr << z <<
' ' << y <<
'[' << z2[i] <<
']' << std::endl;
56 void f(
const vnl_vector<double>& x, vnl_vector<double>& fx)
override {
60 for (
unsigned k=0;k<N;k++) {
62 y=(z+x[0])/(x[1]*z+1+x[2]);
67 #endif // DOXYGEN_SHOULD_SKIP_THIS 81 vnl_vector<double> x(3);
85 vnl_levenberg_marquardt LM(f);
94 T(0,0)=1; T(0,1)=x[0];
95 T(1,0)=x[1]; T(1,1)=1+x[2];
104 unsigned N=p1.size();
105 assert(N==p2.size());
106 if (N<3)
return false;
108 std::vector<double> z1(N,0.0),z2(N,0.0);
114 for (
unsigned i=0;i<N;i++) {
116 if (
v.w() == 0.0)
return false;
118 if (p2[i].w())
return false;
119 z2[i] = p2[i].x()/p2[i].w();
bool compute_cool_homg(const std::vector< vgl_homg_point_1d< double > > &points1, const std::vector< vgl_homg_point_1d< double > > &points2, vgl_h_matrix_1d< double > &H) override
A class to hold a line-to-line projective transformation matrix and to perform common operations usin...
compute the h_matrix using Levenberg-Marquardt.
vgl_h_matrix_1d & set(T const *M)
Set to 2x2 row-stored matrix.
find line-to-line projectivity from a set of matched points using SVD
bool compute(const std::vector< vgl_homg_point_1d< double > > &p1, const std::vector< vgl_homg_point_1d< double > > &p2, vgl_h_matrix_1d< double > &H)
principal interface: given point correspondences in p1,p2, returns H.
Represents a homogeneous 1-D point, i.e., a homogeneous pair (x,w).