【发布时间】:2021-05-04 07:37:25
【问题描述】:
我正在尝试像这样运行无缝克隆功能...
# Read images : src image will be cloned into dst
im = cv2.imread('background.jpg')
obj= cv2.imread('object.png')
# Create an all white mask
mask = 255 * np.ones(obj.shape, obj.dtype)
# The location of the center of the src in the dst
width, height, channels = im.shape
center = (height/2, width/2)
# Seamlessly clone src into dst and put the results in output
normal_clone = cv2.seamlessClone(obj, im, mask, center, cv2.NORMAL_CLONE)
mixed_clone = cv2.seamlessClone(obj, im, mask, center, cv2.MIXED_CLONE)
# Write results
cv2.imwrite("output_images/opencv-normal-clone-example.jpg", normal_clone)
cv2.imwrite("output_images/opencv-mixed-clone-example.jpg", mixed_clone)
但它给了我错误......
integer argument expected, got float
有什么想法可以找出它不喜欢哪个论点吗?
【问题讨论】:
-
我感觉它来自您的
center = (height/2, width/2)计算。如果你碰巧给它一个奇数,它可能会产生一个非整数,而seamlessClone()函数可能需要一个整数。你可以尝试传入偶数的假数字,编译,看看你是否得到同样的错误。 -
或使用
center=(height//2, width//2)。 -
已尝试使用 center=(250,250) 强制中心,但仍然收到断言失败错误
-
您可以编辑您的问题并包含完整的回溯吗?