jloyd / javacv

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

cvGetPerspectiveTransform is not applicable #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 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?
I want to align the perspective of the input image. I get the following error 
instead:

"The method cvGetPerspectiveTransform(opencv_core.CvPoint2D32f, 
opencv_core.CvPoint2D32f, opencv_core.CvMat) in the type opencv_imgproc is not 
applicable for the arguments (opencv_core.CvPoint2D32f[], 
opencv_core.CvPoint2D32f[], opencv_core.CvMat)"

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.
I`m trying to align the perspective of the image(Y). Here is my code:

                CvMat mmat = cvCreateMat(3,3,CV_32FC1);
        CvPoint2D32f[] c1 = new CvPoint2D32f[4];
        CvPoint2D32f[] c2 = new CvPoint2D32f[4];

        for(int i=0; i<4; i++){
            c1[i] = new CvPoint2D32f();
            c2[i] = new CvPoint2D32f();
        }

        c1[0].set(43, 18);
        c1[1].set(280, 40);
        c1[2].set(19, 223);
        c1[3].set(304, 200);

        c2[0].set(0, 0);
        c2[1].set(Y.width(), 0);
        c2[2].set(0, Y.height());
        c2[3].set(Y.width(), Y.height());

        mmat = cvGetPerspectiveTransform(c1, c2, mmat);  
        cvWarpPerspective(Y, Y, mmat);

        cvNamedWindow("Image:",1);
        cvShowImage("Image:",Y);
        cvWaitKey();

Am I doing something wrong?

I will be thankful for any help.

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

GoogleCodeExporter commented 9 years ago
Search the README.txt file for "array"

Original comment by samuel.a...@gmail.com on 6 Jul 2011 at 1:18

GoogleCodeExporter commented 9 years ago
Thanks. That solved this problem but this time I`m getting the following error:

Assertion failed (dst.data != src.data && src.cols > 0 && src.rows > 0) in 
unknown function, file 
c:\Users\vp\work\ocv\opencv\modules\imgproc\src\imgwarp.cpp, line 2954

My Code:

        CvMat mmat = cvCreateMat(3,3,CV_32FC1);
        CvPoint2D32f c1 = new CvPoint2D32f(4);
        CvPoint2D32f c2 = new CvPoint2D32f(4);

        //corner points of the parking place
        c1.position(0).set(43, 18);
        c1.position(1).set(280, 40);
        c1.position(2).set(19, 223);
        c1.position(3).set(304, 200);

        c2.position(0).set(0, 0);
        c2.position(1).set(320, 0);
        c2.position(2).set(0, 240);
        c2.position(3).set(320, 240);

        mmat = cvGetPerspectiveTransform(c1, c2, mmat);  
        cvWarpPerspective(Y, Y, mmat);

Original comment by fur...@isikdogan.com on 6 Jul 2011 at 1:42

GoogleCodeExporter commented 9 years ago
You are overwriting the reference to your mmat, so it gets deallocated. You 
need to keep a reference to it.

Original comment by samuel.a...@gmail.com on 6 Jul 2011 at 1:50

GoogleCodeExporter commented 9 years ago
Ah no, this is not the problem. The error message clearly indicates "dst.data 
!= src.data", so you cannot do what you want to do. This is a perfectly normal 
error of OpenCV and has nothing to do with JavaCV. Please write /correct/ 
code...

Original comment by samuel.a...@gmail.com on 6 Jul 2011 at 1:51

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thanks. It`s working now. Here`s the final code:

                CvMat mmat = cvCreateMat(3,3,CV_32FC1);
        CvPoint2D32f c1 = new CvPoint2D32f(4);
        CvPoint2D32f c2 = new CvPoint2D32f(4);

        //corner points of the parking place
        c1.position(0).set(0, 0);
        c1.position(1).set(320, 0);
        c1.position(2).set(0, 240);
        c1.position(3).set(320, 240);

        c2.position(0).set(0, 0);
        c2.position(1).set(Y.width(), 0);
        c2.position(2).set(0, Y.height());
        c2.position(3).set(Y.width(), Y.height());

        cvGetPerspectiveTransform(c1, c2, mmat);  
            cvWarpPerspective(Y, AlignedY, mmat);

Original comment by fur...@isikdogan.com on 6 Jul 2011 at 2:00