I am working with OpenCV 3.1 and with Python.
My problem comes when I try to deskew (fix the tilt of) an image with text. I am using cv2.warpPerspective
The problem is related to the interpolation required by the warping. If you don't want things to appear smoother, you should switch from default interpolation method, which is INTER_LINEAR
to another one, such as INTER_NEAREST
. It would help you with the sharpness of the edges.
Try flags=cv2.INTER_NEAREST
on your warp
call, be it warpAffine() or warpPerspective().
Interpolation flags are listed here.
enum InterpolationFlags {
INTER_NEAREST = 0,
INTER_LINEAR = 1,
INTER_CUBIC = 2,
INTER_AREA = 3,
INTER_LANCZOS4 = 4,
INTER_MAX = 7,
WARP_FILL_OUTLIERS = 8,
WARP_INVERSE_MAP = 16
}