python - Image loses quality with cv2.warpPerspective -
i working opencv 3.1 , python.
my problem comes when try deskew (fix tilt of) image text. using cv2.warpperspective
make possible, image loses lot of quality. can see here original part of image:
and then, here, "rotated" image:
it smoothed.
i using morphological transformation like:
kernel = np.ones((2, 2), np.uint8) blur_image = cv2.erode(tresh, kernel, iterations=1)
and
white_mask2 = cv2.morphologyex(white_mask2, cv2.morph_open, kernel)
to see if improves something, nothing.
i saw this example here in so, guys had same problem: ,
so, don't have idea can do. maybe there way not losing quality of image, or, there's method rotate image without quality lost. know method:
root_mat = cv2.getrotationmatrix2d(to_rotate_center, angle, 1.0) result = cv2.warpaffine(to_rotate, root_mat, to_rotate.shape, flags=cv2.inter_linear)
but doesn't work me, have rotate every rectangle here:
and not whole image. means, best way found it, warpperspective
, , works fine, quality loss. appreciate advice avoid quality lost.
the problem related interpolation required warping. if don't want things appear smoother, should switch default interpolation method, inter_linear
one, such inter_nearest
. sharpness of edges.
try flags=cv2.inter_nearest
on warp
call, warpaffine() or warpperspective().
interpolation flags 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 }
Comments
Post a Comment