InA*_*ash 4 python opencv computer-vision
我想找一个复选框([
])1
检查与否.到目前为止,我尝试使用pyimagesearch中使用的方法.我试图查看图像中是否有任何三角形.如果至少有一个三角形,则表示选中了复选框.我发现的问题是,有时检测外部矩形而不是三角形.我应该如何忽略矩形并仅检测三角形
我认为您甚至不需要使用层次结构信息,只需计算轮廓数量并使用它来对图像进行分类.我给出了一个简单的python实现来查看各个轮廓.
OpenCV中的轮廓层次结构表示已在此处解释Contour Hierachy
img = cv2.imread(r'D:/Image/cross.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret,bw = cv2.threshold(gray,220,255,cv2.THRESH_BINARY_INV)
_,contours,hierarchy = cv2.findContours(bw, cv2.RETR_CCOMP,1)
cntLen = 10
ct = 0 #number of contours
for cnt in contours:
if len(cnt) > cntLen: #eliminate the noises
ct += 1
newimg = img.copy()
cv2.drawContours(newimg,[cnt],0,(0,0,255),2)
cv2.imshow('Win', newimg)
cv2.waitKey(0)
print('Total contours: ',ct)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3835 次 |
| 最近记录: |