예제 #1
0
    def alignEyes(self, eye1, eye2, img):
        # distance between eyes:
        d = eye1.dist(eye2)
        self.meanShape.scale(d)

        rightEyeIx = 36
        leftEyeIx = 31

        ## Rotation
        xDiff = self.meanShape.shapePoints[
            rightEyeIx].x - self.meanShape.shapePoints[leftEyeIx].x
        yDiff = self.meanShape.shapePoints[
            rightEyeIx].y - self.meanShape.shapePoints[leftEyeIx].y

        p0 = [
            xDiff, yDiff
        ]  #self.meanShape.shapePoints[0].x, self.meanShape.shapePoints[0].y ]
        axisVector = [1, 0]
        thetaP = PASM.angleV(p0, axisVector)
        thetaRot = thetaP

        rot = [[math.cos(thetaRot), -math.sin(thetaRot)],
               [math.sin(thetaRot), math.cos(thetaRot)]]

        self.meanShape.rotate(rot)

        t = [[eye2.x - self.meanShape.shapePoints[rightEyeIx].x],
             [eye2.y - self.meanShape.shapePoints[rightEyeIx].y]]

        self.meanShape.translate(t)

        self.transDict = {}  #DANGER!!!!!!!
        self.transDict.update({'rot': rot, 't': t})
def run():

    asm = PASM([0,1], 1000 )
    allLines = []
    pts = []
    for f in files:
        with open( os.path.join( OUTPUT, f), "r" ) as infile:
        
            allLines = infile.readlines()
            if len(allLines) > 0:
                cleanLines = [ x.strip().split('\t') for x in allLines]
                ptList = [ Point( x[0], x[1]) for x in cleanLines ]
                print len( ptList ) 
                asm.addShape( Shape( ptList ) )



    asm.iterateAlignment()
def getGradient( pt, img ):
    img = np.array([])
    dx = img
    delF = [ (img[ pt.y, pt.x + 1] - img[pt.y, pt.x - 1 ] )/2,
            (img[ pt.y + 1 , pt.x] - img[pt.y - 1, pt.x ] )/2 ] 
    print delF
    mag = math.sqrt( delF[0] ** 2 + delF[1] ** 2 )
    dir = PASM.angleV( delF, [ 0, 0] )
    return mag, dir
def setup( ):
    s1 = Shape( [ Point(200,340), Point( 0, 200), Point( 350,200) ] )
    s2 = Shape( [ Point(210,320), Point( 5, 205), Point( 340,190) ] )
    s3 = Shape( [ Point(205,300), Point( 10, 190), Point( 344,204) ] )
    s4 = Shape( [ Point(199,380), Point( -5, 205), Point( 333,203) ] )
    s5 = Shape( [ Point(190,290), Point( 0, 190), Point( 351,201) ] )

    asm = PASM( [0,1], 10 )

    asm.addShape( s1 )
    asm.addShape( s2 )
    asm.addShape( s3 )
    asm.addShape( s4 )
    asm.addShape( s5 )
    return asm
예제 #5
0
    def getGradient(pt, img):
        if pt.x is np.nan or pt.y is np.nan:
            return
        ## Check bounds
        h, w = np.shape(img)
        if pt.y > h or pt.y > h - 1:
            pt.setY(h - 2)
        if pt.x > w or pt.x > w - 1:
            pt.setX(w - 2)

        delF = [(img[pt.y, pt.x + 1] - img[pt.y, pt.x - 1]) / 2,
                (img[pt.y + 1, pt.x] - img[pt.y - 1, pt.x]) / 2]
        #print delF
        mag = math.sqrt(delF[0]**2 + delF[1]**2)
        #dir = PASM.angleV( delF, [ 0, 0] )
        unitF = PASM.unitV(delF)

        return unitF, mag
예제 #6
0
def run():

    asm = PASM([0, 1], 1000)
    allLines = []
    pts = []
    for f in files:
        with open(os.path.join(OUTPUT, f), "r") as infile:

            allLines = infile.readlines()
            if len(allLines) > 0:
                cleanLines = [x.strip().split('\t') for x in allLines]
                ptList = [Point(x[0], x[1]) for x in cleanLines]
                print len(ptList)
                asm.addShape(Shape(ptList))

    asm.iterateAlignment()
                
                elif line is '}':
                    pointLine = False
                    pass
                elif pointLine:
                    ptList.append( map( float, line.split(' ') ) )
                else:
                    pass

        asm.addShape( Shape( ptList ) )
        m += 1
        print m
if __name__ == "__main__":

    DIR = "C:\\Users\\Valerie\\Desktop\\MicroExpress\\facePoints"
    SUBDIR = "session_1"
    folder = os.path.join( DIR, SUBDIR )
    files = next(os.walk(folder))[2]
    asm = PASM( [36,31], 100)
    readIn( asm, files)
    asm.iterateAlignment()
    with open( 'outfile-ASM-100iters-500tr.txt', "w") as output:
            output.write( str(asm.meanShape) )
            output.write( "!!!\n" )
            for shape in asm.allShapes:
                output.write(  str(shape) )
                output.write( "@@@\n" )
            output.write( "!!!\n" )

    
예제 #8
0
                elif line is '}':
                    pointLine = False
                    pass
                elif pointLine:
                    ptList.append(map(float, line.split(' ')))
                else:
                    pass

        asm.addShape(Shape(ptList))
        m += 1
        print m


if __name__ == "__main__":

    DIR = "C:\\Users\\Valerie\\Desktop\\MicroExpress\\facePoints"
    SUBDIR = "session_1"
    folder = os.path.join(DIR, SUBDIR)
    files = next(os.walk(folder))[2]
    asm = PASM([36, 31], 100)
    readIn(asm, files)
    asm.iterateAlignment()
    with open('outfile-ASM-100iters-500tr.txt', "w") as output:
        output.write(str(asm.meanShape))
        output.write("!!!\n")
        for shape in asm.allShapes:
            output.write(str(shape))
            output.write("@@@\n")
        output.write("!!!\n")