0

When i apply translation on the landmark, it make the points move to top left, Moreover, when applied with scale it make it compact

I know what the translation do but moving to top left feels like an issue to me,... Or is this suppose to be happen???????

Thanks in advance Tried my best to give u a good description of the problem

i came across the norm_trans like function in mediapipe but i wanna know how to fix this manually

Reading this paper -> Paper with the original paper of AAM

Code Below

# i used mediapipe line to get rid to manual work.. as mediapipe give 0 1 values so multiply it with h and w, still in abyss
# Generated using mediapipe, jsut to make my life easy
mp_face = mp.solutions.face_mesh
mp_draw = mp.solutions.drawing_utils
faces = "./Faces/"
scale = 50
landmarks = []
images = []
for f in os.listdir(faces):
    url = os.path.join(faces, f)
img = cv2.imread(url) 
# width = int(img.shape[1] * scale / 100)
# height = int(img.shape[0] * scale / 100)
# img = cv2.resize(img, (width, height))

with mp_face.FaceMesh(static_image_mode=False, max_num_faces=1) as face_mesh:
    result = face_mesh.process(img)

    if result.multi_face_landmarks:
        for face_landmark in result.multi_face_landmarks:
            temp = []
            w, h = img.shape[:2]
            for lm in face_landmark.landmark:
                temp.append(np.array([lm.x*w, lm.y*h]))
            landmarks.append(np.array(temp))
            images.append(img)


def plot_image_with_connections(image, landmark, title="Worked"): img = image.copy() # will ignore depth for now h, w, *_ = img.shape

for x, y, *_ in landmark:
    px, py = int(x), int(y)
    cv2.circle(img, (px, py), 2, (0, 255, 0), -1)

for start_idx, end_idx in FACEMESH_CONTOURS:
    x1, y1, *_ = landmark[start_idx]
    x2, y2, *_ = landmark[end_idx]
    pt1 = (int(x1), int(y1))
    pt2 = (int(x2), int(y2))
    cv2.line(img, pt1, pt2, (0, 255, 255), 1)

cv2.imshow(title, img)
cv2.waitKey(0)
cv2.destroyAllWindows()

def norma_translation(landmark): mean_ = np.mean(landmark, axis=0) return (landmark - mean_)

def norma_scale(landmark): return landmark / np.linalg.norm(landmark)

Some landmarks values are

