numpy OpenCV的翘曲中的错误

f4t66c6m  于 2023-05-17  发布在  其他
关注(0)|答案(1)|浏览(121)

即使Angular 的微小变化,小至0.001,也会导致显著不同的结果。在分析ROI时,明显的是,不存在具有高度592的区域。扭曲的图像似乎具有擦除的有效区域。在70度至90度的Angular 范围内观察到这种现象。
是否有任何可能的解决办法或办法来处理这个问题?

import cv2
import numpy as np

from scipy.spatial.transform import Rotation

def plot_image(img, figsize_in_inches=(5, 5)):
    fig, ax = plt.subplots(figsize=figsize_in_inches)
    ax.imshow(cv.cvtColor(img, cv.COLOR_BGR2RGB))
    plt.show()

img = cv2.imread('1.png')

image_height, image_width  = img.shape[:2]
focal_length = 800
print(focal_length)
image_center = (image_width / 2, image_height / 2)

K = np.array([[focal_length, 0, image_center[0]],
              [0, focal_length, image_center[1]],
              [0, 0, 1]], dtype=np.float32)

R = Rotation.from_euler('zxy',[0,   90, 0], degrees=True).as_matrix().astype(np.float32)
#R = Rotation.from_euler('zxy',[0,   90.001, 0], degrees=True).as_matrix().astype(np.float32)

warper = cv.PyRotationWarper("spherical", 1000)

_, warped_image = warper.warp(img,K, R, cv.INTER_LINEAR, cv.BORDER_CONSTANT)

warped_rois = warper.warpRoi((image_width, image_height), K, R)

print(warped_rois)
plot_image(warped_image)

你可以很容易地理解我想通过参考以下图像捕获。
对于90.001度:

对于90度:

bwitn5fc

bwitn5fc1#

如果你把x参数推得太远,似乎就超过了翘曲公式的极限。当左上角和右上角的弓碰到屏幕的角时,就会发生这种情况(窗口标题的格式是f"{deg:.2f}: {warped_rois}):

相关问题