Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you should do is :</p> <ol> <li><p>Feed the 4 corners that you have found and the 4 real corners of the image to <a href="http://opencv.willowgarage.com/documentation/cpp/imgproc_geometric_image_transformations.html#cv-getperspectivetransform" rel="nofollow"><code>cv::getPerspectiveTransform</code></a>. It will give you a matrix of the perspective transformation that will warp the quadrangle to the whole image.</p></li> <li><p>Use <a href="http://opencv.willowgarage.com/documentation/cpp/imgproc_geometric_image_transformations.html#warpPerspective" rel="nofollow"><code>cv::WarpPerspective</code></a> to create the image you want.</p></li> </ol> <p>The links will take you to the documentation.</p> <p>EDIT : You could use <code>cv::findHomography</code> to do step 1. But this is more about having a lot of corresponding points and outliers.</p> <p>EDIT : Here is an example. It is with the C interface but you could easily make it to work with the c++</p> <pre><code>#include &lt;stdio.h&gt; #include "highgui.h" #include "cv.h" int main( int argc, char** argv ) { // cvLoadImage determines an image type and creates datastructure with appropriate size IplImage* img = cvLoadImage( argv[1], CV_LOAD_IMAGE_COLOR); IplImage* img1 = cvCreateImage( cvSize(img-&gt;width, img-&gt;height), img-&gt;depth, img-&gt;nChannels ); cvNamedWindow( "out", CV_WINDOW_AUTOSIZE ); cvShowImage( "out", img1 ); // create a window. Window name is determined by a supplied argument cvNamedWindow( argv[1], CV_WINDOW_AUTOSIZE ); // Display an image inside and window. Window name is determined by a supplied argument cvShowImage( argv[1], img ); // The part you need // Here is the points that you take the image from (the small quadrangle) CvPoint2D32f first[4] = { {0,0}, {(img-&gt;width /4)* 3, img-&gt;height /4 }, { img-&gt;width /4 ,(img-&gt;height /4) *3}, {(img-&gt;width /4)* 3,(img-&gt;height /4) *3}, }; // Here are the points that you draw the quadrangle into (the four corners) CvPoint2D32f second[4] = { {0,0}, {img-&gt;width,0}, {0,img-&gt;height}, {img-&gt;width,img-&gt;height} }; // The part you need CvMat *transform = cvCreateMat(3,3, CV_32F); cvGetPerspectiveTransform(first,second, transform); cvWarpPerspective(img, img1, transform, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0)); // End of part you need cvShowImage( "out", img1 ); // wait indefinitely for keystroke cvWaitKey(0); // release pointer to an object cvReleaseImage( &amp;img ); // Destroy a window cvDestroyWindow( argv[1] ); } </code></pre> <p>You should replace the array <code>first</code> with end points of the quadrangle you have found.</p> <p>EDIT : Here are some samples. I haven't looked them very well.</p> <p><a href="http://www.adaptive-vision.com/en/technical_data/documentation/filters/GeometricImageTransformations/index.html" rel="nofollow">Geometric Image Transformations</a></p> <p><a href="http://www.adaptive-vision.com/en/technical_data/documentation/filters/GeometricImageTransformations/cvGetPerspectiveTransform.html" rel="nofollow">cvGetPerspectiveTransform</a></p>
    singulars
    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.
    1. VO
      singulars
      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