def sizeFiltering(contours):
#this function filters out the smaller retroreflector (as well as any noise) by size
#_, contours, _ = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
"""blank_image = np.zeros((img.shape[0],img.shape[1],3), np.uint8)
cv2.drawContours(blank_image, contours, -1, (255, 255, 255))
cv2.imshow("imagia", blank_image)
cv2.waitKey()"""
if len(contours) == 0:
print "errorrrrr"
return 0
big = contours[0]
for c in contours:
if type(c) and type(big) == np.ndarray:
if cv2.contourArea(c) > cv2.contourArea(big):
big = c
else:
print type(c) and type(big)
return 0
"""blank_image = np.zeros((img.shape[0],img.shape[1],3), np.uint8)
cv2.drawContours(blank_image, big, -1, (255, 255, 255))
cv2.imshow("imagia", blank_image)
cv2.waitKey()"""
"""blank_image = np.zeros((img.shape[0],img.shape[1],3), np.uint8)
cv2.drawContours(blank_image, big, -1, (255, 255, 255))"""
x,y,w,h = cv2.boundingRect(big)
"""cv2.rectangle(blank_image, (x,y), (x+w, y+h), (255,255,255))
cv2.imshow("rect", blank_image)
cv2.waitKey()"""
return big
评论列表
文章目录