Esempio n. 1
0
    rightEyeIx = 28

    ## Scale
    d1 = s1.shapePoints[leftEyeIx].dist(s1.shapePoints[rightEyeIx])
    s = float(1) / float(d1)

    ## Rotation
    leftEyeIx = 33
    rightEyeIx = 28

    xDiff = s1.shapePoints[rightEyeIx].x - s1.shapePoints[leftEyeIx].x
    yDiff = s1.shapePoints[rightEyeIx].y - s1.shapePoints[leftEyeIx].y

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

    #thetaRot = math.atan2( yDiff, xDiff )

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

    ## What order to calculate and apply the transformations?

    for pt in s1.shapePoints:
        pt.rotate(rot)
    s1.update()

    plotAll(ax3, s1)
         ls='-')

t = [[cmShape.x - cmMeanShape.x], [cmShape.y - cmMeanShape.y]]

## Scale
d1 = s1.shapePoints[0].dist(s1.shapePoints[1])
d2 = s2.shapePoints[0].dist(s2.shapePoints[1])
s = d1 / d2

## Rotation
#http://stackoverflow.com/questions/2827393/angles-between-two-n-dimensional-vectors-in-python
p0 = [s1.shapePoints[0].x, s1.shapePoints[0].y]
m0 = [s2.shapePoints[0].x, s2.shapePoints[0].y]
axisVector = [1, 0]

thetaP = ASM.angleV(p0, axisVector)
thetaM = ASM.angleV(m0, axisVector)

thetaRot = thetaP - thetaM

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

d = {'rot': np.multiply(s, rot), 't': t}
s2.applyTrans(d)
s2.draw(sns.xkcd_palette(["light blue"]), ax4)

cmMeanShape1 = ASM.centroid(s2)
ax4.scatter(cmMeanShape1.x, cmMeanShape1.y, c='r')
ax4.plot([s2.shapePoints[0].x, s2.shapePoints[1].x],
         [s2.shapePoints[0].y, s2.shapePoints[1].y],

t = [[ cmShape.x - cmMeanShape.x ], [cmShape.y - cmMeanShape.y ]] 
        
## Scale
d1 = s1.shapePoints[0].dist( s1.shapePoints[1] )
d2 = s2.shapePoints[0].dist( s2.shapePoints[1] )
s = d1/d2
        
## Rotation
#http://stackoverflow.com/questions/2827393/angles-between-two-n-dimensional-vectors-in-python
p0 = [ s1.shapePoints[0].x, s1.shapePoints[0].y ]
m0 = [ s2.shapePoints[0].x, s2.shapePoints[0].y ]
axisVector = [ 1, 0 ]
        
thetaP = ASM.angleV( p0, axisVector )
thetaM = ASM.angleV( m0, axisVector )

thetaRot = thetaP - thetaM

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

d= { 'rot' : np.multiply( s , rot) , 't': t}
s2.applyTrans( d )
s2.draw( sns.xkcd_palette( ["light blue"] ), ax4)

cmMeanShape1 = ASM.centroid( s2 )
ax4.scatter( cmMeanShape1.x, cmMeanShape1.y, c='r')
ax4.plot( [s2.shapePoints[0].x, s2.shapePoints[1].x],
         [s2.shapePoints[0].y, s2.shapePoints[1].y],
    rightEyeIx = 28
    
    ## Scale
    d1 = s1.shapePoints[leftEyeIx].dist( s1.shapePoints[rightEyeIx] )
    s = float(1)/float(d1)
        
    ## Rotation
    leftEyeIx = 33
    rightEyeIx = 28

    xDiff = s1.shapePoints[rightEyeIx].x - s1.shapePoints[leftEyeIx].x
    yDiff = s1.shapePoints[rightEyeIx].y - s1.shapePoints[leftEyeIx].y
    
    p0 = [ xDiff, yDiff ] #s1.shapePoints[0].x, s1.shapePoints[0].y ]
    axisVector = [ 1, 0]
    thetaP = ASM.angleV( p0, axisVector )
    thetaRot = thetaP
    
    #thetaRot = math.atan2( yDiff, xDiff )

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






    ## What order to calculate and apply the transformations?