Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
Bio Metric Based Smart Electronic Identification System For Citizens
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-306
Bio Metric Based Smart Electronic Identification System For Citizens
Commits
fbc106f3
Commit
fbc106f3
authored
Oct 10, 2022
by
Avindika H.M.U
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scanner Code
parent
d6ed54d3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
new.py
new.py
+67
-0
No files found.
new.py
0 → 100644
View file @
fbc106f3
import
os.path
#from textwrap import wrap
#from xxlimited import new
from
cv2
import
perspectiveTransform
import
numpy
as
np
import
cv2
import
json
from
flask
import
Flask
,
request
,
Response
import
uuid
def
find_sheet_end_point
(
window
):
window
=
window
.
reshape
((
4
,
2
))
new_window
=
np
.
zeros
((
4
,
2
),
dtype
=
np
.
float32
)
add
=
window
.
sum
(
axis
=
1
)
diff
=
np
.
diff
(
window
,
axis
=
1
)
new_window
[
0
]
=
window
[
np
.
argmin
(
add
)]
new_window
[
1
]
=
window
[
np
.
argmin
(
diff
)]
new_window
[
2
]
=
window
[
np
.
argmin
(
add
)]
new_window
[
3
]
=
window
[
np
.
argmin
(
diff
)]
return
new_window
def
ImageToText
(
image
):
#path to save after the processed
path_file
=
(
'static/
%
s.jpg'
%
uuid
.
uuid4
()
.
hex
)
image
=
cv2
.
resize
(
image
,(
1300
,
800
))
original
=
image
#convert image to grey
gray_image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_BGR2GRAY
)
blurred_image
=
cv2
.
GaussianBlur
(
gray_image
,(
5
,
5
),
0
)
edged_image
=
cv2
.
Canny
(
blurred_image
,
28
,
48
)
contours
,
hierarchy
=
cv2
.
findContours
(
edged_image
,
cv2
.
RETR_LIST
,
cv2
.
CHAIN_APPROX_SIMPLE
)
contours
=
sorted
(
contours
,
key
=
cv2
.
contourArea
,
reverse
=
True
)
for
contour
in
contours
:
contour_perimeter
=
cv2
.
arcLength
(
contour
,
True
)
contour_approximation
=
cv2
.
approxPolyDP
(
contour
,
0.02
*
contour_perimeter
,
True
)
if
len
(
contour_approximation
)
==
4
:
selected_window
=
contour_approximation
break
contour_approximation
=
find_sheet_end_point
(
selected_window
)
points
=
np
.
float32
([[
0
,
0
],[
800
,
0
],[
800
,
800
],[
0
,
800
]])
perspective
=
cv2
.
getPerspectiveTransform
(
contour_approximation
,
points
)
wrap
=
cv2
.
warpPerspective
(
original
,
perspective
,(
800
,
800
))
cv2
.
imwrite
(
path_file
,
gray_image
)
return
json
.
dumps
(
path_file
)
app
=
Flask
(
__name__
)
@
app
.
route
(
"/api/upload"
,
methods
=
[
'POST'
])
def
upload
():
img
=
cv2
.
imdecode
(
np
.
fromstring
(
request
.
files
[
'image'
]
.
read
(),
np
.
uint8
),
cv2
.
IMREAD_UNCHANGED
)
img_proccessed
=
ImageToText
(
img
)
return
Response
(
response
=
img_proccessed
,
status
=
200
,
mimetype
=
"application/json"
)
app
.
run
(
host
=
"0.0.0.0"
,
port
=
5000
)
if
__name__
==
"_main_"
:
app
.
run
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment