Beispiel #1
0
def sector_count(line):
    (orig,dest)=line
    sector = getsector(orig[0],orig[1],dest[0],dest[1])
    li = cv.InitLineIterator(sector_maps[sector],orig,dest,8)
    li2 = cv.InitLineIterator(sector_maps[(sector+1)%8],orig,dest,8)
    li3 = cv.InitLineIterator(sector_maps[(sector+7)%8],orig,dest,8)
    return sum(li)+sum(li2)+sum(li3)
Beispiel #2
0
def line_whiteness(img, pt1, pt2):
    """
    線分の白の割合を調べる
    """

    sum = 0.0
    count = 0.0

    p1 = (int(pt1[1]), int(pt1[0]))  # なんか逆
    p2 = (int(pt2[1]), int(pt2[0]))
    li = cv.InitLineIterator(cv.fromarray(img), p1, p2)
    ther_color = 240

    for (r, g, b) in li:
        sum += 1
        if (r >= ther_color and g >= ther_color and b >= ther_color):
            count += 1

    return count / sum
Beispiel #3
0
    def get_line(self,p1,p2,img):
        a,b = v.vector(p1, p2)
        if a>b:l=a
        else:l=b
        if l==0: return [],[]
        li=cv.InitLineIterator(img, p1, p2,8)
        points=[]
        for i,c in enumerate(li):
            points.append(c)
        l=len(points)
        if len(points)==0:
            return [],[]
        vec=(a/float(l),b/float(l))
        real_p=[]
        for i in range(l):
#            list.append(c)
#        for i in range(l):
            p=v.int_point(v.add(p1,vec,i))
            real_p.append(p)
#            points.append(img[p[1],p[0]]);
        return points,real_p
Beispiel #4
0
 def coords(self, image):
     original = self.endPoints()
     (x1, y1), (x2, y2) = original
     try:
         clipped = cv.ClipLine((self.w, self.h), (int(x1), int(y1)),
                               (int(x2), int(y2)))
     except:
         print self.alpha, self.pos
         raise
     if clipped is None:
         return None
     (x1c, y1c), (x2c, y2c) = clipped
     iter = cv.InitLineIterator(image, *clipped)
     clip = tuple(iter)
     cliplenpts = len(clip)
     cliplen = dist2D(*clipped)
     origlen = dist2D(*original)
     clipoff = dist2D((x1, y1), (x1c, y1c))
     origpist = origlen / 2.0
     clippist = origpist - clipoff
     clippistpt = (cliplenpts * clippist) / cliplen
     return (int(clippistpt), clip)
 def testAt(self, image, off):
     crd = self.coords(off)
     if crd is None:
         return 0
     iter = cv.InitLineIterator(image, *crd)
     return sum(iter)