Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2 as cv
- from ultralytics import YOLO
- cap = cv.VideoCapture("/mnt/c/Users/Bemposta/Videos/madrid.mp4")
- if not cap.isOpened():
- print("Cannot open camera")
- exit()
- model = YOLO("yolo26s.pt") # pretrained YOLO26n model
- while True:
- # Capture frame-by-frame
- ret, frame = cap.read()
- # if frame is read correctly ret is True
- if not ret:
- print("Can't receive frame (stream end?). Exiting ...")
- break
- # Our operations on the frame come here
- #imgrgb = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
- # Run batched inference on a list of images
- results = model.predict(source=frame, iou=0.5, verbose=False, imgsz=[736, 1280]) # return a list of Results objects
- #print(model.names)
- #model.info() # Prints model summary and returns tuple
- #model.info(detailed=True) # Prints detailed info and returns tuple
- img_result = results[0].plot(
- line_width=1, # Grosor de las cajas
- font_size=10, # TamaƱo del texto
- labels=True, # Mostrar etiquetas
- conf=True, # Mostrar confianza
- boxes=True, # Dibujar cajas
- )
- print("results[0].to_json():\n", results[0].to_json(normalize=True, decimals=5))
- # Display the resulting frame
- #img_result = cv.cvtColor(img_result, cv.COLOR_RGB2BGR)
- cv.imshow('frame', img_result)
- if cv.waitKey(10) == ord('q'):
- break
- # When everything done, release the capture
- cap.release()
- cv.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment