Recognize Luogu Captcha using an AI model.
- Ensure you have TamperMonkey or another UserScript manager installed in your browser.
- Install the UserScript by downloading the file predict.user.js.
The Model and Dataset are hosted on HuggingFace.
- Training data is located in the
datafolder. Note: The folder contains 1000 files, so exercise caution when opening it in your browser! - Training history visualization:

The data generator consists of generate.php and its Python wrapper generate.py.
generate.php- Without arguments: Generates a captcha, outputs the captcha answer to
stdout, and saves the image ascaptcha.jpg. - With two arguments (
tot,seed): Both arguments must be integers. The program generatestotimages using the random seedseed, concatenates all image data, and outputs it tostdout. Each image is formatted as follows:- First 2 bytes (
len): Length of the image data - Next 4 bytes: Captcha answer
- Next
lenbytes: Binary image data
- First 2 bytes (
- Without arguments: Generates a captcha, outputs the captcha answer to
generate.py- Requires three arguments:
TotalImagesandWorkersCount. It generatesTotalImagesimage batch files in thedatadirectory, formatted for HuggingFace (data/luogu_captcha_dataset) and TensorFlow (data/luogu_captcha_tfrecord).
- Requires three arguments:
The script train.py trains the model using TensorFlow with data from the data/luogu_captcha_tfrecord folder. The trained model is saved as models/luoguCaptcha.keras.
The script predict.py is used for captcha prediction.
- With one argument (
port): Starts an HTTP server on the specified port, providing a single API endpoint.- URL:
/ - Request Method:
POST - Request Body: JSON in the following format:
{ "image": "base64 encoded image file" } - Response Body: JSON in the following format:
{ "prediction": "the captcha answer" }
- URL:
This project is licensed under the terms of the GNU General Public License v3.0.