Skip to content
Snippets Groups Projects
tech.py 923 B
import os
import sys

image_path = sys.argv[1] 

if not os.path.exists(f"/var/www/html/forest/my_env/preview/dan/{image_path}"):

    import cv2
    from pathlib import Path
    from ultralytics import YOLO

    model = YOLO("best.pt")
    
    if os.path.exists(f"/var/www/html/forest/images/{image_path}"):
        file_path = f"/var/www/html/forest/images/{image_path}"
    else:
         file_path = f"/var/www/html/forest/animals/{image_path}"
    results = model(file_path, save=True, project="preview", name="dan", exist_ok=True)

    saved_dir = Path("preview/dan")

    for result in results:
        for path in saved_dir.glob("*"):
            if path.suffix.lower() not in [".jpeg"]: 
                img = cv2.imread(str(path))  
                new_path = path.with_suffix(".jpeg")  
                cv2.imwrite(str(new_path), img, [int(cv2.IMWRITE_JPEG_QUALITY), 95])  
                os.remove(str(path))