Computer Vision with Python
OpenCV (Open Source Computer Vision Library) is used for image processing, video analysis, and real-time vision applications.
pip install opencv-python
import cv2
img = cv2.imread("image.jpg")
cv2.imshow("Image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
resized = cv2.resize(img, (300, 300))
cv2.rectangle(img, (50,50), (200,200), (255,0,0), 2)
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
cv2.imshow("Camera", frame)
if cv2.waitKey(1) == 27:
break
cap.release()
cv2.destroyAllWindows()
face = cv2.CascadeClassifier('haarcascade_frontalface.xml')
faces = face.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)