Skip to content

Instantly share code, notes, and snippets.

@tejastank
Created December 28, 2023 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tejastank/583e6a92628d8ca57951015a6ebe792c to your computer and use it in GitHub Desktop.
Save tejastank/583e6a92628d8ca57951015a6ebe792c to your computer and use it in GitHub Desktop.
tongue detection, recognisation
import cv2
import dlib
# Load the pre-trained facial landmark predictor from dlib
predictor_path = "shape_predictor_68_face_landmarks.dat"
predictor = dlib.shape_predictor(predictor_path)
# Load the pre-trained face detector from dlib
face_detector = dlib.get_frontal_face_detector()
# Function to extract facial landmarks, including the tongue region
def get_facial_landmarks(image):
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_detector(gray)
if len(faces) == 0:
return None
face = faces[0]
landmarks = predictor(gray, face)
# Extract landmarks for the mouth region (including the tongue)
landmarks_list = []
for i in range(48, 68):
landmarks_list.append((landmarks.part(i).x, landmarks.part(i).y))
return landmarks_list
# Example usage
if __name__ == "__main__":
# Read the input image
image_path = "path/to/your/image.jpg"
image = cv2.imread(image_path)
# Get facial landmarks (including tongue region)
facial_landmarks = get_facial_landmarks(image)
if facial_landmarks:
# Draw facial landmarks on the image
for (x, y) in facial_landmarks:
cv2.circle(image, (x, y), 1, (0, 0, 255), -1)
# Display the image with facial landmarks
cv2.imshow("Tongue Recognition", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
print("No face detected in the image.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment