# -*- 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)
基于RGB的水体提取
最新推荐文章于 2024-11-29 12:01:35 发布