MCPcopy Create free account
hub / github.com/davisking/dlib / projective_transform_pass_rate

Function projective_transform_pass_rate

dlib/test/geometry.cpp:702–773  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

700// ----------------------------------------------------------------------------------------
701
702 double projective_transform_pass_rate(const double error_rate)
703 {
704 print_spinner();
705 dlog << LINFO << "projective_transform_pass_rate, error_rate: "<< error_rate;
706 dlib::rand rnd;
707 running_stats<double> pass_rate;
708 for (int rounds = 0; rounds < 1000; ++rounds)
709 {
710 running_stats<double> rs, rs_true;
711 matrix<double> H = 2*(randm(3,3,rnd)-0.5);
712
713 H(0,2) = rnd.get_random_gaussian()*10;
714 H(1,2) = rnd.get_random_gaussian()*10;
715
716
717 H(2,0) = rnd.get_random_double()*2.1;
718 H(2,1) = rnd.get_random_double()*2.1;
719 H(2,2) = 1 + rnd.get_random_gaussian()*3.1;
720
721 point_transform_projective tran(H);
722 point_transform_projective traninv = inv(tran);
723
724 const int num = rnd.get_random_32bit_number()%8 + 4;
725
726 std::vector<dlib::vector<double,2> > from_points, to_points;
727 for (int i = 0; i < num; ++i)
728 {
729 dlib::vector<double,2> p = randm(2,1,rnd)*1000;
730 from_points.push_back(p);
731 to_points.push_back(tran(p) + (randm(2,1,rnd)-0.5)*error_rate);
732 DLIB_TEST(length(traninv(tran(p))-p) <= 1e-5);
733 DLIB_TEST(length(tran(traninv(p))-p) <= 1e-5);
734
735 point_transform_projective temp = tran*traninv;
736 DLIB_TEST_MSG(max(abs(temp.get_m() - identity_matrix<double>(3))) < 1e-10, temp.get_m());
737 temp = traninv*tran;
738 DLIB_TEST_MSG(max(abs(temp.get_m() - identity_matrix<double>(3))) < 1e-10, temp.get_m());
739 }
740
741
742 point_transform_projective tran2 = find_projective_transform(from_points, to_points);
743
744 for (unsigned long i = 0; i < from_points.size(); ++i)
745 {
746 const double err = length_squared(tran2(from_points[i]) - to_points[i]);
747 rs.add(err);
748 const double err_true = length_squared(tran(from_points[i]) - to_points[i]);
749 rs_true.add(err_true);
750 }
751
752 if ( rs.mean() < 0.01)
753 {
754 pass_rate.add(1);
755 }
756 else
757 {
758 dlog << LINFO << " errors: mean/max: " << rs.mean() << " " << rs.max();
759 pass_rate.add(0);

Callers 1

perform_testMethod · 0.85

Calls 15

print_spinnerFunction · 0.85
HFunction · 0.85
absFunction · 0.85
get_random_gaussianMethod · 0.80
get_random_doubleMethod · 0.80
randmFunction · 0.70
serializeFunction · 0.70
deserializeFunction · 0.70
invFunction · 0.50
lengthFunction · 0.50

Tested by

no test coverage detected