Question: Could somebody help me to fix my problem? The code ill provide is shoown below, and I need a help based on these cde how

Could somebody help me to fix my problem? The code ill provide is shoown below, and I need a help based on these cde how csn i implement the code here for the deepsort algorithm?
from flask import Flask, render_template, Response
from ultralytics import YOLO
import cv2
import math
app = Flask(__name__)
# model
model = YOLO("best.pt")
# start webcam
cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
# object classes
classNames =["person"]
def generate_frames():
# before your while loop
tick1= cv2.getTickCount()
frame_count =0
fps =0
while True:
success, img = cap.read()
img = cv2.resize(img,(640,480))
results = model.track(img, stream=True,persist=True,tracker="bytetrack.yaml")
# coordinates
for r in results:
boxes = r.boxes
for box in boxes:
# bounding box
x1, y1, x2, y2=[int(x) for x in box.xyxy[0]] # convert to int values once
# put box in cam
cv2.rectangle(img,(x1, y1),(x2, y2),(0,255,0),5)
# confidence
confidence = math.ceil((box.conf[0]*100))/100
print("Confidence --->",confidence)
# class name
cls = int(box.cls[0])
class_name = classNames[cls]
print(f"Class name -->{class_name}")
# concatenate class name and confidence
label = f"{classNames[cls]}: {confidence}"
# object details
org =[x1, y1]
font = cv2.FONT_HERSHEY_SIMPLEX
fontScale =1
color =(0,255,0)
thickness =2
frame_count +=1
if frame_count %10==0:
tick2= cv2.getTickCount()
time =(tick2- tick1)/ cv2.getTickFrequency()
fps = frame_count / time
tick1= tick2
frame_count =0
cv2.putText(img, f"FPS: {fps:.2f}",(10,50), cv2.FONT_HERSHEY_SIMPLEX, 1,(0,255,0),2)
cv2.putText(img, label, org, font, fontScale, color, thickness)
# encode OpenCV raw frame to jpg and displaying it
ret, jpeg = cv2.imencode('.jpg', img)
frame = jpeg.tobytes()
yield (b'--framer
'
b'Content-Type: image/jpegr
r
'+ frame + b'r
r
')
@app.route('/video')
def video():
return Response(generate_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
@app.route('/')
def index():
return render_template('trial.html')
if __name__=='__main__':
app.run(host='0.0.0.0', debug=True)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres how you can modify your existing code to incorporate deepsort using the deepsort library from ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!