|
|
|
@ -792,36 +792,40 @@ void InitSolvePnpRansac() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// It's not very correct test as solvePnP and solvePnpRansac use different algorithms internally
|
|
|
|
|
// TODO add proper test after CPU solvePnpRansac being added
|
|
|
|
|
TEST(solvePnpRansac) |
|
|
|
|
{ |
|
|
|
|
InitSolvePnpRansac(); |
|
|
|
|
|
|
|
|
|
int num_points = 1000000; |
|
|
|
|
for (int num_points = 5000; num_points <= 300000; num_points = int(num_points * 3.76)) |
|
|
|
|
{ |
|
|
|
|
SUBTEST << "num_points " << num_points; |
|
|
|
|
|
|
|
|
|
Mat object; gen(object, 1, num_points, CV_32FC3, Scalar::all(0), Scalar::all(100)); |
|
|
|
|
Mat camera_mat; gen(camera_mat, 3, 3, CV_32F, 0.5, 1); |
|
|
|
|
camera_mat.at<float>(0, 1) = 0.f; |
|
|
|
|
camera_mat.at<float>(1, 0) = 0.f; |
|
|
|
|
camera_mat.at<float>(2, 0) = 0.f; |
|
|
|
|
camera_mat.at<float>(2, 1) = 0.f; |
|
|
|
|
Mat object; gen(object, 1, num_points, CV_32FC3, Scalar::all(10), Scalar::all(100)); |
|
|
|
|
Mat image; gen(image, 1, num_points, CV_32FC2, Scalar::all(10), Scalar::all(100)); |
|
|
|
|
Mat camera_mat; gen(camera_mat, 3, 3, CV_32F, 0.5, 1); |
|
|
|
|
camera_mat.at<float>(0, 1) = 0.f; |
|
|
|
|
camera_mat.at<float>(1, 0) = 0.f; |
|
|
|
|
camera_mat.at<float>(2, 0) = 0.f; |
|
|
|
|
camera_mat.at<float>(2, 1) = 0.f; |
|
|
|
|
|
|
|
|
|
Mat rvec_gold; gen(rvec_gold, 1, 3, CV_32F, 0, 1); |
|
|
|
|
Mat tvec_gold; gen(tvec_gold, 1, 3, CV_32F, 0, 1); |
|
|
|
|
Mat rvec, tvec; |
|
|
|
|
const int num_iters = 200; |
|
|
|
|
const float max_dist = 2.0f; |
|
|
|
|
vector<int> inliers_cpu; |
|
|
|
|
|
|
|
|
|
vector<Point2f> image_vec; |
|
|
|
|
projectPoints(object, rvec_gold, tvec_gold, camera_mat, Mat(), image_vec); |
|
|
|
|
Mat image(1, image_vec.size(), CV_32FC2, &image_vec[0]); |
|
|
|
|
CPU_ON; |
|
|
|
|
solvePnPRansac(object, image, camera_mat, Mat(), rvec, tvec, false, num_iters,
|
|
|
|
|
max_dist, int(num_points * 0.05), &inliers_cpu); |
|
|
|
|
CPU_OFF; |
|
|
|
|
|
|
|
|
|
Mat rvec, tvec; |
|
|
|
|
|
|
|
|
|
CPU_ON; |
|
|
|
|
solvePnP(object, image, camera_mat, Mat(), rvec, tvec); |
|
|
|
|
CPU_OFF; |
|
|
|
|
gpu::SolvePnpRansacParams params; |
|
|
|
|
params.num_iters = num_iters; |
|
|
|
|
params.max_dist = max_dist; |
|
|
|
|
vector<int> inliers_gpu; |
|
|
|
|
params.inliers = &inliers_gpu; |
|
|
|
|
|
|
|
|
|
GPU_ON; |
|
|
|
|
gpu::SolvePnpRansacParams params; |
|
|
|
|
gpu::solvePnpRansac(object, image, camera_mat, Mat(), rvec, tvec, params); |
|
|
|
|
GPU_OFF; |
|
|
|
|
GPU_ON; |
|
|
|
|
gpu::solvePnpRansac(object, image, camera_mat, Mat(), rvec, tvec, params); |
|
|
|
|
GPU_OFF; |
|
|
|
|
} |
|
|
|
|
} |