File size: 1,289 Bytes
3fd025a | 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 52 53 54 55 56 | import json
import pandas as pd
from PIL import Image
from .model import model
from .data import pepsodent_qpds_data
async def detection(model, img_content, confidence):
try:
img = Image.open(img_content)
result = model(source=img, device=0, conf=confidence)
detection = {}
data = json.loads(result[0].tojson())
if not result or not data:
return {}
else:
name_counts = {}
for item in data:
name = item['name']
if name in name_counts:
name_counts[name] += 1
else:
name_counts[name] = 1
detection.update(name_counts)
return detection
except Exception as e:
return {}
async def format_result(convertData,resData):
try:
result = {}
for aiName,sysName in convertData.items():
if aiName in resData:
result.update({sysName:resData[aiName]})
return result
except Exception as e:
pass
async def main(img):
try:
result = await detection(model,img,0.3)
formattedResult = await format_result(pepsodent_qpds_data,result)
return formattedResult
except Exception as e:
pass
|