コード例 #1
0
ファイル: lineseg.py プロジェクト: greggaba/evolution_ocropy
 def charseg(self, line):
     """Segment a text line into potential character parts."""
     assert mean(line) > 0.5 * amax(line)
     line0 = amax(line) - line
     ccuts = contourcuts(line0,
                         maxdist=self.maxdist,
                         minrange=self.minrange,
                         mincdist=self.mincdist,
                         sigma=self.sigma,
                         r=self.rr,
                         s=self.s)
     line = maximum(0, line0 - ccuts)
     # line = line+self.ledge*maximum(0,roll(line,-1,1)-line)
     tracks = dplineseg2(line,
                         imweight=self.imweight,
                         bweight=self.bweight,
                         diagweight=self.diagweight,
                         debug=self.debug,
                         r=self.r)
     tracks = array(tracks < 0.5 * amax(tracks), 'i')
     tracks, _ = morph.label(tracks)
     self.tracks = tracks
     stracks = morph.spread_labels(tracks)
     rsegs = stracks * (line0 > 0.5 * amax(line0))
     if self.debug:
         figure("temp")
         subplot(311)
         morph.showlabels(tracks)
         subplot(312)
         morph.showlabels(stracks)
         subplot(313)
         morph.showlabels(rsegs)
         raw_input()
     return morph.renumber_by_xcenter(rsegs)
コード例 #2
0
ファイル: lineseg.py プロジェクト: greggaba/evolution_ocropy
 def charseg(self, line):
     """Segment a text line into potential character parts."""
     assert mean(line) > 0.5 * amax(line)
     line = amax(line) - line
     # line = line+self.ledge*maximum(0,roll(line,-1,1)-line)
     tracks = dplineseg2(line,
                         imweight=self.imweight,
                         bweight=self.bweight,
                         diagweight=self.diagweight,
                         debug=self.debug,
                         r=self.r,
                         threshold=self.threshold)
     tracks = array(tracks < 0.5 * amax(tracks), 'i')
     tracks, _ = morph.label(tracks)
     self.tracks = tracks  # for debuggin
     stracks = morph.spread_labels(tracks)
     rsegs = stracks * (line > 0.5 * amax(line))
     if 0:
         figure("temp")
         subplot(311)
         morph.showlabels(tracks)
         subplot(312)
         morph.showlabels(stracks)
         subplot(313)
         morph.showlabels(rsegs)
         raw_input()
     return morph.renumber_by_xcenter(rsegs)
コード例 #3
0
ファイル: lineseg.py プロジェクト: AI42/ocropy
def ccslineseg(image,debug=0):
    image = 1.0*(image>0.3*amax(image))
    sigma = 10.0
    smooth = filters.gaussian_filter(image,(sigma,1.0*sigma),mode='constant')
    center = (smooth==amax(smooth,axis=0)[newaxis,:])
    center = filters.maximum_filter(center,(3,3))
    center = morph.keep_marked(image>0.5,center)
    center = filters.maximum_filter(center,(2,2))
    center,_ = morph.label(center)
    center = morph.spread_labels(center)
    center *= image
    return center
コード例 #4
0
def ccslineseg(image,debug=0):
    image = 1.0*(image>0.3*amax(image))
    sigma = 10.0
    smooth = filters.gaussian_filter(image,(sigma,1.0*sigma),mode='constant')
    center = (smooth==amax(smooth,axis=0)[newaxis,:])
    center = filters.maximum_filter(center,(3,3))
    center = morph.keep_marked(image>0.5,center)
    center = filters.maximum_filter(center,(2,2))
    center,_ = morph.label(center)
    center = morph.spread_labels(center)
    center *= image
    return center
コード例 #5
0
ファイル: lineseg.py プロジェクト: AI42/ocropy
 def charseg(self,line):
     """Segment a text line into potential character parts."""
     assert mean(line)>0.5*amax(line)
     line = amax(line)-line
     # line = line+self.ledge*maximum(0,roll(line,-1,1)-line)
     tracks = dplineseg2(line,imweight=self.imweight,bweight=self.bweight,
                         diagweight=self.diagweight,debug=self.debug,r=self.r,
                         threshold=self.threshold)
     tracks = array(tracks<0.5*amax(tracks),'i')
     tracks,_ = morph.label(tracks)
     self.tracks = tracks # for debuggin
     stracks = morph.spread_labels(tracks)
     rsegs = stracks*(line>0.5*amax(line))
     if 0:
         figure("temp")
         subplot(311); morph.showlabels(tracks)
         subplot(312); morph.showlabels(stracks)
         subplot(313); morph.showlabels(rsegs)
         raw_input()
     return morph.renumber_by_xcenter(rsegs)
コード例 #6
0
ファイル: lineseg.py プロジェクト: AI42/ocropy
 def charseg(self,line):
     """Segment a text line into potential character parts."""
     assert mean(line)>0.5*amax(line)
     line0 = amax(line)-line
     ccuts = contourcuts(line0,maxdist=self.maxdist,minrange=self.minrange,
                         mincdist=self.mincdist,sigma=self.sigma,r=self.rr,s=self.s)
     line = maximum(0,line0-ccuts)
     # line = line+self.ledge*maximum(0,roll(line,-1,1)-line)
     tracks = dplineseg2(line,imweight=self.imweight,bweight=self.bweight,
                         diagweight=self.diagweight,debug=self.debug,r=self.r)
     tracks = array(tracks<0.5*amax(tracks),'i')
     tracks,_ = morph.label(tracks)
     self.tracks = tracks
     stracks = morph.spread_labels(tracks)
     rsegs = stracks*(line0>0.5*amax(line0))
     if self.debug:
         figure("temp")
         subplot(311); morph.showlabels(tracks)
         subplot(312); morph.showlabels(stracks)
         subplot(313); morph.showlabels(rsegs)
         raw_input()
     return morph.renumber_by_xcenter(rsegs)