Ask Your Question
2

Find point coordinate in a projected rectangle

asked 2013-11-01 08:40:09 -0600

ArnoG gravatar image

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 problemimage description

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 ?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-11-03 02:11:12 -0600

Michael Burdinov gravatar image

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 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).

edit flag offensive delete link more

Comments

1

you also can apply matrix P to point F using perspectiveTransform() function

tenta4 gravatar imagetenta4 ( 2013-11-04 07:06:37 -0600 )edit

+1. Ye, you are right. I forgot about it.

Michael Burdinov gravatar imageMichael Burdinov ( 2013-11-05 00:22:05 -0600 )edit
0

answered 2013-11-02 02:33:48 -0600

Haris gravatar image

I 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

edit flag offensive delete link more

Comments

@Haris, projected rectangle becames general quadrilateral, i.e. it is not a rectangle anymore and don't have parallel edges.

Michael Burdinov gravatar imageMichael Burdinov ( 2013-11-03 02:13:59 -0600 )edit

@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.

Haris gravatar imageHaris ( 2013-11-05 23:07:42 -0600 )edit

The 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.

Michael Burdinov gravatar imageMichael Burdinov ( 2013-11-06 01:16:53 -0600 )edit

Question Tools

Stats

Asked: 2013-11-01 08:40:09 -0600

Seen: 3,670 times

Last updated: Nov 03 '13