# Function to warp/straighten a curved/folded image?

**URL:** https://forum.opencv.org/t/function-to-warp-straighten-a-curved-folded-image/4855
**Category:** Python
**Tags:** imgproc
**Created:** [August 21, 2021, 2:23am UTC](https://forum.opencv.org/t/function-to-warp-straighten-a-curved-folded-image/4855 "2021-08-21T02:23:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gmaiab](https://avatars.discourse-cdn.com/v4/letter/g/e9a140/32.png) [@gmaiab](https://forum.opencv.org/u/gmaiab)
#### Post date: [August 21, 2021, 2:23am UTC](https://forum.opencv.org/t/function-to-warp-straighten-a-curved-folded-image/4855/1 "2021-08-21T02:23:21Z")

</div>

Hello! 😁

I was wondering if there is a function in OpenCV to straighten a region in an image.

 ![Untitled](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/1/145ea48269532fd2dea222c876b58da8ca14a73b.jpeg)

If I have an image that is just skewed, the _getPerspectiveTransform_ and _warpPerspective_ functions do a good job to straighten it, like shown in Figure 1.

However, if the card/document in the picture is kind of curved or folded, _getPerspectiveTransform_ and _warpPerspective_ were not enough to solve the problem, because they end up cropping information at the bottom and they leave background at the top (Figure 2).

I’m able to find the _contour_ of the card/document. **I was wondering if there is a function that could help me achieve the desired output shown in Figure 3.**

I would really appreciate if anyone could guide or suggest me a way to solve this problem!

Thank you! 😊

---

<div class="post-metadata">

### Author: ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)
#### Post date: [August 21, 2021, 6:43am UTC](https://forum.opencv.org/t/function-to-warp-straighten-a-curved-folded-image/4855/2 "2021-08-21T06:43:03Z")

</div>

have a look at the [remapping tutorial](https://docs.opencv.org/master/d1/da0/tutorial_remap.html)

however, you will have to find your own x y mapping for each image, there is no “general” case here.
