Created
June 7, 2019 00:25
-
-
Save michelpf/1d1c471e107e3b6c8e096ccd836e0ffb to your computer and use it in GitHub Desktop.
Identificar carros utilizando Haar Cascade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def identificar_carros(imagem): | |
cars_classifier = cv2.CascadeClassifier('classificadores/haarcascade_car.xml') | |
gray = cv2.cvtColor(imagem, cv2.COLOR_BGR2GRAY) | |
cars = cars_classifier.detectMultiScale(gray, 1.2, 3) | |
for (x,y,w,h) in cars: | |
roi = imagem[y:y+h, x:x+w] | |
area = int(w) * int(h) | |
cv2.rectangle(imagem, (x,y), (x+w,y+h), (127,0,255), 2) | |
cv2.putText(imagem, "CARRO", (x,y-20), cv2.FONT_HERSHEY_PLAIN, 2, (0,0,255), 1) | |
return imagem | |
cam_capture = cv2.VideoCapture("videos/cars.avi") | |
while True: | |
ret, image_frame = cam_capture.read() | |
if ret: | |
image_frame = identificar_carros(image_frame) | |
cv2.imshow("Faces", image_frame) | |
if cv2.waitKey(1) == 13: | |
break | |
cam_capture.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Valeu @michelpf
Vou estudar o YoloV8 também, mas pretendo fazer algo bem simples, que não necessite de uma IA para detectar objetos.