OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 06 Nov 2013 01:16:53 -0600Find point coordinate in a projected rectanglehttp://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/Hello OpenCV users.
I'm in front of a thought-it-was-simple problem, and as I am quite rusty concerning geometry and mathematics, I would like to request your help.
On the image below you can see a picture representing the problem![image description](/upfiles/13833106476560783.png)
This entire image represent the picture I get from my camera.
In this image I suceed to detect 4 points (A,B,C,D), forming a rectangle.
-I know the coordinates(in pixels) of these 4 points in my camera view.
-I also know the real dimensions of the rectangle I'm trying to detect.
Considering a point F in my camera view, I would like to calculate its coordinate in the frame formed by A,B,C,D.
How to do this with openCV ?
Fri, 01 Nov 2013 08:40:09 -0500http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/Answer by Michael Burdinov for <p>Hello OpenCV users.</p>
<p>I'm in front of a thought-it-was-simple problem, and as I am quite rusty concerning geometry and mathematics, I would like to request your help.</p>
<p>On the image below you can see a picture representing the problem<img alt="image description" src="/upfiles/13833106476560783.png"></p>
<p>This entire image represent the picture I get from my camera.</p>
<p>In this image I suceed to detect 4 points (A,B,C,D), forming a rectangle.</p>
<p>-I know the coordinates(in pixels) of these 4 points in my camera view.</p>
<p>-I also know the real dimensions of the rectangle I'm trying to detect.</p>
<p>Considering a point F in my camera view, I would like to calculate its coordinate in the frame formed by A,B,C,D.
How to do this with openCV ?</p>
http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?answer=23498#post-id-23498First you need to find transformation from 4 points of source quadrilateral (A, B, C and D) to 4 points of some destination quadrilateral. In your case I guess it will be something like (0,0), (width,0), (width,height), (0,height). You can find them by use of [getPerspectiveTransform](http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#getperspectivetransform). Output of getPerspectiveTransform is 3x3 matrix P of perspective transformation of 2D points (in homogeneous coordinates of course). You may apply it to F in order to get the coordinates you need. The calculation is:
Given F=(x,y). Multiply P by (x,y,1). Resulting vector will be (xr,yr,zr). Since this is homogeneous coordinates this is equivalent to (xr/zr, yr/zr, 1). So the coordinate of transformed F is (xr/zr, yr/zr).Sun, 03 Nov 2013 02:11:12 -0600http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?answer=23498#post-id-23498Comment by tenta4 for <p>First you need to find transformation from 4 points of source quadrilateral (A, B, C and D) to 4 points of some destination quadrilateral. In your case I guess it will be something like (0,0), (width,0), (width,height), (0,height). You can find them by use of <a href="http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#getperspectivetransform">getPerspectiveTransform</a>. Output of getPerspectiveTransform is 3x3 matrix P of perspective transformation of 2D points (in homogeneous coordinates of course). You may apply it to F in order to get the coordinates you need. The calculation is:</p>
<p>Given F=(x,y). Multiply P by (x,y,1). Resulting vector will be (xr,yr,zr). Since this is homogeneous coordinates this is equivalent to (xr/zr, yr/zr, 1). So the coordinate of transformed F is (xr/zr, yr/zr).</p>
http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23540#post-id-23540you also can apply matrix P to point F using perspectiveTransform() functionMon, 04 Nov 2013 07:06:37 -0600http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23540#post-id-23540Comment by Michael Burdinov for <p>First you need to find transformation from 4 points of source quadrilateral (A, B, C and D) to 4 points of some destination quadrilateral. In your case I guess it will be something like (0,0), (width,0), (width,height), (0,height). You can find them by use of <a href="http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#getperspectivetransform">getPerspectiveTransform</a>. Output of getPerspectiveTransform is 3x3 matrix P of perspective transformation of 2D points (in homogeneous coordinates of course). You may apply it to F in order to get the coordinates you need. The calculation is:</p>
<p>Given F=(x,y). Multiply P by (x,y,1). Resulting vector will be (xr,yr,zr). Since this is homogeneous coordinates this is equivalent to (xr/zr, yr/zr, 1). So the coordinate of transformed F is (xr/zr, yr/zr).</p>
http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23569#post-id-23569+1. Ye, you are right. I forgot about it.Tue, 05 Nov 2013 00:22:05 -0600http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23569#post-id-23569Answer by Haris for <p>Hello OpenCV users.</p>
<p>I'm in front of a thought-it-was-simple problem, and as I am quite rusty concerning geometry and mathematics, I would like to request your help.</p>
<p>On the image below you can see a picture representing the problem<img alt="image description" src="/upfiles/13833106476560783.png"></p>
<p>This entire image represent the picture I get from my camera.</p>
<p>In this image I suceed to detect 4 points (A,B,C,D), forming a rectangle.</p>
<p>-I know the coordinates(in pixels) of these 4 points in my camera view.</p>
<p>-I also know the real dimensions of the rectangle I'm trying to detect.</p>
<p>Considering a point F in my camera view, I would like to calculate its coordinate in the frame formed by A,B,C,D.
How to do this with openCV ?</p>
http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?answer=23472#post-id-23472I think you do this easly using the following step.
1. Find slop of new x and y axis.
2. Draw a parallel line with the x axis with its slop from F.
3. Find the distance between these two parallel line and that will be your y.
4. Draw a line parallel to y axis from F and find the distance between these two line and that will be your x.
![image description](/upfiles/138337760721159.jpg)
Sat, 02 Nov 2013 02:33:48 -0500http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?answer=23472#post-id-23472Comment by Michael Burdinov for <p>I think you do this easly using the following step.</p>
<ol>
<li>Find slop of new x and y axis.</li>
<li>Draw a parallel line with the x axis with its slop from F.</li>
<li>Find the distance between these two parallel line and that will be your y.</li>
<li>Draw a line parallel to y axis from F and find the distance between these two line and that will be your x.</li>
</ol>
<p><img alt="image description" src="/upfiles/138337760721159.jpg"></p>
http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23499#post-id-23499@Haris, projected rectangle becames general quadrilateral, i.e. it is not a rectangle anymore and don't have parallel edges. Sun, 03 Nov 2013 02:13:59 -0600http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23499#post-id-23499Comment by Haris for <p>I think you do this easly using the following step.</p>
<ol>
<li>Find slop of new x and y axis.</li>
<li>Draw a parallel line with the x axis with its slop from F.</li>
<li>Find the distance between these two parallel line and that will be your y.</li>
<li>Draw a line parallel to y axis from F and find the distance between these two line and that will be your x.</li>
</ol>
<p><img alt="image description" src="/upfiles/138337760721159.jpg"></p>
http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23605#post-id-23605@Michael Burdinov In your question you mentioned it is rectangle that's why I gave such a solution. But in your image look like a quadrilateral.Tue, 05 Nov 2013 23:07:42 -0600http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23605#post-id-23605Comment by Michael Burdinov for <p>I think you do this easly using the following step.</p>
<ol>
<li>Find slop of new x and y axis.</li>
<li>Draw a parallel line with the x axis with its slop from F.</li>
<li>Find the distance between these two parallel line and that will be your y.</li>
<li>Draw a line parallel to y axis from F and find the distance between these two line and that will be your x.</li>
</ol>
<p><img alt="image description" src="/upfiles/138337760721159.jpg"></p>
http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23607#post-id-23607The question is not mine but @ArnoG's. Yes he called it rectangle in the question, but the title of question is projected rectangle and the image is quadrilateral, so I assumed he is asking about general quadrilateral. Wed, 06 Nov 2013 01:16:53 -0600http://answers.opencv.org/question/23443/find-point-coordinate-in-a-projected-rectangle/?comment=23607#post-id-23607