You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于OpenCV中cv2.blur()函数报“Bad argument”错误的原因咨询

Hey there! Let's break down why you're running into this OpenCV error with the blur function.

The core problem here is that the anchor parameter you're passing isn't being recognized as a valid sequence (like a tuple or list) that OpenCV expects for this argument.

Looking at your code, you wrote (-1, -1) for anchor—which should be a valid tuple. But the error message tells us OpenCV can't parse it as a sequence, so here are the most likely culprits:

  • Accidental missing parentheses: If in your actual code you wrote -1, -1 instead of (-1, -1), you're passing two separate integer arguments instead of one tuple. OpenCV would then treat the first -1 as the anchor parameter, which is an integer (not a sequence), triggering the overload failure.
  • Failed image loading: If cv2.imread() couldn't load your image (maybe due to a typo in the file path), img would be None. This can sometimes cause unexpected parameter parsing errors downstream, even though the error message points directly to anchor.

Fixes you can try right away:

  1. Omit the anchor parameter entirely: (-1, -1) is actually the default value for anchor (it sets the anchor to the center of the kernel), so you don't need to specify it at all. Here's a cleaned-up version of your code with an important image check added:
    img = cv2.imread("C:....\\DogInCar.png", cv2.IMREAD_GRAYSCALE)
    # Always verify the image loaded successfully!
    if img is None:
        print("Error: Couldn't read the image. Double-check the file path!")
    else:
        blur = cv2.blur(img, (5, 5), borderType=cv2.BORDER_REFLECT)
    
  2. Double-check the anchor tuple: If you want to explicitly specify anchor, make sure you're using parentheses around the pair of integers (like (-1, -1)). This ensures OpenCV recognizes it as a valid sequence for the parameter.

That should resolve the overload resolution error you're seeing.

内容的提问来源于stack exchange,提问作者lkella

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.01 00:07:45