Skip to content

Instantly share code, notes, and snippets.

View khalidmeister's full-sized avatar

Irfan Alghani Khalid khalidmeister

View GitHub Profile
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)
# 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)
# 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)
while cap.isOpened():
success, image = cap.read()
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)
import cv2
import mediapipe as mp
import numpy as np
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()
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():
if __name__ == '__main__':
app.run(host='0.0.0.0', port=2204, threaded=True)
@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')