Beispiel #1
0
def test(image, char=None):
    classifications = MaskClassifications()
    m1 = make_mask(image, width=mask_table.width, height=mask_table.height)
    for c, m2 in mask_table.masks.items():
        s = cmp_masks(m1, m2)
        classifications.add(c, s)

    return classifications
Beispiel #2
0
 def mask(self, res):
     import mask
     
     lines = [ ]
     
     for points in self.triangles():
         points = [ (x*res,y*res) for x,y,z in points ]
         points = points + [ points[0] ]
         
         area = 0.0
         for i in range(len(points)-1):
             area += (
                 (points[i+1][0]-points[i][0])*
                 (points[i+1][1]+points[i][1])*0.5
             )
         if area > 0.0: 
             points = points[::-1]
         for i in range(len(points)-1):
             lines.append( points[i]+points[i+1] )
         
     return mask.make_mask(lines)
Beispiel #3
0
 def mask(self, res):
     import mask
     lines = [ (self[i][0]*res,self[i][1]*res,
                self[(i+1)%len(self)][0]*res,self[(i+1)%len(self)][1]*res)
               for i in range(len(self)) ]
     return mask.make_mask(lines)
Beispiel #4
0
 def add(self, char, image):
     mask = make_mask(image, width=self._w, height=self._h)
     self._masks[char] = mask