test_main.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "test_precomp.hpp"
  5. CV_TEST_MAIN("cv")
  6. namespace opencv_test { namespace {
  7. TEST(CV_Rapid, rapid)
  8. {
  9. // a unit sized box
  10. std::vector<Vec3f> vtx = {
  11. {1, -1, -1}, {1, -1, 1}, {-1, -1, 1}, {-1, -1, -1}, {1, 1, -1}, {1, 1, 1}, {-1, 1, 1}, {-1, 1, -1},
  12. };
  13. std::vector<Vec3i> tris = {
  14. {2, 4, 1}, {8, 6, 5}, {5, 2, 1}, {6, 3, 2}, {3, 8, 4}, {1, 8, 5},
  15. {2, 3, 4}, {8, 7, 6}, {5, 6, 2}, {6, 7, 3}, {3, 7, 8}, {1, 4, 8},
  16. };
  17. Mat(tris) -= Scalar(1, 1, 1);
  18. // camera setup
  19. Size sz(1280, 720);
  20. Mat K = getDefaultNewCameraMatrix(Matx33f::diag(Vec3f(800, 800, 1)), sz, true);
  21. Vec3f trans = {0, 0, 5};
  22. Vec3f rot = {0.7f, 0.6f, 0};
  23. // draw something
  24. Mat pts2d;
  25. projectPoints(vtx, rot, trans, K, noArray(), pts2d);
  26. Mat_<uchar> img(sz, uchar(0));
  27. rapid::drawWireframe(img, pts2d, tris, Scalar(255), LINE_8);
  28. // recover pose form different position
  29. Vec3f t_init = Vec3f(0.1f, 0, 5);
  30. auto tracker = rapid::Rapid::create(vtx, tris);
  31. // do two iterations
  32. TermCriteria term(TermCriteria::MAX_ITER, 2, 0);
  33. tracker->compute(img, 100, 20, K, rot, t_init, term);
  34. // assert that it improved from init
  35. ASSERT_LT(cv::norm(trans - t_init), 0.075);
  36. }
  37. }} // namespace