29 lines
752 B
Python
29 lines
752 B
Python
import cv2
|
|
from importlib.resources import path
|
|
from time import time
|
|
import torch
|
|
from matplotlib import pyplot as plt
|
|
import numpy as np
|
|
|
|
|
|
|
|
model_name='last.pt'
|
|
model = torch.hub.load('C:/Users/Lenovo/Documents/Downloads/yolov5/yolov5', 'custom', source='local', path ='C:/Users/Lenovo/Documents/Downloads/yolov5/yolov5/runs/train/exp16/weights/best.pt')
|
|
cap= cv2.VideoCapture(0)
|
|
|
|
while cap.isOpened():
|
|
start= time()
|
|
ret, frame = cap.read()
|
|
result= model(frame)
|
|
cv2.imshow('My Face', np.squeeze(result.render()))
|
|
if cv2.waitKey(10) & 0xff == ord('x'):
|
|
break
|
|
if cv2.getWindowProperty('My Face', cv2.WND_PROP_VISIBLE) < 1:
|
|
break
|
|
|
|
end = time()
|
|
fps = 1/(end - start)
|
|
|
|
|
|
cap.release()
|
|
cv2.destroyAllWindows() |