ottoykh's picture
Upload 32 files
60a0db4 verified
raw
history blame
1.13 kB
import pytz
import datetime
import os
import requests
from urllib.parse import urlparse
import time
from ultralytics import YOLO
def process_images(image_urls):
hong_kong_timezone = pytz.timezone('Asia/Hong_Kong')
while True:
current_time = datetime.datetime.now(tz=hong_kong_timezone).strftime("%Y%m%d%H%M%S")
folder_name = f"/content/{current_time}"
print(folder_name)
os.makedirs(folder_name, exist_ok=True)
for image_url in image_urls:
response = requests.get(image_url)
image_data = response.content
parsed_url = urlparse(image_url)
image_name = os.path.basename(parsed_url.path)
file_name = os.path.join(folder_name, image_name)
with open(file_name, "wb") as file:
file.write(image_data)
print(file_name)
folder_name_formatted = f"'{folder_name}'"
yolo = YOLO('/content/Smart-Traffic/best.pt')
yolo.set_conf(0.45)
yolo.predict(source=folder_name_formatted, save=True, save_txt=True)
time.sleep(120)