我指的是此SOF链接计数图像中的彩色点, 但这是针对彩色链接的,因此这里的任何人都可以指导我如何处理该问题并从白底白点黑点。
thredhold使用THRESH_BINARY_INV标志,更改为black-background-white-foreground。findContours,按面积过滤轮廓(由计算contourArea)import cv2
gray = cv2.imread("dots.jpg", 0)
## threshold
th, threshed = cv2.threshold(gray, 100, 255,cv2.THRESH_BINARY_INV|cv2.THRESH_OTSU)
## findcontours
cnts = cv2.findContours(threshed, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2]
## filter by area
s1= 3
s2 = 20
xcnts = []
for cnt in cnts:
if s1<cv2.contourArea(cnt) <s2:
xcnts.append(cnt)
print("Dots number: {}".format(len(xcnts)))
#Dots number: 23
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3670 次 |
| 最近记录: |