Python 在旋转的ROI上进行无缝连接

Python 在旋转的ROI上进行无缝连接,python,opencv,Python,Opencv,输出: 所以你可以看到分割两个三角形的线-连接不是无缝的。 有什么建议可以让连接无缝吗?现在看看这个神奇的地方: import cv2 import numpy as np lena = cv2.imread('lena.jpg') height, width = lena.shape[:2] a = 250 # equilateral triangle side h = a * (3 ** .5) / 2 # equilateral triangle height # triangl

输出:

所以你可以看到分割两个三角形的线-连接不是无缝的。
有什么建议可以让连接无缝吗?

现在看看这个神奇的地方:

import cv2
import numpy as np

lena = cv2.imread('lena.jpg')
height, width = lena.shape[:2]

a = 250  # equilateral triangle side
h = a * (3 ** .5) / 2  # equilateral triangle height

# triangle points to be used for masking the image
tri = np.array([[0, h], [a / 2, 0], [a, h]], np.float32)

mask = np.zeros((height, width), dtype=np.uint8)
cv2.fillConvexPoly(mask, tri.astype(np.int32), (255, 255, 255))
tri_crop = cv2.bitwise_and(lena, lena, mask=mask)

# new triangle points
tri_trans = np.array([[3 * a / 2, 0], [a / 2, 0], [a, h]], np.float32)

# transform inital triangle to new triangle points
aff_trans = cv2.getAffineTransform(tri, tri_trans)
tri_warp = cv2.warpAffine(tri_crop, aff_trans, (width, height))

# join triangles together
new_canvas = cv2.bitwise_or(tri_crop, tri_warp)

cv2.imwrite('lena.png', new_canvas)
tri_crop[tri_crop == 0] = tri_warp[tri_crop == 0]