๐ซ The Pain Point
You have 100 raw portraits (rectangular 4:3). You need to crop them all to squares (1:1) for avatar uploads. If you simple โCenter Cropโ, you might cut off part of the head or the chin if the person is not standing exactly in the middle.
๐ Agentic Solution
Smart Cropping Tool: It โlooksโ for the face/subject first, calculates the bounding box, and then crops a square around that center.
Key Features:
- Face Detection: Uses OpenCV (Haar Cascade) to find faces.
- Smart Padding: If the face is too close to the edge, it adds padding instead of cropping tightly.
โ๏ธ Phase 1: Commander (Quick Fix)
For cropping a single batch of headshots.
Prompt:
โI have a folder of portraits. Use OpenCV to detect the face in each photo and crop a 500x500 square centered on the face. If no face is found, just crop the center. Save to โCroppedโ folder.โ
Result: A folder of perfectly centered avatars.
๐๏ธ Phase 2: Architect (Permanent Tool)
For HR/School Admins.
Engineering Prompt:
**Role:** Python Computer Vision Dev
**Task:** Create a "Face-Centric Square Cropper".
**Requirements:**
1. **GUI:**
* Select Input Folder.
* Target Size (e.g., 500px).
* "Start Processing" button.
2. **Logic:**
* Load `haarcascade_frontalface_default.xml`.
* Detect face coordinates (x, y, w, h).
* Calculate the center of the face.
* Crop a square region around that center.
* Handle cases where the square goes out of bounds (add padding).
3. **Deliverables:** `smart_crop.py`, `run.bat` (Windows), `run.sh` (Mac).
๐ง Prompt Decoding
- Haar Cascade: An old but very fast and efficient algorithm for face detection. Itโs built into OpenCV, meaning you donโt need heavy deep learning models like YOLO for this simple task.
๐ ๏ธ Instructions
- Copy Prompt -> Paste -> Run.
- Select Folder -> Start.