This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img_h, img_w, img_c = image.shape | |
face_3d = [] | |
face_2d = [] | |
if results.multi_face_landmarks: | |
for face_landmarks in results.multi_face_landmarks: | |
for idx, lm in enumerate(face_landmarks.landmark): | |
if idx == 33 or idx == 263 or idx == 1 or idx == 61 or idx == 291 or idx == 199: | |
if idx == 1: | |
nose_2d = (lm.x * img_w, lm.y * img_h) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Flip the image horizontally for a later selfie-view display | |
# Also convert the color space from BGR to RGB | |
image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB) | |
# To improve performance | |
image.flags.writeable = False | |
# Get the results | |
results = face_mesh.process(image) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Flip the image horizontally for a later selfie-view display | |
# Also convert the color space from BGR to RGB | |
image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB) | |
# To improve performance | |
image.flags.writeable = False | |
# Get the results | |
results = face_mesh.process(image) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while cap.isOpened(): | |
success, image = cap.read() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mp_face_mesh = mp.solutions.face_mesh | |
face_mesh = mp_face_mesh.FaceMesh(min_detection_confidence=0.5, min_tracking_confidence=0.5) | |
cap = cv2.VideoCapture(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import mediapipe as mp | |
import numpy as np |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import mediapipe as mp | |
import numpy as np | |
mp_face_mesh = mp.solutions.face_mesh | |
face_mesh = mp_face_mesh.FaceMesh(min_detection_confidence=0.5, min_tracking_confidence=0.5) | |
cap = cv2.VideoCapture(0) | |
while cap.isOpened(): | |
success, image = cap.read() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, Response | |
import cv2 | |
app = Flask(__name__) | |
video = cv2.VideoCapture(0) | |
face_cascade = cv2.CascadeClassifier() | |
face_cascade.load(cv2.samples.findFile("static/haarcascade_frontalface_alt.xml")) | |
@app.route('/') | |
def index(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=2204, threaded=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/video_feed') | |
def video_feed(): | |
# Set to global because we refer the video variable on global scope, | |
# Or in other words outside the function | |
global video | |
# Return the result on the web | |
return Response(gen(video), | |
mimetype='multipart/x-mixed-replace; boundary=frame') |