GithubHelp home page GithubHelp logo

catree / opencv_svdtest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from woreno/opencv_svdtest

1.0 1.0 0.0 107 KB

testing some opencv functions that uses UDVt UDUt decompositions in opencv

C++ 97.53% MATLAB 2.47%

opencv_svdtest's Introduction

// 2019 Manuel Moreno // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // * Redistribution's of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistribution's in binary form must reproduce the above copyright notice, // and/or other materials provided with the distribution. // for OpenCV licence check the attached files

Direct Linear Transform (DLT) is method to recover the rotation and translation of object vectors relative to a projector where they had been projected. With both object vectors and the projection vectors on the projection plane, through an cross product relation between both, is possible to reach a homogeneous linear system Ax = 0, where x are the elements that form the transformation matrix. DLT is used to find R|T and homography (an R|T where the vectors object are fixed on a plane) matrices. In the first case, you get a matrix A with 2Nx12 elements, in the second case, a matrix A with 2Nx9 elements, both with a wellknow format. Moreover, this Ax = 0 can be solved in the least square sense, by finding a solution for the null space of A'A instead of A, requiring the A'A (9x9 or 12x12) product and followed by a UDU' decomposition to get a solution, from U'. However programmatically, isn't necessary explicitly to do this product (this way requires to generate a full A matrix, that is, 2Nx9 or 2Nx12 before the proceed to transpose product A'A). Once you know the format of A'A, it is possible to generate the upper triangle of the 9x9 or 12x12 A'A, and copy those elements to the lower triangle.

Here, i test the generation of A'A and factorization of symmetric matrices as in opencv. This test, comes from a personal question, why in opencv,

implicit, manual A'A triangle + cvCompleteSymm + UDU'(eigenvv) is used by CvHomographyEstimator::runKernel:, a DLT 9x9

and

explicit DLT system in A + cvMulTransposed + UDV'(SVD.compute) is used by cvFindExtrinsicCameraParams2, a DLT 12x12

when...

  • for the symmetric matrixes a UDU' decomposition would expected to run better (as in runKernel)

  • making the DLT A'A triangle manually in a loop would be expected to be better than multiplying by the transpose of the DLT A (as in runKernel)
    (anyway cvMulTransposed will call cvCompleteSymm)

    • the DLT 12x12 triangle can be created manually as in the 9x9 case (as in runKernel)

tests:

test A. gen DLT 12x12 symmetric matrixes

test B. gen generic nxn symmetric matrixes, and run UDU', UDV' 

test C. gen DLT 9x9, 12x12 symmetric matrixes, and run UDU', UDV'

test D. gen DLT 12x12 for n points, and run UDU', UDV'

warning: only tested with visual studio 10, but would be fine in linux (clock.hpp changes on both systems) this test requires opencv and uses opencv "lapack.cpp" functions; almost all functions of the interest here, have been renamed with a posfix underscore and located in blas.hpp (math) and udut_givens.hpp, udvt_givens.hpp (for decompositions) in order to be called, tested, and compiled inline and with optimization flags altogether. other opencv structures and functions not used, eg. cv::Mat, cv::Size, cv::InputArray are using the normal cv:: interface.

USE: #define USE_FP32 if you want to used floats instead of doubles

i used in a project with 2 configs were _DEBUG i set no optimization flags and RELEASE full optimization; so if that is the case, it will output the strings "VC10 not opt" and "VC10 OX" in the plots;

the output are 4 plots that are appended to "res.txt" that you can insert them all in "plot_test.m" to see the results (uses uiaxes.m).

the result of those tests - at least in my machine, running windows10/VC10 -

(test B) UDU' has a clear advantage over UDV' on large matrices; 

(test D) but in small matrices as in the DLT 12x12 case, the results are mixed: 

UDV' is better in 64bits both full optimization and 32-64bit without, and UDU'
is better with optimization on 32bits. 

(test A) for the generation of the DLT symmetric A'A matrix is always better 
to do it manually in a loop and copy the upper triangle to the lower instead of 
creating the DLT A matrix in a loop and calling for doing a product with its transpose.

opencv_svdtest's People

Contributors

woreno avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.