I created a program in python that centers your face in the frame. It only does this in an openCV window. Is there a way to use that output as a webcam? (For video calls) This is the code:
What is the best way to emulate a webcam in Windows 10?
Is there a library that can help. This is the code that centers your face:
import cv2
import os
cascPath = os.path.dirname(
cv2.__file__) + "/data/haarcascade_frontalface_alt2.xml"
faceCascade = cv2.CascadeClassifier(cascPath)
video_capture = cv2.VideoCapture(0)
frameWidth = 640
frameHeight = 480
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
frameHeight = frame.shape[0]
frameWidth = frame.shape[1]
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(60, 60),
flags=cv2.CASCADE_SCALE_IMAGE)
distanceX = frameWidth / 2
distanceY = frameHeight / 2
for (x,y,w,h) in faces:
#cv2.rectangle(frame, (x, y), (x + w, y + h),(0,255,0), 2)
distanceX = x + (w / 2)
distanceY = y + (h / 2)
# Display the resulting frame
frontX = 0
frontY = 0
if (distanceX > frameWidth / 2):
frontX = frameWidth - (2 * (frameWidth - distanceX))
distanceX = int(frameWidth / 2)
if (distanceY > frameHeight / 2):
frontY = frameHeight - (2 * (frameHeight - distanceY))
distanceY = int(frameHeight / 2)
frameCut = frame[int(frontY): int(distanceY * 2), int(frontX): int(distanceX * 2)].copy()
#cv2.imshow('frame', frame)
#blur = cv2.medianBlur(frame, 51)
allBlack = frame
allBlack[0:frameHeight, 0:frameWidth] = [0, 0, 0].copy()
#frameResized = cv2.resize(frameCut, (frameHeight, frameWidth))
cutHeight = int((distanceY * 2) - frontY)
cutWidth = int((distanceX * 2) - frontX)
x1 = int((frameWidth - cutWidth) / 2)
x2 = int(((frameWidth - cutWidth) / 2) + cutWidth)
y1 = int((frameHeight - cutHeight) / 2)
y2 = int(((frameHeight - cutHeight) / 2) + cutHeight)
allBlack[y1:y2, x1:x2] = frameCut
#blur[y1:y2, x1:x2] = frameCut
#cv2.imshow('cut', frameCut)
#cv2.imshow('resized', frameResized)
cv2.imshow('Output', allBlack)
#cv2.imshow('blur', blur)
# press ESC to quit
c = cv2.waitKey(1)
if c == 27:
break
video_capture.release()
cv2.destroyAllWindows()