|
| 1 | +# Slider Captcha Solver API |
| 2 | + |
| 3 | +This project provides a robust API for solving slider captchas (puzzle piece matching) using computer vision techniques (Masked Normalized Cross-Correlation with Sobel Edge Detection). |
| 4 | + |
| 5 | +## Setup & Run |
| 6 | + |
| 7 | +1. Ensure Go is installed. |
| 8 | +2. Add authorized API keys to `allowed_keys.txt` (one per line). |
| 9 | +3. Run the server: |
| 10 | + ```bash |
| 11 | + go run . |
| 12 | + ``` |
| 13 | + The server starts on port `8080`. |
| 14 | + |
| 15 | +## Authentication |
| 16 | + |
| 17 | +All requests must include the `x-api-key` header. The key must exist in `allowed_keys.txt`. |
| 18 | + |
| 19 | +## API Reference |
| 20 | + |
| 21 | +### Solve Captcha |
| 22 | + |
| 23 | +**Endpoint:** `POST /solve` |
| 24 | + |
| 25 | +**Headers:** |
| 26 | +* `x-api-key`: (Required) Your API key. |
| 27 | + |
| 28 | +**Body (`multipart/form-data`):** |
| 29 | +* `background`: (Required) The background image file (PNG, JPEG). |
| 30 | +* `piece`: (Required) The puzzle piece image file (PNG, JPEG). |
| 31 | + |
| 32 | +**Response (`application/json`):** |
| 33 | + |
| 34 | +```json |
| 35 | +{ |
| 36 | + "x": 184,, |
| 37 | + "y": 34, |
| 38 | + "confidence": 0.798903 |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +* `x`: The X coordinate of the top-left corner of the matching position. |
| 43 | +* `y`: The Y coordinate of the top-left corner of the matching position. |
| 44 | +* `confidence`: A score between -1.0 and 1.0 indicating the quality of the match (higher is better). |
| 45 | + |
| 46 | +## Example Usage |
| 47 | + |
| 48 | +```bash |
| 49 | +curl -X POST http://localhost:8080/solve \ |
| 50 | + -H "x-api-key: secret-key-123" \ |
| 51 | + -F "background=@bg-1.png" \ |
| 52 | + -F "piece=@slice-1.png" |
| 53 | +``` |
| 54 | + |
| 55 | +## Algorithm Details |
| 56 | + |
| 57 | +The solver uses the following pipeline: |
| 58 | +1. **Cropping:** Automatically removes transparent/background borders from the puzzle piece. |
| 59 | +2. **Masking:** Extracts a shape mask from the puzzle piece to ignore empty corners during matching. |
| 60 | +3. **Blurring:** Applies Gaussian Blur to reduce texture noise. |
| 61 | +4. **Edge Detection:** Uses Sobel operator to extract structural outlines. |
| 62 | +5. **Matching:** Performs Normalized Cross-Correlation (NCC) between the masked piece edges and the background edges to find the best fit. |
0 commit comments