Fix cropping inaccuracies: added 15px padding and tightened article segmentation gap
This commit is contained in:
parent
d57b8cb595
commit
b0b7ed7e0d
|
|
@ -16,7 +16,7 @@ spec:
|
||||||
containers:
|
containers:
|
||||||
- name: backend
|
- name: backend
|
||||||
image: 192.168.8.250:5000/agentic-os/newspaper-extractor-backend:latest
|
image: 192.168.8.250:5000/agentic-os/newspaper-extractor-backend:latest
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: IfNotPresent
|
||||||
env:
|
env:
|
||||||
- name: DATABASE_URL
|
- name: DATABASE_URL
|
||||||
value: "postgresql://myuser:mypassword@newspaper-db.ai-agents.svc.cluster.local:5432/mydatabase"
|
value: "postgresql://myuser:mypassword@newspaper-db.ai-agents.svc.cluster.local:5432/mydatabase"
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ spec:
|
||||||
containers:
|
containers:
|
||||||
- name: frontend
|
- name: frontend
|
||||||
image: 192.168.8.250:5000/agentic-os/newspaper-extractor-frontend:latest
|
image: 192.168.8.250:5000/agentic-os/newspaper-extractor-frontend:latest
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: IfNotPresent
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 3000
|
- containerPort: 3000
|
||||||
---
|
---
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ spec:
|
||||||
containers:
|
containers:
|
||||||
- name: worker
|
- name: worker
|
||||||
image: 192.168.8.250:5000/agentic-os/newspaper-extractor-backend:latest
|
image: 192.168.8.250:5000/agentic-os/newspaper-extractor-backend:latest
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: IfNotPresent
|
||||||
command: ["celery", "-A", "app.tasks.celery_app", "worker", "--loglevel=info", "-P", "solo"]
|
command: ["celery", "-A", "app.tasks.celery_app", "worker", "--loglevel=info", "-P", "solo"]
|
||||||
env:
|
env:
|
||||||
- name: DATABASE_URL
|
- name: DATABASE_URL
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: kaniko-backend
|
||||||
|
namespace: platform-data
|
||||||
|
spec:
|
||||||
|
restartPolicy: Never
|
||||||
|
volumes:
|
||||||
|
- name: workspace
|
||||||
|
emptyDir: {}
|
||||||
|
initContainers:
|
||||||
|
- name: clone-repo
|
||||||
|
image: alpine/git
|
||||||
|
command:
|
||||||
|
- /bin/sh
|
||||||
|
- -c
|
||||||
|
- "git clone http://gitea.gitea.svc.cluster.local:3000/deepkoluguri/agentic-os.git /workspace"
|
||||||
|
volumeMounts:
|
||||||
|
- name: workspace
|
||||||
|
mountPath: /workspace
|
||||||
|
containers:
|
||||||
|
- name: kaniko
|
||||||
|
image: gcr.io/kaniko-project/executor:latest
|
||||||
|
args:
|
||||||
|
- "--context=dir:///workspace/newspaper-extractor/backend"
|
||||||
|
- "--dockerfile=Dockerfile"
|
||||||
|
- "--destination=registry.platform-data.svc.cluster.local:5000/agentic-os/newspaper-extractor-backend:latest"
|
||||||
|
- "--insecure"
|
||||||
|
- "--skip-tls-verify"
|
||||||
|
- "--cache=false"
|
||||||
|
volumeMounts:
|
||||||
|
- name: workspace
|
||||||
|
mountPath: /workspace
|
||||||
|
|
@ -89,7 +89,7 @@ class ArticleSegmenter:
|
||||||
cur = block["bbox"]
|
cur = block["bbox"]
|
||||||
same_col = abs(last[0] - cur[0]) < 0.05 * page_width
|
same_col = abs(last[0] - cur[0]) < 0.05 * page_width
|
||||||
gap = cur[1] - last[3]
|
gap = cur[1] - last[3]
|
||||||
return same_col and gap < 0.04 * page_width
|
return same_col and gap < 0.025 * page_width
|
||||||
|
|
||||||
def _merge_columns(self, articles, page_width):
|
def _merge_columns(self, articles, page_width):
|
||||||
# Merge article fragments whose headline spans wide / text flows to next col
|
# Merge article fragments whose headline spans wide / text flows to next col
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,16 @@
|
||||||
import cv2, os, uuid
|
import cv2, os, uuid
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
|
|
||||||
def crop_article(page_image, bbox, out_dir):
|
def crop_article(page_image, bbox, out_dir, pad=15):
|
||||||
x, y, w, h = [int(v) for v in bbox]
|
x, y, w, h = [int(v) for v in bbox]
|
||||||
crop = page_image[y:y+h, x:x+w]
|
img_h, img_w = page_image.shape[:2]
|
||||||
|
|
||||||
|
x1 = max(0, x - pad)
|
||||||
|
y1 = max(0, y - pad)
|
||||||
|
x2 = min(img_w, x + w + pad)
|
||||||
|
y2 = min(img_h, y + h + pad)
|
||||||
|
|
||||||
|
crop = page_image[y1:y2, x1:x2]
|
||||||
os.makedirs(out_dir, exist_ok=True)
|
os.makedirs(out_dir, exist_ok=True)
|
||||||
path = os.path.join(out_dir, f"article_{uuid.uuid4().hex[:8]}.png")
|
path = os.path.join(out_dir, f"article_{uuid.uuid4().hex[:8]}.png")
|
||||||
cv2.imwrite(path, cv2.cvtColor(crop, cv2.COLOR_RGB2BGR))
|
cv2.imwrite(path, cv2.cvtColor(crop, cv2.COLOR_RGB2BGR))
|
||||||
|
|
@ -13,7 +20,7 @@ def crop_figures(page_image, article, out_dir):
|
||||||
paths = []
|
paths = []
|
||||||
for b in article["blocks"]:
|
for b in article["blocks"]:
|
||||||
if b["type"] == "Figure":
|
if b["type"] == "Figure":
|
||||||
paths.append(crop_article(page_image, _xywh(b["bbox"]), out_dir))
|
paths.append(crop_article(page_image, _xywh(b["bbox"]), out_dir, pad=5))
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
def _xywh(box):
|
def _xywh(box):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue