Showing
3 changed files
with
7 additions
and
5 deletions
| ... | @@ -89,8 +89,8 @@ class OcrController extends Controller | ... | @@ -89,8 +89,8 @@ class OcrController extends Controller |
| 89 | $templateName = $request->get('template_name', ''); | 89 | $templateName = $request->get('template_name', ''); |
| 90 | 90 | ||
| 91 | // Giả sử file OCR JSON & ảnh nằm trong storage/app/public/image/ | 91 | // Giả sử file OCR JSON & ảnh nằm trong storage/app/public/image/ |
| 92 | - $jsonPath = public_path("image/nemo_new_1757393338_with_table.json"); | 92 | + $jsonPath = public_path("image/Iwasaki_1757404869_with_table.json"); |
| 93 | - $imgPath = ("image/nemo_new_1757393338.jpg"); | 93 | + $imgPath = ("image/Iwasaki_1757404869.jpg"); |
| 94 | 94 | ||
| 95 | if (!file_exists($jsonPath)) { | 95 | if (!file_exists($jsonPath)) { |
| 96 | return response()->json(['error' => 'File OCR JSON không tìm thấy'], 404); | 96 | return response()->json(['error' => 'File OCR JSON không tìm thấy'], 404); | ... | ... |
| ... | @@ -2,7 +2,7 @@ import cv2 | ... | @@ -2,7 +2,7 @@ import cv2 |
| 2 | import numpy as np | 2 | import numpy as np |
| 3 | import os | 3 | import os |
| 4 | 4 | ||
| 5 | -def filter_horizontal_lines(lines_h, img_width, min_h_len_ratio=0.8, tol_y=10): | 5 | +def filter_horizontal_lines(lines_h, img_width, min_h_len_ratio=0.7, tol_y=10): |
| 6 | if lines_h is None: | 6 | if lines_h is None: |
| 7 | return [], [] | 7 | return [], [] |
| 8 | 8 | ||
| ... | @@ -56,7 +56,7 @@ def detect_tables(image_path, gap_threshold=50): | ... | @@ -56,7 +56,7 @@ def detect_tables(image_path, gap_threshold=50): |
| 56 | lines_h = cv2.HoughLinesP(edges, 1, np.pi/180, threshold=120, | 56 | lines_h = cv2.HoughLinesP(edges, 1, np.pi/180, threshold=120, |
| 57 | minLineLength=int(img.shape[1] * 0.6), maxLineGap=20) | 57 | minLineLength=int(img.shape[1] * 0.6), maxLineGap=20) |
| 58 | img_height, img_width = img.shape[:2] | 58 | img_height, img_width = img.shape[:2] |
| 59 | - ys, line_segments = filter_horizontal_lines(lines_h, img_width, min_h_len_ratio=0.8, tol_y=10) | 59 | + ys, line_segments = filter_horizontal_lines(lines_h, img_width, min_h_len_ratio=0.7, tol_y=10) |
| 60 | total_rows = max(0, len(ys) - 1) | 60 | total_rows = max(0, len(ys) - 1) |
| 61 | 61 | ||
| 62 | # --- Vertical lines --- | 62 | # --- Vertical lines --- | ... | ... |
| ... | @@ -348,6 +348,7 @@ | ... | @@ -348,6 +348,7 @@ |
| 348 | }, | 348 | }, |
| 349 | populateTableColumn(field, colIdx) { | 349 | populateTableColumn(field, colIdx) { |
| 350 | // Fill tableForm values from table cells for the given column index, skipping header (row_idx 0) | 350 | // Fill tableForm values from table cells for the given column index, skipping header (row_idx 0) |
| 351 | + console.log(`Populating table column for field "${field}" at colIdx:`, colIdx); | ||
| 351 | this.ensureTableFormSize(); | 352 | this.ensureTableFormSize(); |
| 352 | if (!Array.isArray(this.tableInfo)) return; | 353 | if (!Array.isArray(this.tableInfo)) return; |
| 353 | for (let r = 1; r < this.tableInfo.length; r++) { | 354 | for (let r = 1; r < this.tableInfo.length; r++) { |
| ... | @@ -365,6 +366,8 @@ | ... | @@ -365,6 +366,8 @@ |
| 365 | } else { | 366 | } else { |
| 366 | this.$set(this.tableForm[dataRowIndex], field, (value || '').toString()); | 367 | this.$set(this.tableForm[dataRowIndex], field, (value || '').toString()); |
| 367 | } | 368 | } |
| 369 | + | ||
| 370 | + console.log(`Row ${dataRowIndex} (${field}):`, value, cell); | ||
| 368 | } | 371 | } |
| 369 | }, | 372 | }, |
| 370 | applyTableMappingIfInTable(itemField, bbox) { | 373 | applyTableMappingIfInTable(itemField, bbox) { |
| ... | @@ -373,7 +376,6 @@ | ... | @@ -373,7 +376,6 @@ |
| 373 | // Restrict to table fields only | 376 | // Restrict to table fields only |
| 374 | if (!['product_name','product_code','quantity'].includes(itemField)) return false; | 377 | if (!['product_name','product_code','quantity'].includes(itemField)) return false; |
| 375 | const colIdx = this.getColumnIndexForBbox(bbox); | 378 | const colIdx = this.getColumnIndexForBbox(bbox); |
| 376 | - console.log(`Mapping field "${itemField}" to table column index:`, colIdx); | ||
| 377 | if (colIdx === null || colIdx === undefined) return false; | 379 | if (colIdx === null || colIdx === undefined) return false; |
| 378 | this.$set(this.tableColumnMapping, itemField, colIdx); | 380 | this.$set(this.tableColumnMapping, itemField, colIdx); |
| 379 | this.populateTableColumn(itemField, colIdx); | 381 | this.populateTableColumn(itemField, colIdx); | ... | ... |
-
Please register or sign in to post a comment