我试着改变图像的透视图,这样我得到的结果就是前视图的透视图。我正在使用cv2.0透视函数。但是,在执行扭曲时,图像的某些部分会被切断。我怎样才能避免这种情况?我认为的一个选择是找到图像特定部分的变换矩阵,然后将该矩阵应用于整个图像。然而,这种方法并没有产生令人满意的结果
我使用的代码是:
import numpy as np
import cv2
from google.colab.patches import cv2_imshow
img = cv2.imread("drive/My Drive/Images_for_Adarsh/DSC_0690.JPG")
height,width = 1000,1500
img = cv2.resize(img,(width,height))
pts1 = np.float32([[ 250, 0],[1220, 300],[1300, 770],[ 250, 860]])
pts2 = np.float32([[0,0],[width,0],[width,height],[0,height]])
matrix = cv2.getPerspectiveTransform(pts1,pts2)
print(matrix.shape)
print(matrix)
imgOutput = cv2.warpPerspective(img,matrix,(width,height))
cv2_imshow(imgOutput)
cv2.imwrite("drive/My Drive/PerspectiveWarp-Results1/0690_coarse/0690([[ 250, 0],[1220, 300],[1300, 770],[ 250, 860]]).JPG",imgOutput)
输入图像:
扭曲的图像:
下面是一种在Python/OpenCV中扭曲图像并添加额外空间的简单方法,该空间将包含更多的输入,但将输入之外的区域作为透明区域
输入:
注意:应该可以使用矩阵将输入角点投影到输出域,并计算所需的输出大小以容纳所有扭曲的输入
相关问题 更多 >
编程相关推荐