python高斯滤波批量处理图片代码
时间: 2023-04-02 10:01:29 浏览: 110
python 批量处理图片程序
您好,以下是 Python 高斯滤波批量处理图片的代码示例:
```python
import cv2
import os
def gaussian_blur(img_path, kernel_size):
img = cv2.imread(img_path)
img_blur = cv2.GaussianBlur(img, (kernel_size, kernel_size), )
return img_blur
def batch_gaussian_blur(folder_path, kernel_size):
for filename in os.listdir(folder_path):
if filename.endswith('.jpg') or filename.endswith('.png'):
img_path = os.path.join(folder_path, filename)
img_blur = gaussian_blur(img_path, kernel_size)
cv2.imwrite(os.path.join(folder_path, 'blur_' + filename), img_blur)
batch_gaussian_blur('/path/to/folder', 5)
```
希望对您有帮助!
阅读全文