Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

NAMA : I Made Dwipayana

NPM : 2111010041

Mata Kuliah : Multimedia Content Analysis

SORCCODE :

import cv2

# Load the pre-trained face detector

face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')

# Initialize the USB webcam (change index accordingly)

cap = cv2.VideoCapture(1, cv2.CAP_DSHOW)

# Position for displaying the name

name_position = (int(cap.get(3) / 2) - 100, int(cap.get(4)) - 20)

while True:

# Read frame from the webcam

ret, frame = cap.read()

# Convert frame to grayscale

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Detect faces in the frame

faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)

# Draw rectangles around faces

for (x, y, w, h) in faces:

cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)

# Display the name "I MADE DWIPAYANA" with adjusted font size
font_scale = 1.0 # Adjust the font size here

cv2.putText(frame, "I MADE DWIPAYANA", name_position, cv2.FONT_HERSHEY_SIMPLEX,


font_scale, (255, 0, 0), 2, cv2.LINE_AA)

# Display the resulting frame

cv2.imshow('Face Recognition', frame)

# Exit the loop when 'q' key is pressed or window is closed

key = cv2.waitKey(1)

if key == ord('q') or key == 27: # 'q' key or ESC key

break

# Release the webcam

cap.release()

# Close the window

cv2.destroyAllWindows()

cv2.waitKey(1) # Needed to close the window properly

HASIL:

You might also like