How to Scan and Identify an Object
USE JUPYTER NOTEBOOK
pip install torch torchvision torchaudio
!git clone https://github.com/ultralytics/yolov5
!cd yolov5
pip install -r requirements.txt
import torch
from matplotlib import pyplot as plt
import numpy as np
import cv2
model = (torch.hub.load('ultralytics/yolov5','yolov5s'))
model
img = '//Users//Documents//NewTest//ScanProject//image1.png'
results = model(img)
results.print()
matplotlib inline
plt.imshow(np.squeeze(results.render()))
plt.show()
results.show()
# cap = cv2.VideoCapture(0)
#from machine library then use below:
cap = cv2.VideoCapture('/Users/Documents/NewTest/resources/DemoVideo.mov')
while cap.isOpened():
ret, frame = cap.read()
#make detection
results = model(frame)
cv2.imshow('YOLO',np.squeeze(results.render()))
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Comments
Post a Comment