Traceback (most recent call last): File…
- User
Traceback (most recent call last): File "/opt/conda/envs/zyh/lib/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "mskcompletion.py", line 43, in process_single_image guided_img = guided_filter(input_img, mask, radius, eps) File "mskcompletion.py", line 9, in guided_filter return cv2.ximgproc.guidedFilter(mask, input_img, radius, eps, -1) cv2.error: OpenCV(4.9.0) /io/opencv_contrib/modules/ximgproc/src/guided_filter.cpp:717: error: (-201:Incorrect size of input array) Size of filtering image must be equal to size of guide image in function 'filter'
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "mskcompletion.py", line 68, in process_images(mask_folder, depth_folder, output_folder, radius=2, eps=0.01) File "mskcompletion.py", line 60, in process_images list(tqdm(pool.imap(process_single_image, args), total=len(depth_files), desc="Processing images", unit="file")) File "/opt/conda/envs/zyh/lib/python3.8/site-packages/tqdm/std.py", line 1182, in iter for obj in iterable: File "/opt/conda/envs/zyh/lib/python3.8/multiprocessing/pool.py", line 868, in next raise value cv2.error: OpenCV(4.9.0) /io/opencv_contrib/modules/ximgproc/src/guided_filter.cpp:717: error: (-201:Incorrect size of input array) Size of filtering image must be equal to size of guide image in function 'filter'
- Assistant
The error you are encountering indicates that there is a size mismatch between the input image and the guide image when calling the function in OpenCV. Specifically, the error message states that the size of the filtering image (in this case, ) must be equal to the size of the guide image (in this case, ).
- User
请说中文
- Assistant
好的!您看到的错误是因为在调用 OpenCV 的
cv2.ximgproc.guidedFilter函数时,输入图像(input_img)和引导图像(mask)的尺寸不匹配。具体来说,错误信息表示用于滤波的图像的大小必须与引导图像的大小相等。要解决这个问题,您可以按照以下步骤进行排查和修复:
-
验证维度: 在调用
cv2.ximgproc.guidedFilter之前,检查input_img和mask的维度是否相同。可以在调用之前打印它们的形状:print("输入图像形状:", input_img.shape) print("掩膜形状:", mask.shape) -
调整大小或裁剪: 如果发现
input_img和mask的维度不同,您需要调整其中一个图像的大小,以匹配另一个图像的维度。以下是如何调整掩膜的大小的示例:if input_img.shape != mask.shape: mask = cv2.resize(mask, (input_img.shape[1], input_img.shape[0]))确保选择适合您具体应用的调整方法。
-
检查输入源: 确保从
mask_folder或depth_folder中加载的图像是否正确。如果加载图像时出现问题,可能会导致尺寸不匹配。 -
调试信息: 添加额外的日志或打印语句,以帮助识别导致问题的图像。例如,您可以在处理每个图像时包含文件名或标识符。
-
- User
- Assistant