Downloads · 30 days
0
Softy-lines/Captcha-Digit-Detector
Captcha-Digit-Detector is a object detection model from Softy-lines. Use it when you need objects located in an image. It is set up for adapter-transformers. The card lists the license as apache-2.0.
- License: Apache-2.0 - Developed by: Saidi Souhaieb - Finetuned from model: YOLOv8
Downloads · 30 days
0
Access
Public
Updated May 8, 2024
Repo size
18.5 MB
Likes
0
Public
Click a slice to open those files.
.pt18.5 MB · 100%
From the Hugging Face model README
This model is designed to detect pixelated captcha digits by showing bounding boxes and extracting the coordinates of the detections.
from PIL import Image, ImageDraw
from YOLO import YOLO # Assuming YOLO is a class in a module named YOLO
# Load the model
model = YOLO("models/number_finder.pt")
# Get model results
model_results = model(image_path)
img = Image.open(image_path)
draw = ImageDraw.Draw(img)
# Sort results based on the x-coordinate
detected_objects = []
captcha_result = ""
boxes_data = []
for result in model_results:
for box in result.boxes:
box_data = {"xyxy": box.xyxy[0].tolist(),
"label": str(box.cls.item())}
boxes_data.append(box_data)
sorted_boxes_data = sorted(boxes_data, key=lambda x: x['xyxy'][0])
# Remove similar boxes
unique_sorted_boxes_data = [sorted_boxes_data[0]]
for i in range(1, len(sorted_boxes_data)):
current_box = sorted_boxes_data[i]
prev_box = unique_sorted_boxes_data[-1]
# Check if the current box's x-coordinate is significantly different from the previous box
if abs(current_box['xyxy'][0] - prev_box['xyxy'][0]) > 1: # Adjust threshold as needed
unique_sorted_boxes_data.append(current_box)
for box in unique_sorted_boxes_data:
label_name = box["label"]
box_coords = box["xyxy"]
detected_objects.append((box_coords))
draw.rectangle(box_coords, outline="red")
draw.text((box_coords[0], box_coords[1] - 10), label_name, fill="red")
captcha_result += str(int(label_name[0]) - 2)
img.show() # Display the image with bounding boxes and labels
Raw Pixel Digit Captcha Data [https://huggingface.co/datasets/Softy-lines/Raw-Pixel-Digit-Captcha]
[Saidi Souhaieb]