This repository contains an implementation of a pure computer vision algorithm designed to remove seals or stamps from images. The algorithm focuses on processing images to detect and eliminate seals while preserving the underlying content.
- Seal Detection: Identifies the location of seals in the image.
Note: Thedetect_seal_boxesfunction in this project may not be sufficiently robust for complex real-world cases. For better results, it is recommended to use a deep-learning-based detector, such as PaddleOCR's seal detection model or a fine-tuned variant. - Seal Removal: Removes the detected seals while maintaining the integrity of the original image.
Note: Inremove_seal_from_image, directly replacing seal pixels with(255, 255, 255)may not always produce natural results. A better strategy is to replace those regions using the average color computed from the four corners of the input image. - No Machine Learning: The algorithm is purely based on traditional computer vision techniques, without relying on pre-trained models.
- Python 3.x
- OpenCV
- NumPy
-
Clone the repository:
git clone https://github.com/yaodaoboy/remove_seal.git cd remove_seal -
Install the required dependencies:
pip install -r requirements.txt
remove_seal.py supports processing a single image file or a whole folder.
-
Run with default paths (
input->output):python remove_seal.py
-
Process a single file:
python remove_seal.py --input input/sample.jpg --output output/sample_clean.jpg
-
Process a folder with custom padding:
python remove_seal.py --input input --output output --padding 10
Arguments:
--input: Input image file or folder path. Default:input--output: Output image file or folder path. Default:output--padding: Expansion pixels for detected seal boxes. Default:8
Supported image formats: .jpg, .jpeg, .png, .bmp, .tif, .tiff
The images in the seals directory show real seal-removal results, including cases where seals overlap printed text and handwritten text.
For these processed outputs, you can directly send them to a VLM (Vision-Language Model) to extract the target information.
For example, if seals/4-1421-2339-1905-2779.png is sent to Deepseek-OCR2, the extraction result is shown below:
Input image:
Deepseek-OCR2 extraction result:
Contributions are welcome! Feel free to submit issues or pull requests to improve the algorithm or add new features.
This project is licensed under the MIT License. See the LICENSE file for details.
This algorithm is designed for educational purposes and may not work perfectly in all scenarios. Use it responsibly and ensure compliance with applicable laws and regulations.

