def blobdetect(img):
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
yellowMin = (20,100,100)
yellowMax = (30, 255, 255)
blueMin=(50,100,100)
blueMax=(100,255,255)
brownMin=(0,100,0)
brownMax=(20,255,255)
yellow=cv2.inRange(hsv,yellowMin, yellowMax)
blue=cv2.inRange(hsv,blueMin,blueMax)
brown=cv2.inRange(hsv,brownMin,brownMax)
params = cv2.SimpleBlobDetector_Params()
params.filterByArea = True
params.minArea=150
detector=cv2.SimpleBlobDetector(params)
keypoints=detector.detect(255-yellow)
food=[]
for i in keypoints:
x=i.pt[0]; y=i.pt[1]
food.append([x,y])
params.maxArea=250
detector=cv2.SimpleBlobDetector(params)
keypoints=detector.detect(255-yellow)
wood=[]
for i in keypoints:
x=i.pt[0]; y=i.pt[1]
wood.append([x,y])
params=cv2.SimpleBlobDetector()
keypoints=params.detect(255-blue)
rivers=[]
for i in keypoints:
x=i.pt[0]; y=i.pt[1]
rivers.append([x,y])
keypoints=params.detect(255-brown)
centre=[]
for i in keypoints:
x=i.pt[0]; y=i.pt[1]
centre.append([x,y])
return [food, wood, rivers, centre]
评论列表
文章目录