ugolefoo commited on
Commit
972f9e7
Β·
verified Β·
1 Parent(s): 98e9b1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -21
app.py CHANGED
@@ -19,7 +19,7 @@ def detect_book_regions(image: np.ndarray, min_area=10000, eps_coef=0.02):
19
  edges = cv2.Canny(blurred, 50, 150)
20
 
21
  # Dilate + erode to close gaps
22
- kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5))
23
  closed = cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel)
24
 
25
  contours, _ = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
@@ -56,23 +56,4 @@ def ocr_on_region(image: np.ndarray, box: tuple):
56
  x, y, w, h = box
57
  cropped = image[y:y+h, x:x+w]
58
  gray_crop = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
59
- _, thresh_crop = cv2.threshold(gray_crop, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
60
- custom_config = r'--oem 3 --psm 6'
61
- text = pytesseract.image_to_string(thresh_crop, config=custom_config)
62
- return text.strip()
63
-
64
- # ──────────────────────────────────────────────────────────────
65
- # 3. Query OpenLibrary API
66
- # ──────────────────────────────────────────────────────────────
67
- def query_openlibrary(title_text: str, author_text: str = None):
68
- """
69
- Search OpenLibrary by title (and optional author).
70
- Return a dict with title, author_name, publisher, first_publish_year, or None.
71
- """
72
- base_url = "https://openlibrary.org/search.json"
73
- params = {"title": title_text}
74
- if author_text:
75
- params["author"] = author_text
76
-
77
- try:
78
- resp = requests.get(base_url, params=params, timeout=5)
 
19
  edges = cv2.Canny(blurred, 50, 150)
20
 
21
  # Dilate + erode to close gaps
22
+ kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
23
  closed = cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel)
24
 
25
  contours, _ = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
 
56
  x, y, w, h = box
57
  cropped = image[y:y+h, x:x+w]
58
  gray_crop = cv2.cvtColor(cropped, cv2.COLOR_BGR2GRAY)
59
+ _, thresh_crop = cv2.threshold(gray_crop, 0, 255, cv2._