openCV4Android smoothly correcting perspective

975 views Asked by At

I can correct perspective of rotated card that is in image by the way that is described in Automatic perspective correction for quadrilateral objects.It is fine and works well.But the result of correction appears suddenly.I want to do that smoothly.I mean I want to move card smoothly (not suddenly) to front us,until card be full screen.Excuse me for poor description,but you can see similar process in CamScanner after click on confirm button on interesting area selecting Activity.

Thank you for your attention.

1

There are 1 answers

5
Pervez Alam On BEST ANSWER

As per tutorial in your link [refer to my labelled image for marks], you have a, b, c, d four corners of the image and your ultimate goal is to warp-affine to target coordinates: a', b', c', d'.

But you want to do it gradually, showing like animation. Let us suppose you want to give 5 step-animation(more step, smoother the animation, higher the processing).

enter image description here

1) Using linear equation to find 4 more equidistant points between b and b'. Name it b1, b2, b3, b4. Do this for all corners i.e. a, b, c, d and name them in same manner.

2) Now apply warp-perspective first on target a1, b1, c1, d1 and show the output as 1st animation-step.

3) Repeat above step for all 4 steps and show your image.

4) At last show you result on warp affine on a', b', c', d'.

Here you can give some simple and fancy options like brightness, auto-contrast etc.

Two-points:

first, you see animation in cam-scanner is also slow.

Second, if you want to show animation smooth and fast, resize the image to half or quarter apply transformation and then resize back the resultant. This will be quite fast and as the intermediate steps are temp, you don't need to show the detailed image. Apart from this, you can use approximate transforms also.

Good Luck and Happy Coding!!