File size: 1,845 Bytes
588951f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio.inputs
import torch
import gradio as gr
from PIL import Image
import tempfile
import detect
import os
import shutil


# result = detect.run(source=img, data="VOCdevkit/FLIR.yaml", weights="./best.pt")

def de(image):
    # 创建临时文件夹
    temp_path = tempfile.TemporaryDirectory(dir="./")
    temp_dir = temp_path.name
    # 临时图片的路径
    temp_image_path = os.path.join(temp_dir, f"temp.jpg")
    # 存储临时图片
    img = Image.fromarray(image)
    img.save(temp_image_path)
    # 结果图片的存储目录
    temp_result_path = os.path.join(temp_dir, "tempresult")
    # 对临时图片进行检测
    detect.run(source=temp_image_path, data="OCdevkit/FLIR.yaml", weights="./runs/train/exp/weights/best.pt", project=f'./{temp_dir}',name = 'tempresult', hide_conf=True)
    # 结果图片的路径
    temp_result_path = os.path.join(temp_result_path, os.listdir(temp_result_path)[0])
    # 读取结果图片
    result_image = Image.open(temp_result_path).copy()
    # 删除临时文件夹
    temp_path.cleanup()

    return result_image

example_image= [
    ["./VOCdevkit/images/train/video-2SReBn5LtAkL5HMj2-frame-005072-MA7NCLQGoqq9aHaiL.jpg"],
    ["./VOCdevkit/images/train/video-2rsjnZFyGQGeynfbv-frame-003708-6fPQbB7jtibwaYAE7.jpg"],
    ["./VOCdevkit/images/train/video-2SReBn5LtAkL5HMj2-frame-000317-HTgPBFgZyPdwQnNvE.jpg"],
    ["./VOCdevkit/images/val/video-jNQtRj6NGycZDEXpe-frame-002515-J3YntG8ntvZheKK3P.jpg"],
    ["./VOCdevkit/images/val/video-kDDWXrnLSoSdHCZ7S-frame-003063-eaKjPvPskDPjenZ8S.jpg"],
    ["./VOCdevkit/images/val/video-r68Yr9RPWEp5fW2ZF-frame-000333-X6K5iopqbmjKEsSqN.jpg"]
    ]

iface = gr.Interface(fn=de, inputs=gr.Image(label="上传一张红外图像,仅支持jpg格式"), outputs="image", examples=example_image, share=True)
iface.launch(share=True)