mirror of https://github.com/opencv/opencv.git
Merge pull request #6933 from hrnr:gsoc_all
[GSOC] New camera model for stitching pipeline * implement estimateAffine2D estimates affine transformation using robust RANSAC method. * uses RANSAC framework in calib3d * includes accuracy test * uses SVD decomposition for solving 3 point equation * implement estimateAffinePartial2D estimates limited affine transformation * includes accuracy test * stitching: add affine matcher initial version of matcher that estimates affine transformation * stitching: added affine transform estimator initial version of estimator that simply chain transformations in homogeneous coordinates * calib3d: rename estimateAffine3D test test Calib3d_EstimateAffineTransform rename to Calib3d_EstimateAffine3D. This is more descriptive and prevents confusion with estimateAffine2D tests. * added perf test for estimateAffine functions tests both estimateAffine2D and estimateAffinePartial2D * calib3d: compare error in square in estimateAffine2D * incorporates fix from #6768 * rerun affine estimation on inliers * stitching: new API for parallel feature finding due to ABI breakage new functionality is added to `FeaturesFinder2`, `SurfFeaturesFinder2` and `OrbFeaturesFinder2` * stitching: add tests for parallel feature find API * perf test (about linear speed up) * accuracy test compares results with serial version * stitching: use dynamic_cast to overcome ABI issues adding parallel API to FeaturesFinder breaks ABI. This commit uses dynamic_cast and hardcodes thread-safe finders to avoid breaking ABI. This should be replaced by proper method similar to FeaturesMatcher on next ABI break. * use estimateAffinePartial2D in AffineBestOf2NearestMatcher * add constructor to AffineBestOf2NearestMatcher * allows to choose between full affine transform and partial affine transform. Other params are the as for BestOf2NearestMatcher * added protected field * samples: stitching_detailed support affine estimator and matcher * added new flags to choose matcher and estimator * stitching: rework affine matcher represent transformation in homogeneous coordinates affine matcher: remove duplicite code rework flow to get rid of duplicite code affine matcher: do not center points to (0, 0) it is not needed for affine model. it should not affect estimation in any way. affine matcher: remove unneeded cv namespacing * stitching: add stub bundle adjuster * adds stub bundle adjuster that does nothing * can be used in place of standard bundle adjusters to omit bundle adjusting step * samples: stitching detailed, support no budle adjust * uses new NoBundleAdjuster * added affine warper * uses R to get whole affine transformation and propagates rotation and translation to plane warper * add affine warper factory class * affine warper: compensate transformation * samples: stitching_detailed add support for affine warper * add Stitcher::create method this method follows similar constructor methods and returns smart pointer. This allows constructing Stitcher according to OpenCV guidelines. * supports multiple stitcher configurations (PANORAMA and SCANS) for convenient setup * returns cv::Ptr * stitcher: dynamicaly determine correct estimator we need to use affine estimator for affine matcher * preserves ABI (but add hints for ABI 4) * uses dynamic_cast hack to inject correct estimator * sample stitching: add support for multiple modes shows how to use different configurations of stitcher easily (panorama stitching and scans affine model) * stitcher: find features in parallel use new FeatureFinder API to find features in parallel. Parallelized using TBB. * stitching: disable parallel feature finding for OCL it does not bring much speedup to run features finder in parallel when OpenCL is enabled, because finder needs to wait for OCL device. Also, currently ORB is not thread-safe when OCL is enabled. * stitching: move matcher tests move matchers tests perf_stich.cpp -> perf_matchers.cpp * stitching: add affine stiching integration test test basic affine stitching (SCANS mode of stitcher) with images that have only translation between them * enable surf for stitching tests stitching.b12 test was failing with surf investigated the issue, surf is producing good result. Transformation is only slightly different from ORB, so that resulting pano does not exactly match ORB's result. That caused sanity check to fail. * added size checks similar to other tests * sanity check will be applied only for ORB * stitching: fix wrong estimator choice if case was exactly wrong, estimators were chosen wrong added logging for estimated transformation * enable surf for matchers stitching tests * enable SURF * rework sanity checking. Check estimated transform instead of matches. Est. transform should be more stable and comparable between SURF and ORB. * remove regression checking for VectorFeatures tests. It has a lot if data andtest is the same as previous except it test different vector size for performance, so sanity checking does not add any value here. Added basic sanity asserts instead. * stitching tests: allow relative error for transform * allows .01 relative error for estimated homography sanity check in stitching matchers tests * fix VS warning stitching tests: increase relative error increase relative error to make it pass on all platforms (results are still good). stitching test: allow bigger relative error transformation can differ in small values (with small absolute difference, but large relative difference). transformation output still looks usable for all platforms. This difference affects only mac and windows, linux passes fine with small difference. * stitching: add tests for affine matcher uses s1, s2 images. added also new sanity data. * stitching tests: use different data for matchers tests this data should yeild more stable transformation (it has much more matches, especially for surf). Sanity data regenerated. * stitching test: rework tests for matchers * separated rotation and translations as they are different by scale. * use appropriate absolute error for them separately. (relative error does not work for values near zero.) * stitching: fix affine warper compensation calculation of rotation and translation extracted for plane warper was wrong * stitching test: enable surf for opencl integration tests * enable SURF with correct guard (HAVE_OPENCV_XFEATURES2D) * add OPENCL guard and correct namespace as usual for opencl tests * stitching: add ocl accuracy test for affine warper test consistent results with ocl on and off * stitching: add affine warper ocl perf test add affine warper to existing warper perf tests. Added new sanity data. * stitching: do not overwrite inliers in affine matcher * estimation is run second time on inliers only, inliers produces in second run will not be therefore correct for all matches * calib3d: add Levenberg–Marquardt refining to estimateAffine2D* functions this adds affine Levenberg–Marquardt refining to estimateAffine2D functions similar to what is done in findHomography. implements Levenberg–Marquardt refinig for both full affine and partial affine transformations. * stitching: remove reestimation step in affine matcher reestimation step is not needed. estimateAffine2D* functions are running their own reestimation on inliers using the Levenberg-Marquardt algorithm, which is better than simply rerunning RANSAC on inliers. * implement partial affine bundle adjuster bundle adjuster that expect affine transform with 4DOF. Refines parameters for all cameras together. stitching: fix bug in BundleAdjusterAffinePartial * use the invers properly * use static buffer for invers to speed it up * samples: add affine bundle adjuster option to stitching_detailed * add support for using affine bundle adjuster with 4DOF * improve logging of initial intristics * sttiching: add affine bundle adjuster test * fix build warnings * stitching: increase limit on sanity check prevents spurious test failures on mac. values are still pretty fine. * stitching: set affine bundle adjuster for SCANS mode * fix bug with AffineBestOf2NearestMatcher (we want to select affine partial mode) * select right bundle adjuster * stitching: increase error bound for matcher tests * this prevents failure on mac. tranformation is still ok. * stitching: implement affine bundle adjuster * implements affine bundle adjuster that is using full affine transform * existing test case modified to test both affinePartial an full affine bundle adjuster * add stitching tutorial * show basic usage of stitching api (Stitcher class) * stitching: add more integration test for affine stitching * added new datasets to existing testcase * removed unused include * calib3d: move `haveCollinearPoints` to common header * added comment to make that this also checks too close points * calib3d: redone checkSubset for estimateAffine* callback * use common function to check collinearity * this also ensures that point will not be too close to each other * calib3d: change estimateAffine* functions API * more similar to `findHomography`, `findFundamentalMat`, `findEssentialMat` and similar * follows standard recommended semantic INPUTS, OUTPUTS, FLAGS * allows to disable refining * supported LMEDS robust method (tests yet to come) along with RANSAC * extended docs with some tips * calib3d: rewrite estimateAffine2D test * rewrite in googletest style * parametrize to test both robust methods (RANSAC and LMEDS) * get rid of boilerplate * calib3d: rework estimateAffinePartial2D test * rework in googletest style * add testing for LMEDS * calib3d: rework estimateAffine*2D perf test * test for LMEDS speed * test with/without Levenberg-Marquart * remove sanity checking (this is covered by accuracy tests) * calib3d: improve estimateAffine*2D tests * test transformations in loop * improves test by testing more potential transformations * calib3d: rewrite kernels for estimateAffine*2D functions * use analytical solution instead of SVD * this version is faster especially for smaller amount of points * calib3d: tune up perf of estimateAffine*2D functions * avoid copying inliers * avoid converting input points if not necessary * check only `from` point for collinearity, as `to` does not affect stability of transform * tutorials: add commands examples to stitching tutorials * add some examples how to run stitcher sample code * mention stitching_detailed.cpp * calib3d: change computeError for estimateAffine*2D * do error computing in floats instead of doubles this have required precision + we were storing the result in float anyway. This make code faster and allows auto-vectorization by smart compilers. * documentation: mention estimateAffine*2D function * refer to new functions on appropriate places * prefer estimateAffine*2D over estimateRigidTransform * stitching: add camera models documentations * mention camera models in module documentation to give user a better overview and reduce confusionpull/7545/head
parent
e77bc24b96
commit
c17afe0fab
34 changed files with 2479 additions and 166 deletions
After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 126 KiB |
@ -0,0 +1,115 @@ |
||||
High level stitching API (Stitcher class) {#tutorial_stitcher} |
||||
========================================= |
||||
|
||||
Goal |
||||
---- |
||||
|
||||
In this tutorial you will learn how to: |
||||
|
||||
- use the high-level stitching API for stitching provided by |
||||
- @ref cv::Stitcher |
||||
- learn how to use preconfigured Stitcher configurations to stitch images |
||||
using different camera models. |
||||
|
||||
Code |
||||
---- |
||||
|
||||
This tutorial code's is shown lines below. You can also download it from |
||||
[here](https://github.com/opencv/opencv/tree/master/samples/cpp/samples/cpp/stitching.cpp). |
||||
|
||||
@include samples/cpp/stitching.cpp |
||||
|
||||
Explanation |
||||
----------- |
||||
|
||||
The most important code part is: |
||||
|
||||
@code{.cpp} |
||||
Mat pano; |
||||
Ptr<Stitcher> stitcher = Stitcher::create(mode, try_use_gpu); |
||||
Stitcher::Status status = stitcher->stitch(imgs, pano); |
||||
|
||||
if (status != Stitcher::OK) |
||||
{ |
||||
cout << "Can't stitch images, error code = " << int(status) << endl; |
||||
return -1; |
||||
} |
||||
@endcode |
||||
|
||||
A new instance of stitcher is created and the @ref cv::Stitcher::stitch will |
||||
do all the hard work. |
||||
|
||||
@ref cv::Stitcher::create can create stitcher in one of the predefined |
||||
configurations (argument `mode`). See @ref cv::Stitcher::Mode for details. These |
||||
configurations will setup multiple stitcher properties to operate in one of |
||||
predefined scenarios. After you create stitcher in one of predefined |
||||
configurations you can adjust stitching by setting any of the stitcher |
||||
properties. |
||||
|
||||
If you have cuda device @ref cv::Stitcher can be configured to offload certain |
||||
operations to GPU. If you prefer this configuration set `try_use_gpu` to true. |
||||
OpenCL acceleration will be used transparently based on global OpenCV settings |
||||
regardless of this flag. |
||||
|
||||
Stitching might fail for several reasons, you should always check if |
||||
everything went good and resulting pano is stored in `pano`. See |
||||
@ref cv::Stitcher::Status documentation for possible error codes. |
||||
|
||||
Camera models |
||||
------------- |
||||
|
||||
There are currently 2 camera models implemented in stitching pipeline. |
||||
|
||||
- _Homography model_ expecting perspective transformations between images |
||||
implemented in @ref cv::detail::BestOf2NearestMatcher cv::detail::HomographyBasedEstimator |
||||
cv::detail::BundleAdjusterReproj cv::detail::BundleAdjusterRay |
||||
- _Affine model_ expecting affine transformation with 6 DOF or 4 DOF implemented in |
||||
@ref cv::detail::AffineBestOf2NearestMatcher cv::detail::AffineBasedEstimator |
||||
cv::detail::BundleAdjusterAffine cv::detail::BundleAdjusterAffinePartial cv::AffineWarper |
||||
|
||||
Homography model is useful for creating photo panoramas captured by camera, |
||||
while affine-based model can be used to stitch scans and object captured by |
||||
specialized devices. |
||||
|
||||
@note |
||||
Certain detailed settings of @ref cv::Stitcher might not make sense. Especially |
||||
you should not mix classes implementing affine model and classes implementing |
||||
Homography model, as they work with different transformations. |
||||
|
||||
Try it out |
||||
---------- |
||||
|
||||
If you enabled building samples you can found binary under |
||||
`build/bin/cpp-example-stitching`. This example is a console application, run it without |
||||
arguments to see help. `opencv_extra` provides some sample data for testing all available |
||||
configurations. |
||||
|
||||
to try panorama mode run: |
||||
``` |
||||
./cpp-example-stitching --mode panorama <path to opencv_extra>/testdata/stitching/boat* |
||||
``` |
||||
 |
||||
|
||||
to try scans mode run (dataset from home-grade scanner): |
||||
``` |
||||
./cpp-example-stitching --mode scans <path to opencv_extra>/testdata/stitching/newspaper* |
||||
``` |
||||
 |
||||
|
||||
or (dataset from professional book scanner): |
||||
``` |
||||
./cpp-example-stitching --mode scans <path to opencv_extra>/testdata/stitching/budapest* |
||||
``` |
||||
 |
||||
|
||||
@note |
||||
Examples above expects POSIX platform, on windows you have to provide all files names explicitly |
||||
(e.g. `boat1.jpg` `boat2.jpg`...) as windows command line does not support `*` expansion. |
||||
|
||||
See also |
||||
-------- |
||||
|
||||
If you want to study internals of the stitching pipeline or you want to experiment with detailed |
||||
configuration see |
||||
[stitching_detailed.cpp](https://github.com/opencv/opencv/tree/master/samples/cpp/stitching_detailed.cpp) |
||||
in `opencv/samples/cpp` folder. |
@ -0,0 +1,15 @@ |
||||
Images stitching (stitching module) {#tutorial_table_of_content_stitching} |
||||
=================================== |
||||
|
||||
Sometimes a single image can't capture it all. Here you will learn how to join |
||||
more images together to create a large pano. Doesn't matter if you want to |
||||
create a photo panorama or you want to stitch scans. |
||||
|
||||
- @subpage tutorial_stitcher |
||||
|
||||
*Compatibility:* \>= OpenCV 3.2 |
||||
|
||||
*Author:* Jiri Horner |
||||
|
||||
You will use high level stitching api to create a photo panorama. You will |
||||
learn about Stitcher class and its configurations. |
@ -0,0 +1,170 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
// (3-clause BSD License)
|
||||
//
|
||||
// Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the names of the copyright holders nor the names of the contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall copyright holders or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "perf_precomp.hpp" |
||||
#include <algorithm> |
||||
#include <functional> |
||||
|
||||
namespace cvtest |
||||
{ |
||||
|
||||
using std::tr1::tuple; |
||||
using std::tr1::get; |
||||
using namespace perf; |
||||
using namespace testing; |
||||
using namespace cv; |
||||
|
||||
CV_ENUM(Method, RANSAC, LMEDS) |
||||
typedef tuple<int, double, Method, size_t> AffineParams; |
||||
typedef TestBaseWithParam<AffineParams> EstimateAffine; |
||||
#define ESTIMATE_PARAMS Combine(Values(100000, 5000, 100), Values(0.99, 0.95, 0.9), Method::all(), Values(10, 0)) |
||||
|
||||
static float rngIn(float from, float to) { return from + (to-from) * (float)theRNG(); } |
||||
|
||||
static Mat rngPartialAffMat() { |
||||
double theta = rngIn(0, (float)CV_PI*2.f); |
||||
double scale = rngIn(0, 3); |
||||
double tx = rngIn(-2, 2); |
||||
double ty = rngIn(-2, 2); |
||||
double aff[2*3] = { std::cos(theta) * scale, -std::sin(theta) * scale, tx, |
||||
std::sin(theta) * scale, std::cos(theta) * scale, ty }; |
||||
return Mat(2, 3, CV_64F, aff).clone(); |
||||
} |
||||
|
||||
PERF_TEST_P( EstimateAffine, EstimateAffine2D, ESTIMATE_PARAMS ) |
||||
{ |
||||
AffineParams params = GetParam(); |
||||
const int n = get<0>(params); |
||||
const double confidence = get<1>(params); |
||||
const int method = get<2>(params); |
||||
const size_t refining = get<3>(params); |
||||
|
||||
Mat aff(2, 3, CV_64F); |
||||
cv::randu(aff, -2., 2.); |
||||
|
||||
// LMEDS can't handle more than 50% outliers (by design)
|
||||
int m; |
||||
if (method == LMEDS) |
||||
m = 3*n/5; |
||||
else |
||||
m = 2*n/5; |
||||
const float shift_outl = 15.f; |
||||
const float noise_level = 20.f; |
||||
|
||||
Mat fpts(1, n, CV_32FC2); |
||||
Mat tpts(1, n, CV_32FC2); |
||||
|
||||
randu(fpts, 0., 100.); |
||||
transform(fpts, tpts, aff); |
||||
|
||||
/* adding noise to some points */ |
||||
Mat outliers = tpts.colRange(m, n); |
||||
outliers.reshape(1) += shift_outl; |
||||
|
||||
Mat noise (outliers.size(), outliers.type()); |
||||
randu(noise, 0., noise_level); |
||||
outliers += noise; |
||||
|
||||
Mat aff_est; |
||||
vector<uchar> inliers (n); |
||||
|
||||
warmup(inliers, WARMUP_WRITE); |
||||
warmup(fpts, WARMUP_READ); |
||||
warmup(tpts, WARMUP_READ); |
||||
|
||||
TEST_CYCLE() |
||||
{ |
||||
aff_est = estimateAffine2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining); |
||||
} |
||||
|
||||
// we already have accuracy tests
|
||||
SANITY_CHECK_NOTHING(); |
||||
} |
||||
|
||||
PERF_TEST_P( EstimateAffine, EstimateAffinePartial2D, ESTIMATE_PARAMS ) |
||||
{ |
||||
AffineParams params = GetParam(); |
||||
const int n = get<0>(params); |
||||
const double confidence = get<1>(params); |
||||
const int method = get<2>(params); |
||||
const size_t refining = get<3>(params); |
||||
|
||||
Mat aff = rngPartialAffMat(); |
||||
|
||||
int m; |
||||
// LMEDS can't handle more than 50% outliers (by design)
|
||||
if (method == LMEDS) |
||||
m = 3*n/5; |
||||
else |
||||
m = 2*n/5; |
||||
const float shift_outl = 15.f; const float noise_level = 20.f; |
||||
|
||||
Mat fpts(1, n, CV_32FC2); |
||||
Mat tpts(1, n, CV_32FC2); |
||||
|
||||
randu(fpts, 0., 100.); |
||||
transform(fpts, tpts, aff); |
||||
|
||||
/* adding noise*/ |
||||
Mat outliers = tpts.colRange(m, n); |
||||
outliers.reshape(1) += shift_outl; |
||||
|
||||
Mat noise (outliers.size(), outliers.type()); |
||||
randu(noise, 0., noise_level); |
||||
outliers += noise; |
||||
|
||||
Mat aff_est; |
||||
vector<uchar> inliers (n); |
||||
|
||||
warmup(inliers, WARMUP_WRITE); |
||||
warmup(fpts, WARMUP_READ); |
||||
warmup(tpts, WARMUP_READ); |
||||
|
||||
TEST_CYCLE() |
||||
{ |
||||
aff_est = estimateAffinePartial2D(fpts, tpts, inliers, method, 3, 2000, confidence, refining); |
||||
} |
||||
|
||||
// we already have accuracy tests
|
||||
SANITY_CHECK_NOTHING(); |
||||
} |
||||
|
||||
} // namespace cvtest
|
@ -0,0 +1,130 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
// (3-clause BSD License)
|
||||
//
|
||||
// Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the names of the copyright holders nor the names of the contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall copyright holders or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
using namespace testing; |
||||
|
||||
#include <vector> |
||||
#include <numeric> |
||||
|
||||
CV_ENUM(Method, RANSAC, LMEDS) |
||||
typedef TestWithParam<Method> EstimateAffine2D; |
||||
|
||||
static float rngIn(float from, float to) { return from + (to-from) * (float)theRNG(); } |
||||
|
||||
TEST_P(EstimateAffine2D, test3Points) |
||||
{ |
||||
// try more transformations
|
||||
for (size_t i = 0; i < 500; ++i) |
||||
{ |
||||
Mat aff(2, 3, CV_64F); |
||||
cv::randu(aff, 1., 3.); |
||||
|
||||
Mat fpts(1, 3, CV_32FC2); |
||||
Mat tpts(1, 3, CV_32FC2); |
||||
|
||||
// setting points that are not in the same line
|
||||
fpts.at<Point2f>(0) = Point2f( rngIn(1,2), rngIn(5,6) ); |
||||
fpts.at<Point2f>(1) = Point2f( rngIn(3,4), rngIn(3,4) ); |
||||
fpts.at<Point2f>(2) = Point2f( rngIn(1,2), rngIn(3,4) ); |
||||
|
||||
transform(fpts, tpts, aff); |
||||
|
||||
vector<uchar> inliers; |
||||
Mat aff_est = estimateAffine2D(fpts, tpts, inliers, GetParam() /* method */); |
||||
|
||||
EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-3); |
||||
|
||||
// all must be inliers
|
||||
EXPECT_EQ(countNonZero(inliers), 3); |
||||
} |
||||
} |
||||
|
||||
TEST_P(EstimateAffine2D, testNPoints) |
||||
{ |
||||
// try more transformations
|
||||
for (size_t i = 0; i < 500; ++i) |
||||
{ |
||||
Mat aff(2, 3, CV_64F); |
||||
cv::randu(aff, -2., 2.); |
||||
const int method = GetParam(); |
||||
const int n = 100; |
||||
int m; |
||||
// LMEDS can't handle more than 50% outliers (by design)
|
||||
if (method == LMEDS) |
||||
m = 3*n/5; |
||||
else |
||||
m = 2*n/5; |
||||
const float shift_outl = 15.f; |
||||
const float noise_level = 20.f; |
||||
|
||||
Mat fpts(1, n, CV_32FC2); |
||||
Mat tpts(1, n, CV_32FC2); |
||||
|
||||
randu(fpts, 0., 100.); |
||||
transform(fpts, tpts, aff); |
||||
|
||||
/* adding noise to some points */ |
||||
Mat outliers = tpts.colRange(m, n); |
||||
outliers.reshape(1) += shift_outl; |
||||
|
||||
Mat noise (outliers.size(), outliers.type()); |
||||
randu(noise, 0., noise_level); |
||||
outliers += noise; |
||||
|
||||
vector<uchar> inliers; |
||||
Mat aff_est = estimateAffine2D(fpts, tpts, inliers, method); |
||||
|
||||
EXPECT_FALSE(aff_est.empty()) << "estimation failed, unable to estimate transform"; |
||||
|
||||
EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-4); |
||||
|
||||
bool inliers_good = count(inliers.begin(), inliers.end(), 1) == m && |
||||
m == accumulate(inliers.begin(), inliers.begin() + m, 0); |
||||
|
||||
EXPECT_TRUE(inliers_good); |
||||
} |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(Calib3d, EstimateAffine2D, Method::all()); |
@ -0,0 +1,140 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
// (3-clause BSD License)
|
||||
//
|
||||
// Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the names of the copyright holders nor the names of the contributors
|
||||
// may be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall copyright holders or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
using namespace testing; |
||||
|
||||
#include <vector> |
||||
#include <numeric> |
||||
|
||||
CV_ENUM(Method, RANSAC, LMEDS) |
||||
typedef TestWithParam<Method> EstimateAffinePartial2D; |
||||
|
||||
static float rngIn(float from, float to) { return from + (to-from) * (float)theRNG(); } |
||||
|
||||
// get random matrix of affine transformation limited to combinations of translation,
|
||||
// rotation, and uniform scaling
|
||||
static Mat rngPartialAffMat() { |
||||
double theta = rngIn(0, (float)CV_PI*2.f); |
||||
double scale = rngIn(0, 3); |
||||
double tx = rngIn(-2, 2); |
||||
double ty = rngIn(-2, 2); |
||||
double aff[2*3] = { std::cos(theta) * scale, -std::sin(theta) * scale, tx, |
||||
std::sin(theta) * scale, std::cos(theta) * scale, ty }; |
||||
return Mat(2, 3, CV_64F, aff).clone(); |
||||
} |
||||
|
||||
TEST_P(EstimateAffinePartial2D, test2Points) |
||||
{ |
||||
// try more transformations
|
||||
for (size_t i = 0; i < 500; ++i) |
||||
{ |
||||
Mat aff = rngPartialAffMat(); |
||||
|
||||
// setting points that are no in the same line
|
||||
Mat fpts(1, 2, CV_32FC2); |
||||
Mat tpts(1, 2, CV_32FC2); |
||||
|
||||
fpts.at<Point2f>(0) = Point2f( rngIn(1,2), rngIn(5,6) ); |
||||
fpts.at<Point2f>(1) = Point2f( rngIn(3,4), rngIn(3,4) ); |
||||
|
||||
transform(fpts, tpts, aff); |
||||
|
||||
vector<uchar> inliers; |
||||
Mat aff_est = estimateAffinePartial2D(fpts, tpts, inliers, GetParam() /* method */); |
||||
|
||||
EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-3); |
||||
|
||||
// all must be inliers
|
||||
EXPECT_EQ(countNonZero(inliers), 2); |
||||
} |
||||
} |
||||
|
||||
TEST_P(EstimateAffinePartial2D, testNPoints) |
||||
{ |
||||
// try more transformations
|
||||
for (size_t i = 0; i < 500; ++i) |
||||
{ |
||||
Mat aff = rngPartialAffMat(); |
||||
|
||||
const int method = GetParam(); |
||||
const int n = 100; |
||||
int m; |
||||
// LMEDS can't handle more than 50% outliers (by design)
|
||||
if (method == LMEDS) |
||||
m = 3*n/5; |
||||
else |
||||
m = 2*n/5; |
||||
const float shift_outl = 15.f; |
||||
const float noise_level = 20.f; |
||||
|
||||
Mat fpts(1, n, CV_32FC2); |
||||
Mat tpts(1, n, CV_32FC2); |
||||
|
||||
randu(fpts, 0., 100.); |
||||
transform(fpts, tpts, aff); |
||||
|
||||
/* adding noise to some points */ |
||||
Mat outliers = tpts.colRange(m, n); |
||||
outliers.reshape(1) += shift_outl; |
||||
|
||||
Mat noise (outliers.size(), outliers.type()); |
||||
randu(noise, 0., noise_level); |
||||
outliers += noise; |
||||
|
||||
vector<uchar> inliers; |
||||
Mat aff_est = estimateAffinePartial2D(fpts, tpts, inliers, method); |
||||
|
||||
EXPECT_FALSE(aff_est.empty()); |
||||
|
||||
EXPECT_NEAR(0., cvtest::norm(aff_est, aff, NORM_INF), 1e-4); |
||||
|
||||
bool inliers_good = count(inliers.begin(), inliers.end(), 1) == m && |
||||
m == accumulate(inliers.begin(), inliers.begin() + m, 0); |
||||
|
||||
EXPECT_TRUE(inliers_good); |
||||
} |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(Calib3d, EstimateAffinePartial2D, Method::all()); |
@ -0,0 +1,100 @@ |
||||
#include "perf_precomp.hpp" |
||||
#include "opencv2/imgcodecs.hpp" |
||||
#include "opencv2/opencv_modules.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace perf; |
||||
using std::tr1::tuple; |
||||
using std::tr1::get; |
||||
|
||||
typedef TestBaseWithParam<tuple<string, string> > bundleAdjuster; |
||||
|
||||
#ifdef HAVE_OPENCV_XFEATURES2D |
||||
#define TEST_DETECTORS testing::Values("surf", "orb") |
||||
#else |
||||
#define TEST_DETECTORS testing::Values<string>("orb") |
||||
#endif |
||||
#define WORK_MEGAPIX 0.6 |
||||
#define AFFINE_FUNCTIONS testing::Values("affinePartial", "affine") |
||||
|
||||
PERF_TEST_P(bundleAdjuster, affine, testing::Combine(TEST_DETECTORS, AFFINE_FUNCTIONS)) |
||||
{ |
||||
Mat img1, img1_full = imread(getDataPath("stitching/s1.jpg")); |
||||
Mat img2, img2_full = imread(getDataPath("stitching/s2.jpg")); |
||||
float scale1 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img1_full.total())); |
||||
float scale2 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img2_full.total())); |
||||
resize(img1_full, img1, Size(), scale1, scale1); |
||||
resize(img2_full, img2, Size(), scale2, scale2); |
||||
|
||||
string detector = get<0>(GetParam()); |
||||
string affine_fun = get<1>(GetParam()); |
||||
|
||||
Ptr<detail::FeaturesFinder> finder; |
||||
Ptr<detail::FeaturesMatcher> matcher; |
||||
Ptr<detail::BundleAdjusterBase> bundle_adjuster; |
||||
if (detector == "surf") |
||||
finder = makePtr<detail::SurfFeaturesFinder>(); |
||||
else if (detector == "orb") |
||||
finder = makePtr<detail::OrbFeaturesFinder>(); |
||||
if (affine_fun == "affinePartial") |
||||
{ |
||||
matcher = makePtr<detail::AffineBestOf2NearestMatcher>(false); |
||||
bundle_adjuster = makePtr<detail::BundleAdjusterAffinePartial>(); |
||||
} |
||||
else if (affine_fun == "affine") |
||||
{ |
||||
matcher = makePtr<detail::AffineBestOf2NearestMatcher>(true); |
||||
bundle_adjuster = makePtr<detail::BundleAdjusterAffine>(); |
||||
} |
||||
Ptr<detail::Estimator> estimator = makePtr<detail::AffineBasedEstimator>(); |
||||
|
||||
std::vector<Mat> images; |
||||
images.push_back(img1), images.push_back(img2); |
||||
std::vector<detail::ImageFeatures> features; |
||||
std::vector<detail::MatchesInfo> pairwise_matches; |
||||
std::vector<detail::CameraParams> cameras; |
||||
std::vector<detail::CameraParams> cameras2; |
||||
|
||||
(*finder)(images, features); |
||||
(*matcher)(features, pairwise_matches); |
||||
if (!(*estimator)(features, pairwise_matches, cameras)) |
||||
FAIL() << "estimation failed. this should never happen."; |
||||
// this is currently required
|
||||
for (size_t i = 0; i < cameras.size(); ++i) |
||||
{ |
||||
Mat R; |
||||
cameras[i].R.convertTo(R, CV_32F); |
||||
cameras[i].R = R; |
||||
} |
||||
|
||||
cameras2 = cameras; |
||||
bool success = true; |
||||
while(next()) |
||||
{ |
||||
cameras = cameras2; // revert cameras back to original initial guess
|
||||
startTimer(); |
||||
success = (*bundle_adjuster)(features, pairwise_matches, cameras); |
||||
stopTimer(); |
||||
} |
||||
|
||||
EXPECT_TRUE(success); |
||||
EXPECT_TRUE(cameras.size() == 2); |
||||
|
||||
// fist camera should be just identity
|
||||
Mat &first = cameras[0].R; |
||||
SANITY_CHECK(first, 1e-3, ERROR_ABSOLUTE); |
||||
// second camera should be the estimated transform between images
|
||||
// separate rotation and translation in transform matrix
|
||||
Mat T_second (cameras[1].R, Range(0, 2), Range(2, 3)); |
||||
Mat R_second (cameras[1].R, Range(0, 2), Range(0, 2)); |
||||
Mat h (cameras[1].R, Range(2, 3), Range::all()); |
||||
SANITY_CHECK(T_second, 5, ERROR_ABSOLUTE); // allow 5 pixels diff in translations
|
||||
SANITY_CHECK(R_second, .01, ERROR_ABSOLUTE); // rotations must be more precise
|
||||
// last row should be precisely (0, 0, 1) as it is just added for representation in homogeneous
|
||||
// coordinates
|
||||
EXPECT_TRUE(h.type() == CV_32F); |
||||
EXPECT_FLOAT_EQ(h.at<float>(0), 0.f); |
||||
EXPECT_FLOAT_EQ(h.at<float>(1), 0.f); |
||||
EXPECT_FLOAT_EQ(h.at<float>(2), 1.f); |
||||
} |
@ -0,0 +1,301 @@ |
||||
#include "perf_precomp.hpp" |
||||
#include "opencv2/imgcodecs.hpp" |
||||
#include "opencv2/opencv_modules.hpp" |
||||
#include "opencv2/flann.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace perf; |
||||
using std::tr1::make_tuple; |
||||
using std::tr1::get; |
||||
|
||||
typedef TestBaseWithParam<size_t> FeaturesFinderVec; |
||||
typedef TestBaseWithParam<string> match; |
||||
typedef std::tr1::tuple<string, int> matchVector_t; |
||||
typedef TestBaseWithParam<matchVector_t> matchVector; |
||||
|
||||
#define NUMBER_IMAGES testing::Values(1, 5, 20) |
||||
#define SURF_MATCH_CONFIDENCE 0.65f |
||||
#define ORB_MATCH_CONFIDENCE 0.3f |
||||
#define WORK_MEGAPIX 0.6 |
||||
|
||||
#ifdef HAVE_OPENCV_XFEATURES2D |
||||
#define TEST_DETECTORS testing::Values("surf", "orb") |
||||
#else |
||||
#define TEST_DETECTORS testing::Values<string>("orb") |
||||
#endif |
||||
|
||||
PERF_TEST_P(FeaturesFinderVec, ParallelFeaturesFinder, NUMBER_IMAGES) |
||||
{ |
||||
Mat img = imread( getDataPath("stitching/a1.png") ); |
||||
vector<Mat> imgs(GetParam(), img); |
||||
vector<detail::ImageFeatures> features(imgs.size()); |
||||
|
||||
Ptr<detail::FeaturesFinder> featuresFinder = makePtr<detail::OrbFeaturesFinder>(); |
||||
|
||||
TEST_CYCLE() |
||||
{ |
||||
(*featuresFinder)(imgs, features); |
||||
} |
||||
|
||||
SANITY_CHECK_NOTHING(); |
||||
} |
||||
|
||||
PERF_TEST_P(FeaturesFinderVec, SerialFeaturesFinder, NUMBER_IMAGES) |
||||
{ |
||||
Mat img = imread( getDataPath("stitching/a1.png") ); |
||||
vector<Mat> imgs(GetParam(), img); |
||||
vector<detail::ImageFeatures> features(imgs.size()); |
||||
|
||||
Ptr<detail::FeaturesFinder> featuresFinder = makePtr<detail::OrbFeaturesFinder>(); |
||||
|
||||
TEST_CYCLE() |
||||
{ |
||||
for (size_t i = 0; i < imgs.size(); ++i) |
||||
(*featuresFinder)(imgs[i], features[i]); |
||||
} |
||||
|
||||
SANITY_CHECK_NOTHING(); |
||||
} |
||||
|
||||
PERF_TEST_P( match, bestOf2Nearest, TEST_DETECTORS) |
||||
{ |
||||
Mat img1, img1_full = imread( getDataPath("stitching/boat1.jpg") ); |
||||
Mat img2, img2_full = imread( getDataPath("stitching/boat2.jpg") ); |
||||
float scale1 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img1_full.total())); |
||||
float scale2 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img2_full.total())); |
||||
resize(img1_full, img1, Size(), scale1, scale1); |
||||
resize(img2_full, img2, Size(), scale2, scale2); |
||||
|
||||
Ptr<detail::FeaturesFinder> finder; |
||||
Ptr<detail::FeaturesMatcher> matcher; |
||||
if (GetParam() == "surf") |
||||
{ |
||||
finder = makePtr<detail::SurfFeaturesFinder>(); |
||||
matcher = makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE); |
||||
} |
||||
else if (GetParam() == "orb") |
||||
{ |
||||
finder = makePtr<detail::OrbFeaturesFinder>(); |
||||
matcher = makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE); |
||||
} |
||||
else |
||||
{ |
||||
FAIL() << "Unknown 2D features type: " << GetParam(); |
||||
} |
||||
|
||||
detail::ImageFeatures features1, features2; |
||||
(*finder)(img1, features1); |
||||
(*finder)(img2, features2); |
||||
|
||||
detail::MatchesInfo pairwise_matches; |
||||
|
||||
declare.in(features1.descriptors, features2.descriptors); |
||||
|
||||
while(next()) |
||||
{ |
||||
cvflann::seed_random(42);//for predictive FlannBasedMatcher
|
||||
startTimer(); |
||||
(*matcher)(features1, features2, pairwise_matches); |
||||
stopTimer(); |
||||
matcher->collectGarbage(); |
||||
} |
||||
|
||||
Mat dist (pairwise_matches.H, Range::all(), Range(2, 3)); |
||||
Mat R (pairwise_matches.H, Range::all(), Range(0, 2)); |
||||
// separate transform matrix, use lower error on rotations
|
||||
SANITY_CHECK(dist, 1., ERROR_ABSOLUTE); |
||||
SANITY_CHECK(R, .015, ERROR_ABSOLUTE); |
||||
} |
||||
|
||||
PERF_TEST_P( matchVector, bestOf2NearestVectorFeatures, testing::Combine( |
||||
TEST_DETECTORS, |
||||
testing::Values(2, 4, 8)) |
||||
) |
||||
{ |
||||
Mat img1, img1_full = imread( getDataPath("stitching/boat1.jpg") ); |
||||
Mat img2, img2_full = imread( getDataPath("stitching/boat2.jpg") ); |
||||
float scale1 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img1_full.total())); |
||||
float scale2 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img2_full.total())); |
||||
resize(img1_full, img1, Size(), scale1, scale1); |
||||
resize(img2_full, img2, Size(), scale2, scale2); |
||||
|
||||
Ptr<detail::FeaturesFinder> finder; |
||||
Ptr<detail::FeaturesMatcher> matcher; |
||||
string detectorName = get<0>(GetParam()); |
||||
int featuresVectorSize = get<1>(GetParam()); |
||||
if (detectorName == "surf") |
||||
{ |
||||
finder = makePtr<detail::SurfFeaturesFinder>(); |
||||
matcher = makePtr<detail::BestOf2NearestMatcher>(false, SURF_MATCH_CONFIDENCE); |
||||
} |
||||
else if (detectorName == "orb") |
||||
{ |
||||
finder = makePtr<detail::OrbFeaturesFinder>(); |
||||
matcher = makePtr<detail::BestOf2NearestMatcher>(false, ORB_MATCH_CONFIDENCE); |
||||
} |
||||
else |
||||
{ |
||||
FAIL() << "Unknown 2D features type: " << get<0>(GetParam()); |
||||
} |
||||
|
||||
detail::ImageFeatures features1, features2; |
||||
(*finder)(img1, features1); |
||||
(*finder)(img2, features2); |
||||
vector<detail::ImageFeatures> features; |
||||
vector<detail::MatchesInfo> pairwise_matches; |
||||
for(int i = 0; i < featuresVectorSize/2; i++) |
||||
{ |
||||
features.push_back(features1); |
||||
features.push_back(features2); |
||||
} |
||||
|
||||
declare.time(200); |
||||
while(next()) |
||||
{ |
||||
cvflann::seed_random(42);//for predictive FlannBasedMatcher
|
||||
startTimer(); |
||||
(*matcher)(features, pairwise_matches); |
||||
stopTimer(); |
||||
matcher->collectGarbage(); |
||||
} |
||||
|
||||
size_t matches_count = 0; |
||||
for (size_t i = 0; i < pairwise_matches.size(); ++i) |
||||
{ |
||||
if (pairwise_matches[i].src_img_idx < 0) |
||||
continue; |
||||
|
||||
EXPECT_TRUE(pairwise_matches[i].matches.size() > 100); |
||||
EXPECT_FALSE(pairwise_matches[i].H.empty()); |
||||
++matches_count; |
||||
} |
||||
|
||||
EXPECT_TRUE(matches_count > 0); |
||||
|
||||
SANITY_CHECK_NOTHING(); |
||||
} |
||||
|
||||
PERF_TEST_P( match, affineBestOf2Nearest, TEST_DETECTORS) |
||||
{ |
||||
Mat img1, img1_full = imread( getDataPath("stitching/s1.jpg") ); |
||||
Mat img2, img2_full = imread( getDataPath("stitching/s2.jpg") ); |
||||
float scale1 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img1_full.total())); |
||||
float scale2 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img2_full.total())); |
||||
resize(img1_full, img1, Size(), scale1, scale1); |
||||
resize(img2_full, img2, Size(), scale2, scale2); |
||||
|
||||
Ptr<detail::FeaturesFinder> finder; |
||||
Ptr<detail::FeaturesMatcher> matcher; |
||||
if (GetParam() == "surf") |
||||
{ |
||||
finder = makePtr<detail::SurfFeaturesFinder>(); |
||||
matcher = makePtr<detail::AffineBestOf2NearestMatcher>(false, false, SURF_MATCH_CONFIDENCE); |
||||
} |
||||
else if (GetParam() == "orb") |
||||
{ |
||||
finder = makePtr<detail::OrbFeaturesFinder>(); |
||||
matcher = makePtr<detail::AffineBestOf2NearestMatcher>(false, false, ORB_MATCH_CONFIDENCE); |
||||
} |
||||
else |
||||
{ |
||||
FAIL() << "Unknown 2D features type: " << GetParam(); |
||||
} |
||||
|
||||
detail::ImageFeatures features1, features2; |
||||
(*finder)(img1, features1); |
||||
(*finder)(img2, features2); |
||||
|
||||
detail::MatchesInfo pairwise_matches; |
||||
|
||||
declare.in(features1.descriptors, features2.descriptors); |
||||
|
||||
while(next()) |
||||
{ |
||||
cvflann::seed_random(42);//for predictive FlannBasedMatcher
|
||||
startTimer(); |
||||
(*matcher)(features1, features2, pairwise_matches); |
||||
stopTimer(); |
||||
matcher->collectGarbage(); |
||||
} |
||||
|
||||
// separate rotation and translation in transform matrix
|
||||
Mat T (pairwise_matches.H, Range(0, 2), Range(2, 3)); |
||||
Mat R (pairwise_matches.H, Range(0, 2), Range(0, 2)); |
||||
Mat h (pairwise_matches.H, Range(2, 3), Range::all()); |
||||
SANITY_CHECK(T, 5, ERROR_ABSOLUTE); // allow 5 pixels diff in translations
|
||||
SANITY_CHECK(R, .01, ERROR_ABSOLUTE); // rotations must be more precise
|
||||
// last row should be precisely (0, 0, 1) as it is just added for representation in homogeneous
|
||||
// coordinates
|
||||
EXPECT_DOUBLE_EQ(h.at<double>(0), 0.); |
||||
EXPECT_DOUBLE_EQ(h.at<double>(1), 0.); |
||||
EXPECT_DOUBLE_EQ(h.at<double>(2), 1.); |
||||
} |
||||
|
||||
PERF_TEST_P( matchVector, affineBestOf2NearestVectorFeatures, testing::Combine( |
||||
TEST_DETECTORS, |
||||
testing::Values(2, 4, 8)) |
||||
) |
||||
{ |
||||
Mat img1, img1_full = imread( getDataPath("stitching/s1.jpg") ); |
||||
Mat img2, img2_full = imread( getDataPath("stitching/s2.jpg") ); |
||||
float scale1 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img1_full.total())); |
||||
float scale2 = (float)std::min(1.0, sqrt(WORK_MEGAPIX * 1e6 / img2_full.total())); |
||||
resize(img1_full, img1, Size(), scale1, scale1); |
||||
resize(img2_full, img2, Size(), scale2, scale2); |
||||
|
||||
Ptr<detail::FeaturesFinder> finder; |
||||
Ptr<detail::FeaturesMatcher> matcher; |
||||
string detectorName = get<0>(GetParam()); |
||||
int featuresVectorSize = get<1>(GetParam()); |
||||
if (detectorName == "surf") |
||||
{ |
||||
finder = makePtr<detail::SurfFeaturesFinder>(); |
||||
matcher = makePtr<detail::AffineBestOf2NearestMatcher>(false, false, SURF_MATCH_CONFIDENCE); |
||||
} |
||||
else if (detectorName == "orb") |
||||
{ |
||||
finder = makePtr<detail::OrbFeaturesFinder>(); |
||||
matcher = makePtr<detail::AffineBestOf2NearestMatcher>(false, false, ORB_MATCH_CONFIDENCE); |
||||
} |
||||
else |
||||
{ |
||||
FAIL() << "Unknown 2D features type: " << get<0>(GetParam()); |
||||
} |
||||
|
||||
detail::ImageFeatures features1, features2; |
||||
(*finder)(img1, features1); |
||||
(*finder)(img2, features2); |
||||
vector<detail::ImageFeatures> features; |
||||
vector<detail::MatchesInfo> pairwise_matches; |
||||
for(int i = 0; i < featuresVectorSize/2; i++) |
||||
{ |
||||
features.push_back(features1); |
||||
features.push_back(features2); |
||||
} |
||||
|
||||
declare.time(200); |
||||
while(next()) |
||||
{ |
||||
cvflann::seed_random(42);//for predictive FlannBasedMatcher
|
||||
startTimer(); |
||||
(*matcher)(features, pairwise_matches); |
||||
stopTimer(); |
||||
matcher->collectGarbage(); |
||||
} |
||||
|
||||
size_t matches_count = 0; |
||||
for (size_t i = 0; i < pairwise_matches.size(); ++i) |
||||
{ |
||||
if (pairwise_matches[i].src_img_idx < 0) |
||||
continue; |
||||
|
||||
EXPECT_TRUE(pairwise_matches[i].matches.size() > 400); |
||||
EXPECT_FALSE(pairwise_matches[i].H.empty()); |
||||
++matches_count; |
||||
} |
||||
|
||||
EXPECT_TRUE(matches_count > 0); |
||||
|
||||
SANITY_CHECK_NOTHING(); |
||||
} |
Loading…
Reference in new issue