首页 > 解决方案 > OpenCV Python - 需要整数参数,得到浮点数

问题描述

我正在尝试像这样运行无缝克隆功能......

# 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

有什么想法可以找出它不喜欢的论点之一吗?

标签: pythonopencv

解决方案


当我以这种除以2的方式将中心保持为整数时,它起作用了:-

中心=(高度>>1,宽度>>1)


推荐阅读