【问题标题】:OpenCV Python - integer argument expected, got floatOpenCV Python - 需要整数参数,得到浮点数
【发布时间】: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) 强制中心,但仍然收到断言失败错误
  • 您可以编辑您的问题并包含完整的回溯吗?

标签: python opencv


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    相关资源
    最近更新 更多