Enhance image before ai processing
This commit is contained in:
@@ -2,6 +2,7 @@ import json
|
||||
from pydantic import BaseModel, Field
|
||||
from APIs.aichat import generate
|
||||
import shared.config as config
|
||||
from PIL import Image, ImageEnhance
|
||||
|
||||
class UtensilMaterialCheck(BaseModel):
|
||||
object_name: str = Field(
|
||||
@@ -28,6 +29,21 @@ class DishSafetyResult(BaseModel):
|
||||
description="If is_safe is False, set to 'REMOVE METAL UTENSIL OR FOIL BEFORE MICROWAVING'. Otherwise empty ''."
|
||||
)
|
||||
|
||||
def preprocess_dish_image(image_path: str) -> str:
|
||||
"""Brightens dark areas and sharpens food texture for small vision models."""
|
||||
img = Image.open(image_path)
|
||||
|
||||
# 1. Boost brightness slightly
|
||||
enhancer = ImageEnhance.Brightness(img)
|
||||
img = enhancer.enhance(1.4)
|
||||
|
||||
# 2. Boost contrast to separate food shapes from dark shadows
|
||||
enhancer = ImageEnhance.Contrast(img)
|
||||
img = enhancer.enhance(1.3)
|
||||
|
||||
processed_path = "/tmp/processed_dish.jpg"
|
||||
img.save(processed_path, quality=85)
|
||||
return processed_path
|
||||
|
||||
def check_dish_safety(image_path: str) -> dict:
|
||||
prompt = (
|
||||
|
||||
Reference in New Issue
Block a user