cv2.drawContours
突出显示轮廓。您可能需要调整参数以获得所需的输出结果。结果如下:->
输出
import cv2
import numpy as np
# Load image, grayscale, Gaussian blur, Adaptive threshold
image = cv2.imread('2.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (9,9), 0)
thresh = cv2.adaptiveThreshold(blur,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV,23,3)
# Find contours and filter using contour area
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
area = cv2.contourArea(c)
if area > 10:
cv2.drawContours(image, [c], -1, (36,255,12), 1)
cv2.imshow('thresh', thresh)
cv2.imshow('image', image)
cv2.waitKey()