Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Satini_pvduc
/
ocrpdf
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
tien_nemo
2025-09-09 15:05:37 +0700
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
25306c5f78c47b68f8f23ccbff5f55075a09e3ff
25306c5f
1 parent
fec2e1e8
demo3 push cho anh Dung
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
5 deletions
app/Http/Controllers/OcrController.php
app/Services/OCR/table_detector.py
resources/views/ocr/index.blade.php
app/Http/Controllers/OcrController.php
View file @
25306c5
...
...
@@ -89,8 +89,8 @@ class OcrController extends Controller
$templateName
=
$request
->
get
(
'template_name'
,
''
);
// Giả sử file OCR JSON & ảnh nằm trong storage/app/public/image/
$jsonPath
=
public_path
(
"image/
nemo_new_1757393338
_with_table.json"
);
$imgPath
=
(
"image/
nemo_new_1757393338
.jpg"
);
$jsonPath
=
public_path
(
"image/
Iwasaki_1757404869
_with_table.json"
);
$imgPath
=
(
"image/
Iwasaki_1757404869
.jpg"
);
if
(
!
file_exists
(
$jsonPath
))
{
return
response
()
->
json
([
'error'
=>
'File OCR JSON không tìm thấy'
],
404
);
...
...
app/Services/OCR/table_detector.py
View file @
25306c5
...
...
@@ -2,7 +2,7 @@ import cv2
import
numpy
as
np
import
os
def
filter_horizontal_lines
(
lines_h
,
img_width
,
min_h_len_ratio
=
0.
8
,
tol_y
=
10
):
def
filter_horizontal_lines
(
lines_h
,
img_width
,
min_h_len_ratio
=
0.
7
,
tol_y
=
10
):
if
lines_h
is
None
:
return
[],
[]
...
...
@@ -56,7 +56,7 @@ def detect_tables(image_path, gap_threshold=50):
lines_h
=
cv2
.
HoughLinesP
(
edges
,
1
,
np
.
pi
/
180
,
threshold
=
120
,
minLineLength
=
int
(
img
.
shape
[
1
]
*
0.6
),
maxLineGap
=
20
)
img_height
,
img_width
=
img
.
shape
[:
2
]
ys
,
line_segments
=
filter_horizontal_lines
(
lines_h
,
img_width
,
min_h_len_ratio
=
0.
8
,
tol_y
=
10
)
ys
,
line_segments
=
filter_horizontal_lines
(
lines_h
,
img_width
,
min_h_len_ratio
=
0.
7
,
tol_y
=
10
)
total_rows
=
max
(
0
,
len
(
ys
)
-
1
)
# --- Vertical lines ---
...
...
resources/views/ocr/index.blade.php
View file @
25306c5
...
...
@@ -348,6 +348,7 @@
},
populateTableColumn
(
field
,
colIdx
)
{
// Fill tableForm values from table cells for the given column index, skipping header (row_idx 0)
console
.
log
(
`Populating table column for field "
${
field
}
" at colIdx:`
,
colIdx
);
this
.
ensureTableFormSize
();
if
(
!
Array
.
isArray
(
this
.
tableInfo
))
return
;
for
(
let
r
=
1
;
r
<
this
.
tableInfo
.
length
;
r
++
)
{
...
...
@@ -365,6 +366,8 @@
}
else
{
this
.
$set
(
this
.
tableForm
[
dataRowIndex
],
field
,
(
value
||
''
).
toString
());
}
console
.
log
(
`Row
${
dataRowIndex
}
(
${
field
}
):`
,
value
,
cell
);
}
},
applyTableMappingIfInTable
(
itemField
,
bbox
)
{
...
...
@@ -373,7 +376,6 @@
// Restrict to table fields only
if
(
!
[
'product_name'
,
'product_code'
,
'quantity'
].
includes
(
itemField
))
return
false
;
const
colIdx
=
this
.
getColumnIndexForBbox
(
bbox
);
console
.
log
(
`Mapping field "
${
itemField
}
" to table column index:`
,
colIdx
);
if
(
colIdx
===
null
||
colIdx
===
undefined
)
return
false
;
this
.
$set
(
this
.
tableColumnMapping
,
itemField
,
colIdx
);
this
.
populateTableColumn
(
itemField
,
colIdx
);
...
...
Please
register
or
sign in
to post a comment