以下是一个简单的上下
文火点算法监测森林火灾的代码示例:
```python
im
port cv2
im
port numpy as np
# 读取图像
img = cv2.imread(
'forest.jpg
')
# 转换为灰度图像
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 模糊处理
blur = cv2.GaussianBlur(gray, (7,7), 0)
# 边缘检测
edges = cv2.Canny(blur, 50, 150)
# 膨胀处理
kernel = np.o
nes((5,5), np.uint8)
dilate = cv2.dilate(edges, kernel, iterations=1)
# 查找轮廓
contours, hierarchy = cv2.findCo
ntours(dilate, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
# 绘制矩形框
for co
ntour in contours:
x,y,w,h = cv2.boundingRect(contour)
if w > 50 and h > 50:
cv2.rectangle(img, (x,y), (x+w,y+h), (0,255,0), 2)
# 显示图像
cv2.imshow(
'image
', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```