Files
2nd/10_Wiki/Topics/Domain_Programming/AI_and_ML/Straightening.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

5.4 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-straightening Straightening 10_Wiki/Topics verified self
Image Straightening
Perspective Correction
Deskew
none A 0.9 applied
computer-vision
image-processing
perspective-correction
opencv
2026-05-10 pending
language framework
python opencv

Straightening

매 한 줄

"매 tilted image 의 axis-aligned 로 복원". Document scanning, satellite imagery, photo correction 의 fundamental preprocessing. Classical (Hough line + rotation, perspective transform) + modern deep learning (DeepDeskew, DocAligner) 의 combo.

매 핵심

매 두 가지 problem

  • Skew correction (rotation): 매 in-plane rotation 의 보정. Hough line 의 dominant angle detection.
  • Perspective correction (homography): 매 4-point 의 quadrilateral → rectangle. 매 non-frontal photo 의 document.

매 classical pipeline

  1. Edge detection (Canny).
  2. Line detection (Hough transform) 또는 corner detection.
  3. Dominant angle estimation 또는 4-point selection.
  4. Rotation matrix / homography 계산.
  5. Warp (affine / perspective).

매 modern (deep learning)

  • DocTr / DocAligner (2022+): document 의 corner regression.
  • CNN-based skew angle predictor: 매 single forward pass.
  • LayoutLMv3-based: 매 document understanding 의 part.

매 응용

  1. Document scanning apps (CamScanner, Adobe Scan).
  2. OCR preprocessing — 매 accuracy boost.
  3. Satellite imagery alignment.
  4. Receipt / business card capture.

💻 패턴

Skew detection via Hough

import cv2
import numpy as np

def detect_skew(img):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray, 50, 150)
    lines = cv2.HoughLines(edges, 1, np.pi / 180, 200)
    angles = [(theta * 180 / np.pi) - 90 for rho, theta in lines[:, 0]]
    return np.median([a for a in angles if -45 < a < 45])

Rotation correction

def rotate_image(img, angle):
    h, w = img.shape[:2]
    center = (w // 2, h // 2)
    M = cv2.getRotationMatrix2D(center, angle, 1.0)
    return cv2.warpAffine(img, M, (w, h), flags=cv2.INTER_CUBIC,
                          borderMode=cv2.BORDER_REPLICATE)

Perspective correction (4-point)

def four_point_transform(img, pts):
    rect = order_points(pts)
    (tl, tr, br, bl) = rect
    width = max(np.linalg.norm(br - bl), np.linalg.norm(tr - tl))
    height = max(np.linalg.norm(tr - br), np.linalg.norm(tl - bl))
    dst = np.array([[0, 0], [width-1, 0], [width-1, height-1], [0, height-1]],
                   dtype="float32")
    M = cv2.getPerspectiveTransform(rect, dst)
    return cv2.warpPerspective(img, M, (int(width), int(height)))

def order_points(pts):
    rect = np.zeros((4, 2), dtype="float32")
    s = pts.sum(axis=1); diff = np.diff(pts, axis=1)
    rect[0] = pts[np.argmin(s)]; rect[2] = pts[np.argmax(s)]
    rect[1] = pts[np.argmin(diff)]; rect[3] = pts[np.argmax(diff)]
    return rect

Document corner detection (modern)

# OpenCV contour-based (heuristic)
def find_document_corners(img):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    blurred = cv2.GaussianBlur(gray, (5, 5), 0)
    edges = cv2.Canny(blurred, 75, 200)
    cnts, _ = cv2.findContours(edges, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    cnts = sorted(cnts, key=cv2.contourArea, reverse=True)[:5]
    for c in cnts:
        approx = cv2.approxPolyDP(c, 0.02 * cv2.arcLength(c, True), True)
        if len(approx) == 4:
            return approx.reshape(4, 2)
    return None

Deep learning approach (DocAligner-style)

import torch
from torchvision import transforms

class CornerRegressor(torch.nn.Module):
    def __init__(self, backbone):
        super().__init__()
        self.backbone = backbone  # ResNet34
        self.head = torch.nn.Linear(512, 8)  # 4 corners x (x, y)

    def forward(self, x):
        feat = self.backbone(x)
        corners = self.head(feat).view(-1, 4, 2)
        return torch.sigmoid(corners)  # normalized [0, 1]

매 결정 기준

상황 Approach
매 simple skew (rotation only) Hough line + rotate
매 document photo 4-point perspective
매 noisy / cluttered scene DL corner regressor
매 mobile real-time Lightweight CNN (MobileNet)
매 batch / cloud LayoutLMv3 + classical refinement

기본값: 매 document → contour-based 4-point. 매 OCR pipeline → DocAligner.

🔗 Graph

🤖 LLM 활용

언제: OCR 의 preprocessing pipeline, document understanding 의 normalization, vision-language model 의 input quality 개선. 언제 X: 매 ill-defined edges (handwriting on textured background), 매 already aligned image (overhead).

안티패턴

  • Single Hough line: 매 outlier 의 dominate. median angle 사용.
  • Aggressive crop: rotation 후 black border 의 crop 시 content loss.
  • Over-correction: 매 small skew (< 0.5°) 무시 — overhead > benefit.

🧪 검증 / 중복

  • Verified (OpenCV docs, Hough 1962 patent, Suzuki & Be 1985 contour algorithm).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — Hough + perspective + DL corner coverage