Changeset - 28c6f89a3a7e
[Not reviewed]
default
0 1 0
Laman - 6 years ago 2019-02-09 12:59:46

stone detection enhanced by edge subtraction
1 file changed with 12 insertions and 8 deletions:
0 comments (0 inline, 0 general)
exp/board_detect.py
Show inline comments
 
@@ -105,7 +105,11 @@ class BoardDetector:
 
		# quantize colors
 
		colors=self._sampleColors(rect)
 
		quantized=quantize(rect,colors)
 
		show(quantized,filename)
 
		gray=cv.cvtColor(rect,cv.COLOR_BGR2GRAY)
 
		edges=cv.Canny(gray,70,130)
 
		show(edges,"edges")
 
		quantized=quantized & (255-cv.cvtColor(edges,cv.COLOR_GRAY2BGR))
 
		show(quantized,"quantized, edges separated")
 

	
 
		# detect black and white stones
 
		stones=self._detectStones(quantized,colors)
 
@@ -165,16 +169,16 @@ class BoardDetector:
 

	
 
	def _maskStones(self,quantized,colors):
 
		unit=np.array([1,1,1],dtype=np.uint8)
 
		kernel=np.ones((3,3),np.uint8)
 
		maskB=cv.inRange(quantized,colors[0]-unit,colors[0]+unit)
 
		maskB=cv.morphologyEx(maskB,cv.MORPH_OPEN,kernel,iterations=1)
 
		maskB=cv.erode(maskB,kernel,iterations=3)
 
		# distTransform = cv.distanceTransform(maskB,cv.DIST_L2,5)
 
		# maskB=cv.inRange(distTransform,6,10)
 

	
 
		distTransform=cv.distanceTransform(maskB,cv.DIST_L2,5)
 
		maskB=cv.inRange(distTransform,6,20)
 
		show(maskB,"black areas")
 

	
 
		maskW=cv.inRange(quantized,colors[1]-unit,colors[1]+unit)
 
		maskW=cv.morphologyEx(maskW,cv.MORPH_OPEN,kernel,iterations=1)
 
		maskW=cv.erode(maskW,kernel,iterations=2)
 
		distTransform=cv.distanceTransform(maskW,cv.DIST_L2,5)
 
		maskW=cv.inRange(distTransform,6,20)
 

	
 
		show(maskW,"white areas")
 
		stones=cv.bitwise_or(maskB,maskW)
 
		show(stones,"black and white areas")
0 comments (0 inline, 0 general)