Merge pull request #30 from CuteCat1111/feature_lens_distortion

Add lens distortion (Fisheye) effect
pull/31/head
Kohaku-Blueleaf 2023-06-22 08:15:56 +08:00 committed by GitHub
commit 892467be25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import enum
import cv2
import numpy as np
from PIL import Image
def run(np_img, k1, k2):
height, width = np_img.shape[:2]
focal_length = width
center_x = width / 2
center_y = height / 2
K = np.array(
[[focal_length, 0, center_x], [0, focal_length, center_y], [0, 0, 1]], dtype=np.float64,
)
D = np.array([k1, k2, 0, 0], dtype=np.float64)
img = cv2.fisheye.undistortImage(np_img, K, D, Knew=K)
return Image.fromarray(img)