/*1IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.23By downloading, copying, installing or using the software you agree to this license.4If you do not agree to this license, do not download, install,5copy or use the software.678BSD 3-Clause License910Copyright (C) 2014, Olexa Bilaniuk, Hamid Bazargani & Robert Laganiere, all rights reserved.1112Redistribution and use in source and binary forms, with or without modification,13are permitted provided that the following conditions are met:1415* Redistribution's of source code must retain the above copyright notice,16this list of conditions and the following disclaimer.1718* Redistribution's in binary form must reproduce the above copyright notice,19this list of conditions and the following disclaimer in the documentation20and/or other materials provided with the distribution.2122* The name of the copyright holders may not be used to endorse or promote products23derived from this software without specific prior written permission.2425This software is provided by the copyright holders and contributors "as is" and26any express or implied warranties, including, but not limited to, the implied27warranties of merchantability and fitness for a particular purpose are disclaimed.28In no event shall the Intel Corporation or contributors be liable for any direct,29indirect, incidental, special, exemplary, or consequential damages30(including, but not limited to, procurement of substitute goods or services;31loss of use, data, or profits; or business interruption) however caused32and on any theory of liability, whether in contract, strict liability,33or tort (including negligence or otherwise) arising in any way out of34the use of this software, even if advised of the possibility of such damage.35*/3637/**38* Bilaniuk, Olexa, Hamid Bazargani, and Robert Laganiere. "Fast Target39* Recognition on Mobile Devices: Revisiting Gaussian Elimination for the40* Estimation of Planar Homographies." In Computer Vision and Pattern41* Recognition Workshops (CVPRW), 2014 IEEE Conference on, pp. 119-125.42* IEEE, 2014.43*/4445/* Include Guards */46#ifndef __OPENCV_RHO_H__47#define __OPENCV_RHO_H__48495051/* Includes */52#include <opencv2/core.hpp>535455565758/* Defines */596061/* Flags */62#ifndef RHO_FLAG_NONE63#define RHO_FLAG_NONE (0U<<0)64#endif65#ifndef RHO_FLAG_ENABLE_NR66#define RHO_FLAG_ENABLE_NR (1U<<0)67#endif68#ifndef RHO_FLAG_ENABLE_REFINEMENT69#define RHO_FLAG_ENABLE_REFINEMENT (1U<<1)70#endif71#ifndef RHO_FLAG_ENABLE_FINAL_REFINEMENT72#define RHO_FLAG_ENABLE_FINAL_REFINEMENT (1U<<2)73#endif74757677/* Namespace cv */78namespace cv{7980/* Data structures */8182/**83* Homography Estimation context.84*/8586struct RHO_HEST;87typedef struct RHO_HEST RHO_HEST;888990/* Functions */9192/**93* Initialize the estimator context, by allocating the aligned buffers94* internally needed.95*96* @return A pointer to the context if successful; NULL if an error occurred.97*/9899Ptr<RHO_HEST> rhoInit(void);100101102/**103* Ensure that the estimator context's internal table for non-randomness104* criterion is at least of the given size, and uses the given beta. The table105* should be larger than the maximum number of matches fed into the estimator.106*107* A value of N of 0 requests deallocation of the table.108*109* @param [in] p The initialized estimator context110* @param [in] N If 0, deallocate internal table. If > 0, ensure that the111* internal table is of at least this size, reallocating if112* necessary.113* @param [in] beta The beta-factor to use within the table.114* @return 0 if unsuccessful; non-zero otherwise.115*/116117int rhoEnsureCapacity(Ptr<RHO_HEST> p, unsigned N, double beta);118119120121/**122* Seeds the internal PRNG with the given seed.123*124* Although it is not required to call this function, since context125* initialization seeds itself with entropy from rand(), this function allows126* reproducible results by using a specified seed.127*128* @param [in] p The estimator context whose PRNG is to be seeded.129* @param [in] seed The 64-bit integer seed.130*/131132void rhoSeed(Ptr<RHO_HEST> p, uint64_t seed);133134135/**136* Estimates the homography using the given context, matches and parameters to137* PROSAC.138*139* The given context must have been initialized.140*141* The matches are provided as two arrays of N single-precision, floating-point142* (x,y) points. Points with corresponding offsets in the two arrays constitute143* a match. The homography estimation attempts to find the 3x3 matrix H which144* best maps the homogeneous-coordinate points in the source array to their145* corresponding homogeneous-coordinate points in the destination array.146*147* Note: At least 4 matches must be provided (N >= 4).148* Note: A point in either array takes up 2 floats. The first of two stores149* the x-coordinate and the second of the two stores the y-coordinate.150* Thus, the arrays resemble this in memory:151*152* src = [x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, ...]153* Matches: | | | | |154* dst = [x0, y0, x1, y1, x2, y2, x3, y3, x4, y4, ...]155* Note: The matches are expected to be provided sorted by quality, or at156* least not be worse-than-random in ordering.157*158* A pointer to the base of an array of N bytes can be provided. It serves as159* an output mask to indicate whether the corresponding match is an inlier to160* the returned homography, if any. A zero indicates an outlier; A non-zero161* value indicates an inlier.162*163* The PROSAC estimator requires a few parameters of its own. These are:164*165* - The maximum distance that a source point projected onto the destination166* plane can be from its putative match and still be considered an167* inlier. Must be non-negative.168* A sane default is 3.0.169* - The maximum number of PROSAC iterations. This corresponds to the170* largest number of samples that will be drawn and tested.171* A sane default is 2000.172* - The RANSAC convergence parameter. This corresponds to the number of173* iterations after which PROSAC will start sampling like RANSAC.174* A sane default is 2000.175* - The confidence threshold. This corresponds to the probability of176* finding a correct solution. Must be bounded by [0, 1].177* A sane default is 0.995.178* - The minimum number of inliers acceptable. Only a solution with at179* least this many inliers will be returned. The minimum is 4.180* A sane default is 10% of N.181* - The beta-parameter for the non-randomness termination criterion.182* Ignored if non-randomness criterion disabled, otherwise must be183* bounded by (0, 1).184* A sane default is 0.35.185* - Optional flags to control the estimation. Available flags are:186* HEST_FLAG_NONE:187* No special processing.188* HEST_FLAG_ENABLE_NR:189* Enable non-randomness criterion. If set, the beta parameter190* must also be set.191* HEST_FLAG_ENABLE_REFINEMENT:192* Enable refinement of each new best model, as they are found.193* HEST_FLAG_ENABLE_FINAL_REFINEMENT:194* Enable one final refinement of the best model found before195* returning it.196*197* The PROSAC estimator optionally accepts an extrinsic initial guess of H.198*199* The PROSAC estimator outputs a final estimate of H provided it was able to200* find one with a minimum of supporting inliers. If it was not, it outputs201* the all-zero matrix.202*203* The extrinsic guess at and final estimate of H are both in the same form:204* A 3x3 single-precision floating-point matrix with step 3. Thus, it is a205* 9-element array of floats, with the elements as follows:206*207* [ H00, H01, H02,208* H10, H11, H12,209* H20, H21, 1.0 ]210*211* Notice that the homography is normalized to H22 = 1.0.212*213* The function returns the number of inliers if it was able to find a214* homography with at least the minimum required support, and 0 if it was not.215*216*217* @param [in/out] p The context to use for homography estimation. Must218* be already initialized. Cannot be NULL.219* @param [in] src The pointer to the source points of the matches.220* Must be aligned to 4 bytes. Cannot be NULL.221* @param [in] dst The pointer to the destination points of the matches.222* Must be aligned to 4 bytes. Cannot be NULL.223* @param [out] inl The pointer to the output mask of inlier matches.224* Must be aligned to 4 bytes. May be NULL.225* @param [in] N The number of matches. Minimum 4.226* @param [in] maxD The maximum distance. Minimum 0.227* @param [in] maxI The maximum number of PROSAC iterations.228* @param [in] rConvg The RANSAC convergence parameter.229* @param [in] cfd The required confidence in the solution.230* @param [in] minInl The minimum required number of inliers. Minimum 4.231* @param [in] beta The beta-parameter for the non-randomness criterion.232* @param [in] flags A union of flags to fine-tune the estimation.233* @param [in] guessH An extrinsic guess at the solution H, or NULL if234* none provided.235* @param [out] finalH The final estimation of H, or the zero matrix if236* the minimum number of inliers was not met.237* Cannot be NULL.238* @return The number of inliers if the minimum number of239* inliers for acceptance was reached; 0 otherwise.240*/241242unsigned rhoHest(Ptr<RHO_HEST> p, /* Homography estimation context. */243const float* src, /* Source points */244const float* dst, /* Destination points */245char* inl, /* Inlier mask */246unsigned N, /* = src.length = dst.length = inl.length */247float maxD, /* 3.0 */248unsigned maxI, /* 2000 */249unsigned rConvg, /* 2000 */250double cfd, /* 0.995 */251unsigned minInl, /* 4 */252double beta, /* 0.35 */253unsigned flags, /* 0 */254const float* guessH, /* Extrinsic guess, NULL if none provided */255float* finalH); /* Final result. */256257258259260/* End Namespace cv */261}262263264265266#endif267268269