🤖 AI/ML

OCR

Optical Character Recognition

Extracts text from images. Used for document digitization.

📖 Detailed Explanation

OCR (Optical Character Recognition) is a technology that extracts text from images or scanned documents and converts it into editable digital text. It is used in a variety of fields, such as digitizing paper documents, business card recognition, license plate recognition, and receipt processing.

It began with Emanuel Goldberg's work on machines in the 1920s, and commercial OCR systems appeared in the 1970s. In the 2000s, the Tesseract open-source engine was released, and in the 2010s, deep learning-based OCR dramatically improved accuracy. Today, multimodal LLMs such as GPT-4V and Claude Vision can understand even complex documents.

An OCR pipeline consists of the following stages: image preprocessing (noise removal, skew correction) → text region detection (Text Detection) → character recognition (Text Recognition) → post-processing (spelling correction, layout restoration). For deep learning models, CRNN and Transformer-based architectures are mainly used.

When choosing an OCR in practice, the points to consider are supported languages (whether Korean is included), accuracy, processing speed, and cost. A combination works well: Tesseract for simple tasks, Google Vision/AWS Textract for high-quality documents, and multimodal LLMs for complex layouts. For Korean OCR, Naver CLOVA OCR and Kakao OCR are also good choices.

💻 Code Example

# OCR 구현 예제 (Tesseract + EasyOCR)
# pip install pytesseract easyocr pillow

import pytesseract
from PIL import Image
import easyocr

# ===== 1. Tesseract OCR (오픈소스) =====
# Tesseract 설치 필요: apt-get install tesseract-ocr tesseract-ocr-kor

def tesseract_ocr(image_path):
    """Tesseract로 텍스트 추출"""
    image = Image.open(image_path)
    # 한글 + 영어 인식
    text = pytesseract.image_to_string(image, lang='kor+eng')
    return text

# 상세 정보 (위치, 신뢰도 포함)
def tesseract_detailed(image_path):
    image = Image.open(image_path)
    data = pytesseract.image_to_data(image, lang='kor+eng', output_type=pytesseract.Output.DICT)
    return data

# ===== 2. EasyOCR (딥러닝 기반) =====
def easy_ocr(image_path):
    """EasyOCR로 텍스트 추출 (GPU 지원)"""
    reader = easyocr.Reader(['ko', 'en'])  # 한글, 영어
    results = reader.readtext(image_path)

    # 결과: [(좌표, 텍스트, 신뢰도), ...]
    for (bbox, text, confidence) in results:
        print(f"텍스트: {text}, 신뢰도: {confidence:.2%}")

    return results

# ===== 3. Google Cloud Vision API =====
# pip install google-cloud-vision
from google.cloud import vision

def google_vision_ocr(image_path):
    """Google Vision API로 고품질 OCR"""
    client = vision.ImageAnnotatorClient()

    with open(image_path, 'rb') as f:
        content = f.read()

    image = vision.Image(content=content)
    response = client.text_detection(image=image)
    texts = response.text_annotations

    if texts:
        return texts[0].description  # 전체 텍스트
    return ""

# ===== 4. 이미지 전처리 (정확도 향상) =====
import cv2
import numpy as np

def preprocess_image(image_path):
    """OCR 전 이미지 품질 개선"""
    img = cv2.imread(image_path)
    # 그레이스케일 변환
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    # 노이즈 제거
    denoised = cv2.fastNlMeansDenoising(gray)
    # 이진화 (Adaptive Threshold)
    binary = cv2.adaptiveThreshold(
        denoised, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
        cv2.THRESH_BINARY, 11, 2
    )
    return binary

# 사용 예시
# text = tesseract_ocr("document.png")
# results = easy_ocr("receipt.jpg")

🗣️ Say It Like This in Practice

💬 In a Technical Review Meeting
"For receipt processing, Google Vision or AWS Textract offers high accuracy. If cost is a concern, start with EasyOCR, and even just doing preprocessing (binarization, skew correction) well can get you over 90% accuracy with Tesseract."
💬 In an Interview
"An OCR pipeline consists of preprocessing, text detection, character recognition, and post-processing. Before deep learning it was rule-based, but now CRNN or Transformer-based models are mainly used. Recently, multimodal LLMs such as GPT-4V are also used to handle complex layouts."
💬 In a Troubleshooting Situation
"If the Korean recognition rate is low, first check the image resolution. 300 DPI or higher is good, and deskew processing is essential for tilted documents. If that still doesn't work, a Korean-specialized service such as Naver CLOVA OCR may be better."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Applying OCR directly without preprocessing

If you run OCR directly on low-quality images, accuracy drops sharply. Preprocessing such as noise removal, binarization, and skew correction is essential.

❌
Expecting 100% accuracy

Even top-tier OCR is not 100% perfect. Design post-processing (spell checking, regular expression validation) and a human review process.

✅
The right approach

Choose an OCR engine suited to the data characteristics → build a preprocessing pipeline → confidence-based post-processing → implement a manual review process for low-confidence results

🔗 Related Terms

📚 Learn More