关于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, -1instead of(-1, -1), you're passing two separate integer arguments instead of one tuple. OpenCV would then treat the first-1as theanchorparameter, 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),imgwould beNone. This can sometimes cause unexpected parameter parsing errors downstream, even though the error message points directly toanchor.
Fixes you can try right away:
- Omit the anchor parameter entirely:
(-1, -1)is actually the default value foranchor(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) - 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
相关产品推荐
相关产品推荐

