Please help me to convert opencv matrix multiplication into matlab

2 Ansichten (letzte 30 Tage)
Dear concern, I am facing a problem converting an opencv matrix multiplication into matlab which seemed very easy but it is giving me different output. I have two matrices:
transformationMatrix =
-7.04442501068115 0 2239.44677734375
0 1.53200602531433 -2508.06420898438
0 6.14454364776611 -1048.95043945313
0 -0.00281885638833046 0.481214046478271
matrixmultiplier =
317.903421890249 460 100 317.903421890249
220 220 220 350
1 1 1 1
While using opencv the code and output becomes: CvMat *result = cvCreateMat( resultRows, resultCols, CV_32FC1 ); cvMatMul(&transformationMatrix, &matrixmultiplier, result) =
-3.88010430469876e-05 -1000.98872756958 1535.00427627563 -3.88010430469876e-05
-2171.02288341522 -2171.02288341522 -2171.02288341522 -1971.86210012436
302.84916305542 302.84916305542 302.84916305542 1101.63983726501
-0.13893435895443 -0.13893435895443 -0.13893435895443 -0.505385689437389
But while using matlab the code and output becomes: transformedMatrix*matrixmultiplier =
3.18194215651602e-05 -1000.98870849609 1535.00427246094 3.18194215651602e-05
-2171.02294921875 -2171.02294921875 -2171.02294921875 -1971.86206054688
302.849151611328 302.849151611328 302.849151611328 1101.63989257813
-0.13893435895443 -0.13893435895443 -0.13893435895443 -0.50538569688797
I need urgent help to find the error in my coding to understand the discrepancy between two outputs.
Thanks in advance

Akzeptierte Antwort

David Young
David Young am 11 Okt. 2015
Your code is fine, it's just rounding error. Note that the differences are smaller, by many orders of magnitude, than the largest elements of the matrix. It's likely that OpenCV and MATLAB do the computation in a different order and that results in these tiny discrepancies.
For more information, see this FAQ, or put "rounding error" into the search box on this page.
  3 Kommentare
David Young
David Young am 11 Okt. 2015
You can convert between single and double precision floats in MATLAB using the single and double commands. It's safest and clearest to ensure that all arguments to a function are the same type if it's important to carry out the operation using that type (though in fact MATLAB has rules about implicit conversions).
Shibbir Ahmed
Shibbir Ahmed am 11 Okt. 2015
Thank you again David. Your answer is helping a lot.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by