i have yielded 2 functions
times = []
total = 0
is_round = False
average = str(datetime.timedelta(seconds=0))[2:7]
while True:
success, img = video.read()
image = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(image, lower, upper)
blur = cv2.GaussianBlur(mask, (15, 15), 0)
circles = cv2.HoughCircles(blur, cv2.HOUGH_GRADIENT, 1, 14,
param1=34, param2=10, minRadius=4, maxRadius=10)
circles = np.uint16(np.around(circles))
if (len(circles[0, :]) == 7) and not is_round:
start_time = time.time()
is_round = True
curr_count = 0
round_total = 0
elif is_round:
if len(circles[0, :]) == 1:
end_time = time.time()
is_round = False
time_taken = end_time - start_time
print('Round time: ', str(
datetime.timedelta(seconds=time_taken))[2:7])
times.append(time_taken)
average = sum(times) / len(times)
print('Average time: ', str(
datetime.timedelta(seconds=average))[2:7])
elif len(circles[0, :]) < 7:
curr_count = (7 - round_total) - len(circles[0, :])
total += curr_count
round_total += curr_count
for i in circles[0, :]:
cv2.circle(img, (i[0], i[1]), i[2], (0, 255, 0), 2)
cv2.circle(img, (i[0], i[1]), 2, (0, 0, 255), 3)
yield dict(total=total, average=average)
@app.route("/")
def home():
return render_template('theme1.html')
gen_total = Tracking()
total, average = next(gen_total)
# initate the function out of the scope of update route
@app.get("/update")
def update():
return jsonify(next(gen_total))
if __name__ == "__main__":
app.run(debug=True)
average is a value that uses time.time so it returns a number to the webpage e.g 16.553839.. i need to make it so it returns the time in minutes and seconds e.g 16:55. I have the following code that does this
str(datetime.timedelta(seconds=average))[2:7]
i need to print this to the webpage, when i try yielding this value as a string i get an error
TypeError: unsupported type for timedelta seconds component: str
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script>
function update(){
$.get("/update", function(data){
$("#total").html(data.total)
$("#average").html(data.average.toFixed(2).replace(".", ":"))
});
}
update()
var intervalId = setInterval(function() {
update()
}, 1000);
</script>
How do i solve this? Thanks.