array([[501.70430183, 478.92040062],
       [511.1965704 , 428.5222683 ],
       [505.83550215, 438.19850159],
       [496.23317719, 373.75407982],
       [513.77804279, 414.65303421],
       [515.71601152, 392.78467941],
       [519.54906702, 334.05176258],
       [351.50528193, 307.64656162],
       [524.13897276, 297.93477249],
       [527.26793051, 279.01498604],
       [536.26069546, 194.91702461],
       [500.77702045, 486.53829956],
       [499.44455385, 491.36608505],
       [498.52928162, 492.49628258],
       [499.03871059, 491.49466515],
       [498.20903778, 498.29940796],
       [497.01042652, 506.55924225],
       [495.49946785, 513.99468994],
       [492.50304937, 522.82666397],
       [509.52368021, 434.01287079],
       [485.08573055, 429.60614014],
       [269.47482347, 232.43104553],
       [422.25877047, 324.5672369 ],
       [398.47658038, 325.26359177],
       [374.57786322, 324.18494034],
       [342.54925728, 311.67106152],
       [441.15647435, 321.88286972],
       [386.56679988, 288.38385105],
       [412.89010286, 290.40463352],
       [362.8580904 , 288.72311211],
       [347.08542347, 291.75634766],
       [322.74689198, 321.09274483],
       [403.41129661, 535.11775398],
       [341.34335279, 302.17602921],
       [252.56688118, 298.21202469],
       [295.20531893, 307.16711712],
       [394.77847695, 395.77553749],
       [474.07186508, 475.0695343 ],
       [476.5517807 , 490.08515358],
       [444.70662951, 477.2760582 ],
       [426.77662134, 480.65449905],
       [455.81176996, 488.9645195 ],
       [439.71984625, 488.30179024],
       [391.29585266, 494.322155  ],
       [491.63466215, 427.00321579],
       [490.38126945, 413.59622955],
       [313.74387264, 276.76551437],
       [444.06071305, 357.21006393],
       [433.71181965, 413.71994019],
       [432.83268452, 404.04686546],
       [328.44646454, 386.8646431 ],
       [493.47365141, 392.87474251],
       [371.74759865, 271.53860855],
       [337.71417856, 271.30651951],
       [295.47642946, 212.63545799],
       [475.08321047, 292.3957386 ],
       [435.4440701 , 295.55656719],
       [376.5286088 , 481.34065437],
       [260.40462971, 431.4049015 ],
       [449.54954982, 422.45031357],
       [467.76492596, 428.74051666],
       [404.00953293, 485.90351486],
       [414.87322927, 485.67706299],
       [325.97839355, 259.44196796],
       [431.91979766, 418.86441612],
       [417.22595215, 277.78152084],
       [414.14568901, 265.58628464],
       [396.48374796, 193.16182518],
       [311.64194345, 236.1205616 ],
       [408.30452919, 229.22937489],
       [300.11311054, 266.91439724],
       [285.11171579, 250.7815876 ],
       [474.83474731, 484.42780495],
       [451.13286495, 484.93563271],
       [433.53615165, 485.11979485],
       [455.03783822, 425.45358658],
       [409.95244145, 486.28868484],
       [418.82665038, 489.04852867],
       [416.62143707, 484.30111122],
       [464.18850422, 420.94657135],
       [443.91364217, 486.86968613],
       [459.90932822, 488.97873306],
       [478.68995667, 490.98376656],
       [462.69141912, 521.09085464],
       [467.11259365, 511.74934196],
       [470.54413795, 503.8891983 ],
       [473.88756037, 495.85037613],
       [476.70543194, 490.19539642],
       [439.88885164, 487.12947845],
       [436.29597902, 489.27629662],
       [430.17252207, 493.12812805],
       [424.14735913, 497.12503433],
       [408.2455802 , 458.83299637],
       [244.79575872, 353.23616695],
       [507.72653103, 434.94894791],
       [429.32988048, 486.04556274],
       [424.88287807, 487.39067459],
       [475.27453423, 436.34231567],
       [438.62610936, 427.89792442],
       [471.48688316, 432.70092392],
       [421.18403435, 364.00188732],
       [383.66025805, 373.07845306],
       [428.6958909 , 409.28412437],
       [335.74950457, 199.14718246],
       [350.85259318, 227.95432186],
       [364.76422668, 258.33956146],
       [410.42471886, 504.09626007],
       [469.95925426, 273.86906242],
       [466.46399021, 232.81834316],
       [461.06782675, 192.14178276],
       [354.03219223, 319.45360088],
       [296.15264297, 330.2221508 ],
       [452.68607497, 319.26788139],
       [322.29298472, 293.19689655],
       [460.87540627, 349.75204563],
       [449.64877605, 411.5807991 ],
       [269.64201927, 336.11294842],
       [312.95746565, 344.89282799],
       [343.91276121, 354.68465614],
       [389.67785358, 354.10205364],
       [422.07419157, 348.45591354],
       [444.8030591 , 343.15559292],
       [496.02298975, 335.95486641],
       [272.27498293, 369.71694565],
       [302.73181677, 289.42725372],
       [497.25028038, 433.0213871 ],
       [443.84485006, 375.29664612],
       [246.21478438, 287.343256  ],
       [463.05591583, 337.79293442],
       [426.75762057, 407.72721291],
       [334.33900595, 301.90211105],
       [449.35356498, 399.86891174],
       [247.81205535, 390.64461708],
       [450.81676126, 313.67949486],
       [471.06946945, 395.04209137],
       [307.84639597, 487.06806183],
       [305.18138051, 496.6034317 ],
       [246.97892785, 362.13004017],
       [282.71515131, 460.85579681],
       [268.28443766, 271.35440254],
       [394.71527815, 547.72917557],
       [498.17098141, 433.95601654],
       [423.05093527, 384.62859535],
       [274.9356389 , 306.37280273],
       [377.94428945, 315.13546371],
       [399.71884131, 316.98476219],
       [411.94110632, 490.79118156],
       [274.75764036, 399.31195068],
       [433.29520106, 569.43644333],
       [365.15211105, 540.79357147],
       [336.67492151, 522.55046463],
       [531.96498632, 236.34161758],
       [482.9247427 , 574.50550842],
       [419.30934668, 316.15111923],
       [437.27864504, 314.14654636],
       [447.26581097, 313.76517105],
       [286.09849453, 282.66835403],
       [430.77026486, 302.41840553],
       [409.65476274, 297.44126797],
       [388.13884616, 295.9881506 ],
       [366.97015285, 297.17033291],
       [354.13786173, 299.68637466],
       [254.19425726, 255.91356087],
       [362.75713682, 311.70341492],
       [504.45313454, 450.4934082 ],
       [427.39997268, 451.48664665],
       [449.77906704, 420.86909866],
       [472.19948053, 450.97223854],
       [521.42057419, 313.43354321],
       [334.72137928, 510.84085846],
       [363.27119946, 529.27953339],
       [434.61069584, 562.222929  ],
       [280.67781925, 467.4256649 ],
       [444.46315646, 309.47918987],
       [477.20937729, 360.90905571],
       [485.30469179, 567.3187542 ],
       [396.22917056, 557.32833099],
       [251.49444818, 395.54013634],
       [456.83509707, 488.56474113],
       [452.82925248, 492.62867928],
       [447.67867327, 498.53230858],
       [442.94970274, 505.52077484],
       [433.39390635, 513.50945473],
       [425.53567648, 486.98567581],
       [418.85184765, 485.65604973],
       [412.07383752, 482.78723526],
       [390.33358574, 469.58147621],
       [307.55230904, 415.13598824],
       [478.73333216, 342.138731  ],
       [470.5008173 , 308.39575672],
       [455.17158389, 306.90997887],
       [430.37464857, 485.00191879],
       [298.12041521, 447.02578163],
       [490.50476074, 312.82560635],
       [418.05419922, 523.25763321],
       [516.95333719, 372.75347137],
       [495.36067724, 355.72851944],
       [518.07786465, 354.04930115],
       [457.56740808, 384.14958954],
       [487.71326542, 553.59139252],
       [490.04358768, 536.5892086 ],
       [453.17480326, 533.65380096],
       [366.4409554 , 495.16838837],
       [406.70775175, 418.72824669],
       [388.66617918, 510.56373787],
       [358.49822283, 411.72661972],
       [386.31798029, 433.63366699],
       [336.14514828, 433.3116684 ],
       [441.7604959 , 549.23467255],
       [442.26838946, 389.54784775],
       [344.25027847, 500.27623367],
       [372.96378493, 518.43050575],
       [351.79059505, 476.91650772],
       [278.05631638, 424.19594955],
       [322.69035578, 470.98317909],
       [261.13356829, 427.63510513],
       [367.45389104, 452.97253418],
       [460.41352034, 367.70171261],
       [456.89286709, 418.75904274],
       [440.29431105, 419.44282913],
       [468.83620739, 411.98812294],
       [453.94492388, 296.71236229],
       [415.55648923, 287.21504879],
       [381.64919257, 283.31075001],
       [353.20602894, 282.46679783],
       [333.40306044, 285.33425236],
       [317.58975983, 304.93411827],
       [246.30556583, 329.69028282],
       [336.11433029, 329.87067223],
       [360.80880404, 337.16209793],
       [393.04814577, 338.19924927],
       [422.66543627, 335.25824833],
       [444.17260647, 331.63192558],
       [459.25622821, 328.85288906],
       [245.63979864, 319.35421562],
       [440.30667663, 422.32993698],
       [476.16299152, 377.71834755],
       [474.32932138, 422.66022682],
       [485.17505884, 428.76249504],
       [473.46087933, 423.37559891],
       [446.03608012, 426.75518036],
       [489.81897831, 431.16449928],
       [490.34759998, 432.39866638],
       [459.38429832, 316.05853367],
       [471.82001352, 322.69528008],
       [478.17915678, 328.32488155],
       [346.73041344, 301.38572884],
       [335.78756094, 295.03862762],
       [536.26491785, 375.07721329],
       [679.23920393, 318.3360157 ],
       [531.04943991, 430.7668705 ],
       [761.61792755, 250.2878418 ],
       [606.77679777, 330.53162479],
       [629.13420439, 332.64249229],
       [652.06086636, 333.29280663],
       [685.04576206, 322.72658062],
       [590.13837576, 326.6987009 ],
       [651.85725927, 297.58713245],
       [626.44486904, 298.22966003],
       [673.93659115, 299.30445099],
       [687.28379488, 303.15501022],
       [699.35945511, 333.28442764],
       [571.44474506, 539.28526688],
       [689.56865788, 313.3849802 ],
       [759.75821018, 315.35774803],
       [725.94583511, 321.26651001],
       [617.83820629, 402.80252075],
       [529.25190687, 476.33945465],
       [521.51834726, 491.13015747],
       [555.81108809, 479.76764297],
       [570.60953379, 483.97525215],
       [540.75014114, 490.88707924],
       [555.41648626, 491.01403618],
       [596.21461868, 499.54827118],
       [530.45073748, 427.99044418],
       [536.27084017, 415.05044365],
       [722.49614   , 290.60926056],
       [579.82646942, 361.68591022],
       [582.26937056, 418.18628883],
       [583.99918079, 408.58858109],
       [679.27248955, 397.7292881 ],
       [536.8639493 , 394.27122498],
       [674.96871948, 282.48256874],
       [704.50956821, 284.20798111],
       [747.65836716, 229.49454117],
       [573.47105503, 296.33684349],
       [603.49534035, 301.92369461],
       [614.37781811, 487.29771614],
       [712.5573945 , 444.23869514],
       [564.52928782, 425.73298836],
       [545.80933571, 431.0622406 ],
       [588.56989384, 490.5437603 ],
       [578.33064556, 489.81900024],
       [717.41369486, 273.07674408],
       [581.23543262, 423.30409241],
       [632.40063667, 285.76480484],
       [639.17028427, 273.81069469],
       [668.5997057 , 203.60210323],
       [732.2589159 , 251.20077801],
       [651.73557758, 238.29194641],
       [735.74409008, 281.72409534],
       [748.67760897, 267.04409599],
       [525.85628033, 485.53852463],
       [547.49407053, 487.11627388],
       [563.13759804, 488.11661911],
       [558.45052242, 428.4465065 ],
       [583.0555582 , 490.57806587],
       [574.07578945, 493.01753426],
       [576.41247272, 488.26494026],
       [553.93963575, 423.10115433],
       [550.23144245, 489.42435455],
       [535.20169735, 490.87685776],
       [517.31487274, 491.96555519],
       [521.2038064 , 522.5070343 ],
       [523.0535984 , 513.1407795 ],
       [522.85476208, 505.17973709],
       [521.63021326, 497.14025688],
       [520.27817011, 491.40819931],
       [554.40738916, 490.13446236],
       [557.54265308, 492.48601723],
       [562.59170294, 496.62856865],
       [567.01825142, 500.87706375],
       [593.28734875, 463.87315178],
       [744.61851835, 369.27553558],
       [564.23141718, 489.5644722 ],
       [568.70797634, 491.12103271],
       [536.50614262, 438.15502739],
       [572.08391666, 432.01147842],
       [541.11436367, 434.84291649],
       [599.15143013, 369.83495331],
       [632.38045692, 381.10021019],
       [585.58000088, 413.96819496],
       [719.10259724, 213.68247986],
       [702.10587502, 240.71952629],
       [684.87878561, 269.75634193],
       [575.44971228, 508.24442673],
       [584.72548723, 278.44440365],
       [596.66306973, 237.90486813],
       [609.56494808, 198.00114822],
       [672.48918772, 329.9572916 ],
       [719.85204458, 343.93889618],
       [580.71876526, 323.5536871 ],
       [708.23925734, 305.94104385],
       [566.86547756, 353.38819504],
       [570.36255121, 415.05921745],
       [740.28343678, 351.29700279],
       [702.64239311, 357.3610611 ],
       [672.62282372, 365.27062321],
       [630.23964882, 362.03102779],
       [601.13770962, 354.35267735],
       [581.42066956, 347.68800831],
       [540.94683886, 337.50131512],
       [730.13159752, 383.97073555],
       [726.19665623, 303.51521873],
       [521.32499456, 433.58176994],
       [576.86525583, 379.66437721],
       [761.1755085 , 305.22731686],
       [566.7095232 , 341.24446106],
       [585.6905508 , 412.56798363],
       [695.04669189, 313.57480145],
       [571.95905447, 403.58444214],
       [733.40866804, 405.20018196],
       [583.89822721, 318.09521866],
       [555.38851976, 397.65681648],
       [664.89310265, 496.13903427],
       [660.89208364, 505.69730377],
       [748.56130123, 377.9519062 ],
       [692.03426123, 471.81818199],
       [755.37470818, 288.10616016],
       [575.34097195, 552.05439758],
       [517.51217365, 434.49560547],
       [593.30199003, 390.16815567],
       [742.49871254, 321.75167942],
       [652.71281481, 324.09801388],
       [631.24353647, 324.43369961],
       [579.84878778, 495.11583328],
       [719.42942142, 412.71963882],
       [532.29098797, 571.72868729],
       [600.20461559, 546.5547142 ],
       [628.25040817, 529.79297638],
       [612.33823776, 322.40642452],
       [596.0675478 , 319.36660862],
       [586.94602728, 318.44266129],
       [741.0766983 , 297.89937019],
       [604.93791819, 308.6856432 ],
       [625.6183219 , 305.16057014],
       [647.12658882, 304.83468914],
       [667.70115852, 307.06459522],
       [679.27945375, 310.29938698],
       [765.66725731, 274.06410408],
       [667.9904747 , 321.77819824],
       [577.93105364, 455.66490746],
       [565.70393562, 424.10917664],
       [536.19456291, 452.65176392],
       [636.01824045, 518.10140038],
       [607.15867758, 535.20711517],
       [535.25126934, 564.6967907 ],
       [687.19896317, 478.40682602],
       [590.75298071, 314.52906227],
       [552.9519248 , 363.43268681],
       [569.29516315, 561.48184967],
       [735.9221983 , 410.04411125],
       [538.83635521, 490.74902344],
       [541.91837311, 494.98304176],
       [545.07365227, 501.07789612],
       [547.3219943 , 508.19073105],
       [551.01099491, 516.47833443],
       [568.36503029, 490.4425106 ],
       [575.54079533, 489.48524475],
       [582.48027086, 487.04990005],
       [606.20688438, 475.18306732],
       [688.91248703, 426.44638634],
       [553.85902643, 344.75023174],
       [567.75930882, 311.95197678],
       [581.77820206, 311.46237659],
       [563.41265678, 488.25410461],
       [685.69047213, 457.71227455],
       [549.95912552, 315.13592434],
       [561.27842903, 526.83155441],
       [538.9767909 , 357.26176357],
       [565.26052952, 387.556633  ],
       [526.16166353, 535.49498367],
       [616.96652889, 501.38361931],
       [602.13638783, 424.67346382],
       [591.58254385, 515.64868355],
       [647.3244381 , 420.53398323],
       [617.63267994, 440.52807808],
       [660.64230442, 442.79378128],
       [532.7534771 , 551.36745262],
       [576.40792131, 393.71891403],
       [633.1311655 , 507.3747673 ],
       [602.88545132, 523.97883987],
       [635.9251833 , 484.21587372],
       [708.57129097, 436.70528793],
       [660.30725479, 479.65292549],
       [718.84464741, 440.71092415],
       [629.59543228, 460.30607414],
       [564.97148752, 371.09737206],
       [561.89950466, 421.49585533],
       [575.1006794 , 423.29720497],
       [555.01832008, 414.44531441],
       [588.33305597, 301.72961807],
       [627.45210171, 294.74466133],
       [660.5437088 , 292.94690895],
       [686.55321121, 294.02202892],
       [702.54259109, 297.97493458],
       [707.90420771, 317.69434357],
       [757.26008892, 346.37553501],
       [685.48757792, 341.21173477],
       [661.03657722, 347.02365589],
       [630.5177784 , 345.91282654],
       [603.23020697, 341.11410427],
       [584.48771715, 336.33128452],
       [571.636343  , 332.62898064],
       [752.20089436, 336.33626366],
       [573.22599173, 426.26937485],
       [552.27233887, 380.27889442],
       [546.87875271, 424.49899673],
       [532.68964767, 429.93717575],
       [545.57880402, 425.04152489],
       [566.00169659, 430.4181118 ],
       [528.53618383, 432.09895325],
       [525.32617807, 433.28372383],
       [575.53174734, 320.02062988],
       [562.14072943, 325.80616379],
       [555.75416803, 331.02806854],
       [685.31281471, 312.33635712],
       [696.19227648, 307.02287579]])

Image Below

Without Anything Without Anything

With translation With translation

With Scaling With Scaling

With translation and scaling With translation and scaling

0 Answers0