feat: enhance layout preprocessing and unify image scaling proposal
Backend changes: - Add image scaling configuration for PP-Structure processing - Enhance layout preprocessing service with scaling support - Update OCR service with improved memory management - Add PP-Structure enhanced processing improvements Frontend changes: - Update preprocessing settings UI - Fix processing page layout and state management - Update API types for new parameters Proposals: - Archive add-layout-preprocessing proposal (completed) - Add unify-image-scaling proposal for consistent coordinate handling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,7 @@ export default function PreprocessingSettings({
|
||||
}: PreprocessingSettingsProps) {
|
||||
const { t } = useTranslation()
|
||||
const modes: PreprocessingMode[] = ['auto', 'manual', 'disabled']
|
||||
const contrastOptions: PreprocessingContrast[] = ['none', 'histogram', 'clahe']
|
||||
const contrastOptions: PreprocessingContrast[] = ['none', 'histogram', 'clahe', 'document']
|
||||
|
||||
const getModeInfo = (m: PreprocessingMode) => ({
|
||||
label: t(`processing.preprocessing.mode.${m}`),
|
||||
|
||||
@@ -81,7 +81,8 @@
|
||||
"label": "對比度增強",
|
||||
"none": "不增強",
|
||||
"histogram": "直方圖均衡化",
|
||||
"clahe": "CLAHE 自適應均衡化"
|
||||
"clahe": "CLAHE 自適應均衡化",
|
||||
"document": "掃描件優化 (背景校正+CLAHE)"
|
||||
},
|
||||
"sharpen": "邊緣銳化",
|
||||
"strength": {
|
||||
|
||||
@@ -382,23 +382,49 @@ export default function ProcessingPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Direct Track Notice - Show when document is editable PDF */}
|
||||
{documentAnalysis && documentAnalysis.recommended_track === 'direct' && (
|
||||
<Card className="border-blue-200 bg-blue-50">
|
||||
{/* Document Analysis Info */}
|
||||
{documentAnalysis && (
|
||||
<Card className={documentAnalysis.recommended_track === 'direct' ? 'border-blue-200 bg-blue-50' : 'border-green-200 bg-green-50'}>
|
||||
<CardContent className="pt-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<Info className="w-5 h-5 text-blue-600 flex-shrink-0 mt-0.5" />
|
||||
<div>
|
||||
<p className="text-sm font-medium text-blue-800">此文件為可編輯 PDF</p>
|
||||
<p className="text-sm text-blue-700 mt-1">
|
||||
系統偵測到此 PDF 包含文字圖層,將使用直接文字提取方式處理。
|
||||
版面偵測和影像前處理設定不適用於此類文件。
|
||||
</p>
|
||||
{documentAnalysis.text_coverage && (
|
||||
<p className="text-xs text-blue-600 mt-2">
|
||||
文字覆蓋率: {(documentAnalysis.text_coverage * 100).toFixed(1)}%
|
||||
</p>
|
||||
<Info className={`w-5 h-5 flex-shrink-0 mt-0.5 ${documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}`} />
|
||||
<div className="flex-1">
|
||||
{documentAnalysis.recommended_track === 'direct' ? (
|
||||
<>
|
||||
<p className="text-sm font-medium text-blue-800">此文件為可編輯 PDF</p>
|
||||
<p className="text-sm text-blue-700 mt-1">
|
||||
系統偵測到此 PDF 包含文字圖層,將使用直接文字提取方式處理。
|
||||
版面偵測和影像前處理設定不適用於此類文件。
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<p className="text-sm font-medium text-green-800">
|
||||
{documentAnalysis.is_editable ? '混合文件' : '掃描文件 / 影像'}
|
||||
</p>
|
||||
<p className="text-sm text-green-700 mt-1">
|
||||
{documentAnalysis.reason}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-4 mt-2 text-xs">
|
||||
<span className={documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}>
|
||||
處理方式: {documentAnalysis.recommended_track === 'direct' ? '直接提取' : documentAnalysis.recommended_track === 'ocr' ? 'OCR 識別' : '混合處理'}
|
||||
</span>
|
||||
{documentAnalysis.page_count && (
|
||||
<span className={documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}>
|
||||
頁數: {documentAnalysis.page_count}
|
||||
</span>
|
||||
)}
|
||||
{documentAnalysis.text_coverage !== null && (
|
||||
<span className={documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}>
|
||||
文字覆蓋率: {(documentAnalysis.text_coverage * 100).toFixed(1)}%
|
||||
</span>
|
||||
)}
|
||||
<span className={documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}>
|
||||
信心度: {(documentAnalysis.confidence * 100).toFixed(0)}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
@@ -408,7 +408,7 @@ class ApiClientV2 {
|
||||
* Analyze document to get recommended processing track
|
||||
*/
|
||||
async analyzeDocument(taskId: string): Promise<DocumentAnalysisResponse> {
|
||||
const response = await this.client.get<DocumentAnalysisResponse>(`/tasks/${taskId}/analyze`)
|
||||
const response = await this.client.post<DocumentAnalysisResponse>(`/tasks/${taskId}/analyze`)
|
||||
return response.data
|
||||
}
|
||||
|
||||
|
||||
@@ -92,8 +92,12 @@ export type PreprocessingMode = 'auto' | 'manual' | 'disabled'
|
||||
|
||||
/**
|
||||
* Contrast enhancement method for preprocessing.
|
||||
* - none: No contrast enhancement
|
||||
* - histogram: Standard histogram equalization
|
||||
* - clahe: Contrast Limited Adaptive Histogram Equalization (good for most cases)
|
||||
* - document: Background normalization + CLAHE (best for scanned documents)
|
||||
*/
|
||||
export type PreprocessingContrast = 'none' | 'histogram' | 'clahe'
|
||||
export type PreprocessingContrast = 'none' | 'histogram' | 'clahe' | 'document'
|
||||
|
||||
/**
|
||||
* Preprocessing configuration for layout detection enhancement.
|
||||
|
||||
Reference in New Issue
Block a user