How to do non-perspective image warping in OpenCV? - image-processing

I have an image where the user selects an arbitrary 4-cornered polygon.
I want to stretch this polygon into the entire image.
I've tried doing it with homography and cvWarpPerspective,
but the result was a Perspective transformation, which is not what I want.
Any ideas how to do this with OpenCV/EMGU ?
Thanks,
SW

What you're trying should work. Calculate the homography by making the 4 corners of the polygon correspond to (0,0) (0,height) (width,0) and (width,height).
Have a look at GetPerspectiveTransform

I think what you want is a reversal of perspective transform.
Here is what you must consider doing. Assume that you had the polygon at locations (x1,y1)....(x4,y4) originally on your screen (0,0) ....(w,h).
Applying perspective transform using cvWarpPerspective/getPerspectiveTransform you would be able to get the original co-ordinates to the known co-ordinates. So you should basically multiply the known co-ordinates with the inverse of the perspective transform matrix (unless that is non-invertible, in which case you must add a delta term to the homogeneous -coordinate term )

Related

Reverse image distortion

Say I've the following image
which is a circle and a square capture by a camera positioned 30° far from the ground.
This the scene from an orthogonal POV:
This is the camera:
Is it possible to reverse the distortion in order to obtain the second image (orthogonal POV) from the first one (distorted image) without knowing the camera angle?
Regards
To inverse a perspective transformation, also known as homography, you need to identify 8 parameters. For this you need to know the (X, Y) coordinates of four points both in the original and undistorted image.
A possibility is to use the four corners of the square, but this won't be very accurate. Alternatively, use two corners and the tangency points of the lines from these corners to the circle.
If you don't know the relative sizes of the square and the circle and their distance, you are a little stuck.

Calculate the Affine transformation matrix in image Feature based registration

I have two images, one is the result of applying an affine transform to the other.
I can register them using homography by extracting the points using the ORB_create function in OpenCV.
However, I want to calculate the Affine matrix needed for this transformation.
is there any way of doing it simply by having the two images?
Detect a rotated rectangle and use its corners to get your transformation matrix
Use : getPerspectiveTransform or getAffineTransform
Edit: regarding rotated rectangle detection :
Please check this Opencv tutorial on how to find contours and detect rotated rectangles Creating Bounding rotated boxes and ellipses for contours

Is it possible to perspectivetransform an ellipse into a circle?

For a project, I need to store circles detected on some photos. The problem is that some of these photos are taken from an angle, meaning the circles are ellipses. Is it possible to somehow turn the ellipses into circles?
I thought of rectifying the ellipse, then transforming the rectangle to a square. Indeterminate problem comes to my mind, meaning there are too many possible variations for my approach, and the results are different for each approach.
To find perspective transform, you need to have 4 pairs of corresponding coordinates: points at distorted picture and their ideal positions after correction of perspective.
In this case you can calculate matrix of perspective transform with getPerspectiveTransform function and apply it to correct all the picture. Example

OpenCV circle distortion detection

OpenCV has capapabilities to compensate for distortion in patterns, such as a this board, for example:
Every example I ever saw for this process does it with grids or squares. I would like to know if something similar exists for a single circle. My practical case is that I detect an ellipse, and I need to calculate the angle between the plane of this ellipse and the projection plane where the ellipse is projected as a circle. I managed to achieve that in my own code, but I would like to know if there is something built into the library to that purpose.
Use the ellipse axes to your advantage
I don't know of any "circular projection" as you name it, but I'm thinking that you can rephrase your problem into having the solution already.
Images make any answer SO cool.
Forget the ellipse, take the axes
A circle can be thought of as 2 vectors with unit norm defining a plane.
The projected circle's axes you estimate are the projection of the unit referential into the 3D plane
Then for projecting back and forth is just an affair of applying the transformation described by the estimated axes vectors

Calculating object position from image processing

I am looking for an efficient way to calculate the position of an oject on a surface based on an image taken from a certain perspective.
Let me explain a little further.
There is an object on a rectangular flat surface.
I have a picture taken of this setup with the camera positioned at one of the corners of the surface area at a rather low angle.
On the picture I will thus see a somewhat distorted, diamond-shaped view of the surface area and somewhere on it the object.
Through some image processing I do have the coordinates of the object on the picture but now have to calculate the actual position of the object on the surface.
So I do know that the center of the object is at the pixel-coordinates (x/y) on the picture and I know the coordinates of the 4 reference points that represent the corners of the area.
How can I now calculate the "real world" position of the object most efficiently (x and y coordinates on the surface)?
Any input is highly appreciated since I have worked so hard on this I can't even think straight anymore.
Best regards,
Tom
You have to find a perspective transformation.
Here you may find an explanation and code in Matlab
HTH!
How good is your linear algebra? A perspective transformation can be described by a homography matrix. You can estimate that matrix using the four corner points, invert it and the calculate the world coordinates of every pixel in your image.
Or you can just let OpenCV do that for you.

Resources