Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. def identificar_carros(imagem):
  2. cars_classifier = cv2.CascadeClassifier('classificadores/haarcascade_car.xml')
  3.  
  4. gray = cv2.cvtColor(imagem, cv2.COLOR_BGR2GRAY)
  5. cars = cars_classifier.detectMultiScale(gray, 1.2, 3)
  6.  
  7. for (x,y,w,h) in cars:
  8. roi = imagem[y:y+h, x:x+w]
  9. area = int(w) * int(h)
  10. cv2.rectangle(imagem, (x,y), (x+w,y+h), (127,0,255), 2)
  11. cv2.putText(imagem, "CARRO", (x,y-20), cv2.FONT_HERSHEY_PLAIN, 2, (0,0,255), 1)
  12.  
  13. return imagem
  14.  
  15. cam_capture = cv2.VideoCapture("videos/cars.avi")
  16.  
  17. while True:
  18. ret, image_frame = cam_capture.read()
  19.  
  20. if ret:
  21. image_frame = identificar_carros(image_frame)
  22. cv2.imshow("Faces", image_frame)
  23.  
  24. if cv2.waitKey(1) == 13:
  25. break
  26.  
  27. cam_capture.release()
  28. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement