python opencv滤镜
时间: 2023-10-15 10:03:49 浏览: 142
opencv-python
Python中的OpenCV库提供了许多滤镜效果,可以通过对图像进行不同的处理来实现。以下是一些常见的滤镜效果:
1. 灰度化滤镜:
```python
import cv2
img = cv2.imread('image.jpg')
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('Gray Image', gray_img)
cv2.waitKey(0)
```
2. 边缘检测滤镜:
```python
import cv2
img = cv2.imread('image.jpg')
edges = cv2.Canny(img, 100, 200)
cv2.imshow('Edges', edges)
cv2.waitKey(0)
```
3. 模糊滤镜:
```python
import cv2
img = cv2.imread('image.jpg')
blur_img = cv2.blur(img, (5, 5))
cv2.imshow('Blur Image', blur_img)
cv2.waitKey(0)
```
4. 锐化滤镜:
```python
import cv2
import numpy as np
img = cv2.imread('image.jpg')
kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
sharp_img = cv2.filter2D(img, -1, kernel)
cv2.imshow('Sharp Image', sharp_img)
cv2.waitKey(0)
```
阅读全文