【发布时间】:2022-01-17 23:42:49
【问题描述】:
我正在尝试使用 warpPerspective 转换在囤积板上实现皮卡丘图像。输出没有平滑的边缘,而是有点。
import cv2
import numpy as np
image = cv2.imread("base_img.jpg")
h_base, w_base = image.shape[0], image.shape[1]
white_subject = np.ones((480,640,3),dtype="uint8")*255
h_white, w_white = white_subject.shape[:2]
subject = cv2.imread('subject.jpg')
h_sub, w_sub = subject.shape[:2]
pts2 = np.float32([[109,186],[455,67],[480,248],[90,349]])
pts3 = np.float32([[0, 0], [w_white, 0], [w_white, h_white], [0, h_white]])
transformation_matrix_white = cv2.getPerspectiveTransform(pts3, pts2)
mask = cv2.warpPerspective(white_subject, transformation_matrix_white, (w_base, h_base))
image[mask==255] = 0
pts3 = np.float32([[0, 0], [w_sub, 0], [w_sub, h_sub], [0, h_sub]])
transformation_matrix = cv2.getPerspectiveTransform(pts3, pts2)
warped_image = cv2.warpPerspective(subject, transformation_matrix, (w_base, h_base))
囤积板图片
皮卡丘图片
输出图像
图案图像
请帮助我获得边缘没有虚线的输出。
【问题讨论】:
-
我不明白你如何将扭曲的主题与背景结合起来。你只是带着面具复制吗?
-
我正在使用 transformation_matrix_white 创建蒙版图像。在面具图像的帮助下,我将皮卡丘图像叠加在了围板上。
-
您需要通过模糊边缘来消除遮罩的锯齿。例如,请参阅我如何在 stackoverflow.com/questions/63001988/… 或 stackoverflow.com/questions/64208431/… 使用 Gaussianblur 和 skimage.exposure.rescale_intensity()
-
这里我的意思是平滑边缘就像输出应该有像原始图像边缘一样的边缘。
-
如果你没有一个常量颜色,那么在warpPerspective中为borderConstant使用cv.BORDER_REFLECT。这可能有助于缓解黑色虚线轮廓。
标签: python opencv computer-vision