Skip to content

Instantly share code, notes, and snippets.

@me-suzy
Created May 10, 2026 14:34
Show Gist options
  • Select an option

  • Save me-suzy/706cdb55a7022c3ce091b7afbb0d62c1 to your computer and use it in GitHub Desktop.

Select an option

Save me-suzy/706cdb55a7022c3ce091b7afbb0d62c1 to your computer and use it in GitHub Desktop.
ar34t5t.py
import cv2
import numpy as np
from pathlib import Path
INPUT_DIR = Path(r"g:\Colectia EMINESCIANA")
OUTPUT_DIR = Path(r"g:\Colectia EMINESCIANA\Output")
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
def procesare_ultra_rapida(img_path):
# 1. Citire imagine
img = cv2.imread(str(img_path), cv2.IMREAD_GRAYSCALE)
if img is None: return False
# 2. Threshold rapid (forțăm contrastul)
# Tot ce e gri închis devine negru, restul alb
_, binary = cv2.threshold(img, 150, 255, cv2.THRESH_BINARY_INV)
# 3. Ștergere "Zăpadă" (Morphological Opening)
# Folosim un sâmbure mic (2x2) care elimină tot ce e mai mic decât o literă
kernel_clean = np.ones((2, 2), np.uint8)
clean = cv2.morphologyEx(binary, cv2.MORPH_OPEN, kernel_clean)
# 4. Îngroșare Text (pentru a face literele negre intens)
kernel_bold = np.ones((2, 2), np.uint8)
bold = cv2.dilate(clean, kernel_bold, iterations=1)
# 5. Inversare (Text negru pe fundal alb pur)
final = cv2.bitwise_not(bold)
# 6. Salvare rapidă
cv2.imwrite(str(OUTPUT_DIR / img_path.name), final)
return True
# Rulare
files = list(INPUT_DIR.glob("*.jpg")) + list(INPUT_DIR.glob("*.png"))
print(f"🚀 Start procesare rapidă: {len(files)} fișiere...")
for i, path in enumerate(files):
procesare_ultra_rapida(path)
if i % 10 == 0: # Afișează progresul din 10 în 10 pentru a nu încetini consola
print(f"Progres: {i}/{len(files)}")
print("🏁 Gata! Verifică folderul Output.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment