Introduction

LDM (Landmark Detection Module) is a Python package designed for facial landmark detection, face feature extraction, and face recognition comparisons between images.

Overview

LDM offers several key functionalities including face_feature for extracting the feature vector of a face in an image, landmarks for detecting and returning the landmarks (such as eyes, nose) of a face in an image, face_rec for comparing the similarity of faces in two images, and has_same_person for determining if there is a same person in two images by returning an integer value. The current version is 3.x.

Getting Started

To get started with LDM, you can install it via pip:

pip install ldm

Here’s a quick example of how to use these functionalities effectively:

from ldm import LDM
import io  # Assuming io.imread() is from PIL or similar library for image reading

# Paths to sample images
imagepath1 = "closed_eye/9.jfif"
imagepath2 = "closed_eye/14.jfif"

# Read images
img1 = io.imread(imagepath1)
img2 = io.imread(imagepath2)

# Initialize LDM object
ldmer = LDM()

# Detect landmarks and face regions in the first image
ldl, facel, txt = ldmer.landmarks(img1)
print(txt)

for ld in ldl:
    print(10 * '-')
    print('nose:')
    print(ld['nose'])

for face in facel:
    print(10 * '-')
    print('face:')
    print(face.top())
    print(face.left())
    print(face.width())
    print(face.height())
    print(face.bottom())
    print(face.right())
    x, y, w, h = [face.top(), face.left(), face.width(), face.height()]
    print(x, y, w, h)

# Extract features from the first image
print("feature:")
ffl = ldmer.face_feature(img1, facel)
for ff in ffl:
    print('ff=' + str(ff))
    print('len(ff)=' + str(len(ff)))
    print('ff[0]=' + str(ff[0]))
    print('ff[127]=' + str(ff[127]))

# Compare faces between two images
print("face compare:")
print(ldmer.face_rec(img1, img2))
print(ldmer.has_same_person(img1, img2))
print(ldmer.has_same_person(img2, img2))

# Count number of faces in an image
print("face number:")
print(ldmer.face_number(img1, facel))

Core Concepts

LDM’s main functionalities include face_feature for extracting the feature vector, landmarks for detecting facial landmarks, face_rec for comparing face similarity, and has_same_person for determining if two faces are from the same person. The API overview includes methods such as compare2dir and compare2imglist, which compare faces across multiple images or directories and return comparison rates, scores, class IDs.

Practical Examples

Example 1: Face Feature Extraction

from ldm import LDM
import io  # Assuming io.imread() is from PIL or similar library for image reading

# Path to sample image
imagepath = "sample.jpg"

# Read image
img = io.imread(imagepath)

# Initialize LDM object
ldmer = LDM()

# Extract features from the image
ffl = ldmer.face_feature(img)
for ff in ffl:
    print('feature=' + str(ff))
    print('len(ff)=' + str(len(ff)))

Example 2: Face Comparison

from ldm import LDM
import io  # Assuming io.imread() is from PIL or similar library for image reading

# Paths to sample images
imagepath1 = "person1.jpg"
imagepath2 = "person2.jpg"

# Read images
img1 = io.imread(imagepath1)
img2 = io.imread(imagepath2)

# Initialize LDM object
ldmer = LDM()

# Compare faces between the two images
print("Face comparison:")
print(ldmer.face_rec(img1, img2))

Best Practices

  • Tips and Recommendations: Always ensure that you have the latest version of LDM installed to avoid compatibility issues.
  • Common Pitfalls: Avoid using deprecated functions such as compare2dir and compare2imglist. Instead, use the newer methods available in the current version.

Conclusion

In summary, LDM is a powerful tool for facial landmark detection and face recognition. By following this guide, you can effectively utilize its functionalities to perform various tasks related to face analysis. For further reading, please refer to the GitHub Repository, Python Package Index (PyPI), and Official Documentation.


Powered by Jekyll & Minimal Mistakes.

About this article. This article was generated by the Best-of-the-Best autonomous AI digest and reviewed by Ruslan Magana Vsevolodovna. Package metadata was last checked on 23 April 2026. See the data leaderboard and the GitHub repository for sources.