Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views2 pages

cvopen (1)

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Chris Lobo

2023209

Mech b1

Open CV

In [1]: !pip install opencv-python

Collecting opencv-python
Using cached opencv_python-4.10.0.84-cp37-abi3-win_amd64.whl.metadata (2
0 kB)
Requirement already satisfied: numpy>=1.21.2 in c:\users\harsh\appdata\loc
al\programs\python\python312\lib\site-packages (from opencv-python) (2.1.
2)
Using cached opencv_python-4.10.0.84-cp37-abi3-win_amd64.whl (38.8 MB)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.10.0.84
[notice] A new release of pip is available: 24.0 -> 24.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip

In [2]: import cv2


import matplotlib.pyplot as plt

#task 1
face = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontal

In [6]: # Importing libraries

# Importing libraries
import cv2
import matplotlib.pyplot as plt

# Importing pre-trained haarcascades classifier


face = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontal

# Reading the images in GRAY scale


image_path = r'C:\Users\HARSH\Downloads\hk.png'
image = cv2.imread(image_path)

# Check if the image was loaded successfully


if image is None:
print("Error: Could not load image. Please check the file path:", ima
else:
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detecting faces
f = face.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minS

# Creating a rectangle around the face


for (x,y,w,h) in f:
cv2.rectangle(image, (x,y), (x+w, y+h), (255,0,0), 2)

# Changing color scheme to RGB


rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

plt.figure(figsize=(4,4))
plt.imshow(rgb)
plt.title('Detected Face')
plt.axis('off')
plt.show()

In [ ]:

You might also like