基于RGB的水体提取

# -*- coding:utf-8 -*-
import cv2
import numpy

image = cv2.imread("01.jpg")
cv2.namedWindow("original", 0)
# cv2.resizeWindow("original", 400, 400)
cv2.imshow("original", image)


# BGR = numpy.array([90,98,67])
BGR = numpy.array([246, 217, 180])
upper = BGR + 10
lower = BGR - 10
mask = cv2.inRange(image, lower, upper)  # 设置阈值进行掩膜
cv2.namedWindow("Mask", 0)
cv2.imshow("Mask", mask)
# cv2.waitKey(0)

(_, contours, hicrarchy) = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
print("number of contours:%d" % (len(contours)))  # 边缘检测

alllakesImage = image.copy()
cv2.drawContours(alllakesImage, contours, -1, (0, 0, 255), 2)
cv2.namedWindow("Image of All Lake", 0)
cv2.imshow("Image of All Lake", alllakesImage)
cv2.waitKey(0)

# theLargestLake = image.copy()
# contours.sort(key=len, reverse=True)
# cv2.drawContours(theLargestLake, [contours[0]], -1, (0, 0, 255), 2)
# cv2.imshow("Image of the Largest Lake", theLargestLake)
# cv2.waitKey(0)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值