Skip to content

mosh-dvd/ocr-hebrew

Repository files navigation

מנוע OCR לעברית / Hebrew OCR Engine

מנוע זיהוי תווים אופטי (OCR) מאפס ב-Go, המתמחה בזיהוי טקסט עברי בגופנים שונים.

A from-scratch Optical Character Recognition (OCR) engine built in Go, specializing in Hebrew text recognition across different fonts.

תכונות / Features

  • ✅ תמיכה בעברית רגילה וכתב רשי / Support for regular Hebrew and Rashi script
  • ✅ עיבוד תמונה מתקדם / Advanced image preprocessing
  • ✅ זיהוי טקסט דו-כיווני / Bidirectional text recognition
  • ✅ פורמטי פלט מרובים (Plain Text, JSON, hOCR) / Multiple output formats
  • ✅ אימון מודלים מותאם אישית / Custom model training
  • ✅ ציוני ביטחון לכל תו / Per-character confidence scores
  • ✅ מצב אינטראקטיבי לתיקון ידני / Interactive mode for manual corrections

דרישות מערכת / Requirements

  • Go 1.24 or higher
  • 500MB RAM minimum
  • Supported image formats: PNG, JPEG, TIFF

התקנה / Installation

go get github.com/hebrew-ocr/engine

שימוש בסיסי / Basic Usage

כקובץ הפעלה / As CLI Application

# זיהוי תמונה בסיסי / Basic image recognition
ocr -input image.png

# עם פורמט פלט ספציפי / With specific output format
ocr -input image.png -format json

# עם סוג גופן ספציפי / With specific font type
ocr -input image.png -font rashi

# מצב debug / Debug mode
ocr -input image.png -debug

# מצב אינטראקטיבי לתיקון ידני / Interactive mode for manual corrections
ocr -input image.png -model models/hebrew_regular.model -interactive

מצב אינטראקטיבי / Interactive Mode

המצב האינטראקטיבי מאפשר לך לתקן ידנית תווים שזוהו בצורה שגויה ולשפר את המודל:

Interactive mode allows you to manually correct misrecognized characters and improve the model:

# התחלת מצב אינטראקטיבי / Start interactive mode
ocr -input document.png -model models/hebrew_regular.model -interactive

# פקודות זמינות / Available commands:
> view          # הצגת תוצאות / View results
> correct 5 א   # תיקון תו / Correct character at index 5
> save          # שמירת תיקונים / Save corrections
> apply         # החלת תיקונים על המודל / Apply corrections to model
> export path   # ייצוא כנתוני אימון / Export as training data
> quit          # יציאה / Exit

למידע נוסף, ראה Interactive Mode Guide.

For more information, see the Interactive Mode Guide.

כספרייה / As Library

package main

import (
    "fmt"
    "image"
    _ "image/jpeg"
    _ "image/png"
    "os"
    
    "github.com/hebrew-ocr/engine/pkg/ocr"
)

func main() {
    // יצירת תצורה / Create configuration
    config := &ocr.Config{
        FontType:      ocr.RegularHebrew,
        MinConfidence: 0.5,
        OutputFormat:  ocr.PlainText,
    }
    
    // אתחול המנוע / Initialize engine
    engine := ocr.NewOCREngine(config)
    
    // טעינת תמונה / Load image
    file, _ := os.Open("image.png")
    defer file.Close()
    img, _, _ := image.Decode(file)
    
    // זיהוי טקסט / Recognize text
    result, err := engine.RecognizeImage(img)
    if err != nil {
        panic(err)
    }
    
    fmt.Printf("Text: %s\n", result.Text)
    fmt.Printf("Confidence: %.2f\n", result.Confidence)
}

אימון מודלים / Training Models

יצירת נתוני אימון / Generating Training Data

המנוע כולל כלי ליצירת נתוני אימון סינתטיים:

The engine includes a tool for generating synthetic training data:

# יצירת נתוני אימון עם הגדרות ברירת מחדל / Generate with default settings
./scripts/generate_training_data.sh

# יצירה עם הגדרות מותאמות / Generate with custom settings
./scripts/generate_training_data.sh -s 64 -n 10 -o my_training_data/

נתוני האימון הסינתטיים כוללים:

  • 27 תווים עבריים (22 אותיות רגילות + 5 אותיות סופיות)
  • 5 וריאציות לכל תו (ברירת מחדל)
  • מאפיינים מחולצים אוטומטית (16 zoning + 6 stroke features)

Synthetic training data includes:

  • 27 Hebrew characters (22 regular letters + 5 final forms)
  • 5 variations per character (default)
  • Automatically extracted features (16 zoning + 6 stroke features)

שימוש בנתוני אימון / Using Training Data

// טעינת נתוני אימון / Load training data
dataset, err := classification.LoadTrainingData("testdata/training/hebrew_regular.json")
if err != nil {
    panic(err)
}

// אימון המודל / Train the model
err = engine.Train(dataset)
if err != nil {
    panic(err)
}

// שמירת המודל / Save the model
err = engine.SaveModel("models/custom_model.bin")
if err != nil {
    panic(err)
}

פורמטי פלט / Output Formats

Plain Text

שלום עולם

JSON

{
  "text": "שלום עולם",
  "confidence": 0.92,
  "characters": [
    {
      "char": "ש",
      "confidence": 0.95,
      "position": {"x": 10, "y": 20},
      "boundingBox": {"x": 10, "y": 20, "width": 15, "height": 20}
    }
  ],
  "processingTime": "1.2s",
  "metadata": {
    "imageWidth": 800,
    "imageHeight": 600,
    "modelVersion": "1.0"
  }
}

hOCR

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
    <div class='ocr_page'>
      <span class='ocrx_word' title='bbox 10 20 100 40; x_wconf 92'>שלום</span>
    </div>
  </body>
</html>

מבנה הפרויקט / Project Structure

.
├── cmd/
│   └── ocr/              # CLI application
├── pkg/
│   ├── ocr/              # Core OCR engine
│   ├── preprocessing/    # Image preprocessing
│   ├── segmentation/     # Character segmentation
│   ├── features/         # Feature extraction
│   ├── classification/   # Character classification
│   └── reconstruction/   # Text reconstruction
├── internal/
│   ├── logger/           # Logging utilities
│   └── profiler/         # Performance profiling
├── testdata/
│   ├── training/         # Training datasets
│   └── images/           # Test images
└── models/               # Trained models

בדיקות / Testing

# הרצת כל הבדיקות / Run all tests
go test ./...

# בדיקות עם כיסוי / Tests with coverage
go test -cover ./...

# בדיקות property-based / Property-based tests
go test -v ./... -run Property

ביצועים / Performance

  • עמוד A4 ב-300 DPI: < 5 שניות / A4 page at 300 DPI: < 5 seconds
  • עיבוד מקבילי: עד 4 תמונות במקביל / Concurrent processing: up to 4 images
  • צריכת זיכרון: < 500MB לתמונה / Memory usage: < 500MB per image

תרומה / Contributing

תרומות מתקבלות בברכה! אנא פתחו issue או pull request.

Contributions are welcome! Please open an issue or pull request.

רישיון / License

MIT License

יוצרים / Authors

Hebrew OCR Engine Team

קישורים / Links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors