## Pet Image Quality Detection <span class="tag_h2">On-App AI</span>

<div style="display: flex; align-items: center; justify-content: flex-start; margin-top: 20px;">
<img alt="Pet Image Quality Detection" src="https://images.tuyacn.com/rms-static/83839850-564f-11f0-9fb9-e1834df84344-1751355995733.jpg?tyName=image_error.jpg" width="250" style="margin-right: 10px;">
<img alt="Pet Image Quality Detection" src="https://images.tuyacn.com/rms-static/83851ef0-564f-11f0-9f57-5d628208d2a7-1751355995743.jpg?tyName=image_success.jpg" width="250">
</div>

### Feature Introduction

This feature supports real-time quality inspection of images uploaded by users, automatically intercepting low-quality images such as blurry, distorted, and low resolution pictures to avoid ineffective transmission. Through local real-time filtering, it reduces dependency on cloud detection, significantly lowers network latency, enhances response efficiency, and provides a smoother upload experience for users.

### Process Description

1. **Subject Recognition**

   - Automatically identify the subject in the image (e.g., a pet) using object detection models
   - Output the subject category, position coordinates, and size information

2. **Face Detection**

   - Locate the pet's face area first
   - Identify key facial features (e.g., eyes, nose) afterward

3. **Quality Verification**

   - **Brightness Detection**: Calculate the average brightness of the subject area to filter out overexposed/underexposed images
   - **Posture Detection**: Calculate facial deflection angles based on feature points
   - **Occlusion Detection**: Determine if there are any obstructions to the face

### Interaction Flow

```mermaid
sequenceDiagram
    participant User
    participant Panel
    participant AI Engine
    participant Cloud

    rect rgb(200, 230, 255)
        User->>Panel: Enter the Create/Edit Pet Profile page
        Panel->>AI Engine: petsDetectCreate()
        AI Engine-->>Panel: Instance entity
    end

    rect rgb(200, 255, 225)
        Panel->>AI Engine: petsPictureQualityDetectForImage(images)
        AI Engine->>AI Engine: Analyze image quality
        alt High Quality
            AI Engine-->>Panel: {lowQuality: false}
        else Low Quality
            AI Engine-->>Panel: {lowQuality: true, reason: 11xx/12xx/13xx}
        end
    end

    rect rgb(255, 230, 200)
        alt Images meeting the standards are present
            Panel->>Cloud: Upload images that passed the detection
            Cloud-->>Panel: Return training results
            Panel->>User: Proceed to the next step
        else No images meeting the standards are present
            Panel->>User: Display error message
        end
    end
```

### Notes

1. It is recommended to reuse the same pet image quality detection instance within a single page.

2. Timely destruction of instances that are no longer in use is advisable.
