Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Can I Perform a Perspective Transform Using a Homography Matrix (3x3) in JavaCV?
    primarykey
    data
    text
    <p>I have been trying for some time now to take an image of a pool table from an arbitrary angle, locate four coordinate pairs (x,y) of the corners, and rotate/warp the image such that the resulting image contains only the table from a bird's eye view. I am using JavaCV to accomplish this task. So far, I have written code which successfully calculates the four corners of the table as shown below (I have coded red cvCircles of radius 25 on the four corners).</p> <p><img src="https://i.stack.imgur.com/Zmrwk.jpg" alt="enter image description here"></p> <p>After finding my four corners:<br> Corner 1 (Bottom Right) X: 3234 Y: 1858<br> Corner 2 (Bottom Left) X: 0 Y: 1801<br> Corner 3 (Top Right) X: 2722 Y: 1069<br> Corner 4 (Top Left) X: 523 Y: 1030<br></p> <h2>I attempted to use cvFindHomography and then cvWarpPerspectve to accomplish this. My code can be found below:<br></h2> <pre><code>// Initialize Table Corners as Image Coordinates float[] aImg = { corners.get(0).x(), corners.get(0).y(), // BR X: 3234 Y: 1858 corners.get(1).x(), corners.get(1).y(), // BL X: 0 Y: 1801 corners.get(2).x(), corners.get(2).y(), // TR X: 2722 Y: 1069 corners.get(3).x(), corners.get(3).y() // TL X: 523 Y: 1030 }; // Initialize World Coordinates (Are these even correct? How do I determine these?) float[] aWorld = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,1.0f }; // Create 3x3 Homography Matrix CvMat homography = cvCreateMat(3, 3, opencv_core.CV_32FC1); opencv_imgproc.cvGetPerspectiveTransform(aImg, aWorld, homography); System.out.println(homography.toString()); // Create imgWarped and Warp Perspective IplImage imgWarped = cvCreateImage(cvGetSize(img), 8, 3); opencv_imgproc.cvWarpPerspective(img, imgWarped, homography, opencv_imgproc.CV_INTER_LINEAR, CvScalar.ZERO); // Create Canvas and Display Image CanvasFrame canvas = new CanvasFrame("Warped Image"); canvas.showImage(imgWarped); canvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); </code></pre> <p><br> The 3x3 Homography Matrix I'm obtaining is:<br> [ 0.0011688289, 7.928632E-4, -1.4279466<br> -8.698455E-5, 0.0049045905, -5.006235<br> -2.8205379E-5, 0.0015696458, 1.0 ]<br> <br></p> <h2>**Unfortunately, the result is a purely black image containing <em>nothing</em>. Am I approaching this incorrectly? Any advice, code, pseudocode, etc. would be GREATLY APPRECIATED!<br></h2> <h2>Thank you so much for reading.**</h2>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload