diff --git a/exp/hough.py b/exp/hough.py --- a/exp/hough.py +++ b/exp/hough.py @@ -27,7 +27,8 @@ class HoughTransform: def extract(self): shift=self._diagLen//2 - peaks=sorted(list(findPeaks(self._acc)),key=lambda rc: self._acc[rc],reverse=True)[:2*19] + allPeaks=sorted(list(findPeaks(self._acc)),key=lambda rc: self._acc[rc],reverse=True) + peaks=allPeaks[:38] peaks=[(alpha,d-shift) for (alpha,d) in peaks] peaks=self._filterClose(peaks) peaks.sort(key=lambda rc: rc[0]) @@ -35,6 +36,7 @@ class HoughTransform: (alpha,beta)=self._detectDominantAngles(peaks) img=self._createImg() + img=self._markPeaks(img,self._filterClose(allPeaks[:38])) doublePeaks=peaks+[(alpha+180,-d) for (alpha,d) in peaks] params=self._computeGridParams([(gamma,d+shift) for (gamma,d) in doublePeaks if alpha<=gamma<=alpha+self._angleBandwidth]) self._drawGridCurve(img,params,0) @@ -63,7 +65,7 @@ class HoughTransform: """Discard points with Euclidean distance on the original image lower than 10. From such pairs keep only the one with a higher value in the accumulator. This can delete a series of points. If a-b and b-c are close and a>b>c, only a is kept.""" - minDist=10 + minDist=13 center=EPoint(*self._center) res=[] for (alphaDeg,d) in peaks: @@ -93,7 +95,7 @@ class HoughTransform: log.debug("angles histogram: %s",histogram) dominantAngles=sorted(histogram,key=lambda xy: xy[1],reverse=True) alpha=dominantAngles[0] - dominantAngles=[beta for beta in dominantAngles if 165>abs(alpha[0]-beta[0])>15] + dominantAngles=[beta for beta in dominantAngles if 180-bandwidth>abs(alpha[0]-beta[0])>bandwidth] beta=dominantAngles[0] log.debug("dominant angles: %s, %s",alpha,beta) return (alpha[0],beta[0]) @@ -126,6 +128,12 @@ class HoughTransform: return img + def _markPeaks(self,img,peaks): + colors=[[255,0,0],[255,255,0],[0,255,0],[0,255,255],[0,0,255]] + for (i,(alpha,d)) in enumerate(peaks[:38]): + cv.drawMarker(img,(d,alpha),colors[i//9],cv.MARKER_TILTED_CROSS) + return img + def _drawGridCurve(self,img,params,colorKey=0): colors=[[0,255,255],[255,0,255],[255,255,0]] color=colors[colorKey]