Veer
Veer

Reputation: 211

Alternative to opencv warpPerspective

I am using opencv warpPerspective() function to warp the found countour in the image to find contour i am using findContours().

This is shown in this image:

enter image description here

but the warpPerspective() function takes "more time" to warp to full image is there any alternative to this function to warp the object in image to full image as shown in figure. OR will traversing help?but this would be difficult to do so that i can reduce the time the warpPerspective() function takes.

Upvotes: 2

Views: 2364

Answers (1)

Bolat Tleubayev
Bolat Tleubayev

Reputation: 1855

You can try to work on rotation and translation matrices (or roto-translational matrix, a combination of both), which can warp image as you wish. The function warpPerspective() utilizes similar approach, so you will basically will have an opportunity to look inside the function.

The approach is:

  1. You calculate the matrix, then multiply the height and width of the original image to find dimensions of the output image.

  2. Go through all pixels in the original image and multiply their (x,y) coordinates to the matrix R (rotation/translation/roto-translation matrix) to get the coordinates on the output image (xo,yo).

  3. On every calculated coordinate (xo,yo) assign value from the corresponding original image coordinate (x,y).

  4. Interpolate using median filter/bilinear/bicubic/etc. method as sometimes there may be empty points left on the output image

However, if you work in Python your implementation may work even slower than warpPerspective(), so you may consider C++. Another thing is that OpenCV uses C++ compiler and I am pretty sure that implementation of warpPerspective() in OpenCV is very efficient.

So, I think that you can go around warpPerspective(), however, I am not sure if you can do it faster than in OpenCV without any boosts (like GPU, powerful CPU etc.) :)

Good luck!

Upvotes: 1

Related Questions