HamoudaOthman / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

cvGetPerspectiveTransform generates a different matrix on every run #82

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Defined CvPoint2D32f type points
2. Used cvGetPerspective function

What is the expected output? What do you see instead?
When I assign the same points for transformation, I expect to see an identify 
matrix as output, but i get a random-like matrix instead.

What version of the product are you using? On what operating system?
Java SE 1.6, openCV 2.1 and JavaCV on Windows 7

Please provide any additional information below.
Here is my code:
        CvMat mmat = cvCreateMat(3,3,CV_32FC1);
        CvPoint2D32f c1 = new CvPoint2D32f(4);
        CvPoint2D32f c2 = new CvPoint2D32f(4);

        c1.position(0).set(0, 0);
        c1.position(1).set(640, 0);
        c1.position(2).set(0, 480);
        c1.position(3).set(640, 480);

        c2.position(0).set(0, 0);
        c2.position(1).set(640, 0);
        c2.position(2).set(0, 480);
        c2.position(3).set(640, 480);

        cvGetPerspectiveTransform(c1, c2, mmat);  

        System.out.print(mmat);

c1 and c2 are the same so the output should be identify matrix, however it 
generates a different matrix on every run as follows:

[ -2.7626187E-24, 7.499996E-7, -5.3940282E-17
  8.134292E-24, 5.624997E-7, -1.503761E-16
  -9.999995E-4, -7.499996E-4, 1.0 ]

[ -6.2276979E8, -7.3132959E12, -935882.1
  2.54554512E13, -5.4859955E12, -1.62929928E16
  -5.4853492E15, 7.3137871E15, 1.0 ]

[ 2.0286456E-28, 0.0, 0.0
  4.65568E-39, 0.0, 0.0
  -3.3429618E-34, 0.0, 1.0 ]

Thank you for your help.

Original issue reported on code.google.com by fur...@isikdogan.com on 6 Jul 2011 at 2:51

GoogleCodeExporter commented 8 years ago
Right, cvGetPerspectiveTransform() is known to be buggy, so either try to 
convince the developers of OpenCV fix it, or use the equivalent non-buggy 
JavaCV.getPerspectiveTransform():
http://www.google.com/codesearch#8TJuDx-2Qiw/trunk/javacv/src/com/googlecode/jav
acv/JavaCV.java&q=getPerspectiveTransform%20package:http://javacv\.googlecode\.c
om&l=45

Original comment by samuel.a...@gmail.com on 7 Jul 2011 at 5:30

GoogleCodeExporter commented 8 years ago
And you forgot to call `Pointer.position(0)` before calling 
cvGetPerspectiveTransform().

Original comment by samuel.a...@gmail.com on 7 Jul 2011 at 5:32