Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-235
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
2021-235
2021-235
Commits
5e02390c
Commit
5e02390c
authored
Nov 26, 2021
by
Dinuja Theeraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
0884ac1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
img_to_text.py
img_to_text.py
+92
-0
No files found.
img_to_text.py
0 → 100644
View file @
5e02390c
#Importing libraries
from
cv2
import
cv2
import
numpy
as
np
import
os
import
matplotlib.pyplot
as
plt
from
watchdog.observers
import
Observer
from
watchdog.events
import
LoggingEventHandler
import
time
import
read_images
as
ri
# Declaring Paths
current_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
)))
img_path
=
current_path
+
"
\\
Images"
test_images_path
=
current_path
+
"
\\
Test_images"
per
=
25
scale
=
0.5
roi
=
[[(
285
,
230
),
(
2000
,
364
),
'text'
,
'Validation'
],
#(x,y) (width+x,height+y)
[(
1150
,
660
),
(
2400
,
780
),
'text'
,
'Name'
],
[(
2654
,
660
),
(
3400
,
730
),
'text'
,
'RegNo'
],
[(
784
,
960
),
(
2350
,
1040
),
'text'
,
'Course'
],
[(
2412
,
1350
),
(
3250
,
1450
),
'text'
,
'Amount'
]]
imageT
=
cv2
.
imread
(
"template.jpg"
)
h
,
w
,
c
=
imageT
.
shape
orb
=
cv2
.
ORB_create
(
1000
)
# unique key points/elements to image, decsripters are the representation of these key points that will be easier for
#the computer to understand
kp1
,
des1
=
orb
.
detectAndCompute
(
imageT
,
None
)
Image_list
=
os
.
listdir
(
test_images_path
)
def
on_created
(
event
):
print
(
event
.
src_path
)
img
=
cv2
.
imread
(
event
.
src_path
)
fileName
=
(
event
.
src_path
)
.
split
(
"
\\
"
)
fileName1
=
fileName
[
len
(
fileName
)
-
1
]
fileName
=
fileName1
.
split
(
"."
)
h
,
w
,
c
=
img
.
shape
kp2
,
des2
=
orb
.
detectAndCompute
(
img
,
None
)
bf
=
cv2
.
BFMatcher
(
cv2
.
NORM_HAMMING
)
matches
=
bf
.
match
(
des2
,
des1
)
matches
.
sort
(
key
=
lambda
x
:
x
.
distance
)
good
=
matches
[:
int
(
len
(
matches
)
*
(
per
/
100
))]
imgMatch
=
cv2
.
drawMatches
(
img
,
kp2
,
imageT
,
kp1
,
good
[:
100
],
None
,
flags
=
2
)
srcPoints
=
np
.
float32
([
kp2
[
m
.
queryIdx
]
.
pt
for
m
in
good
])
.
reshape
(
-
1
,
1
,
2
)
dstPoints
=
np
.
float32
([
kp1
[
m
.
trainIdx
]
.
pt
for
m
in
good
])
.
reshape
(
-
1
,
1
,
2
)
M
,
_
=
cv2
.
findHomography
(
srcPoints
,
dstPoints
,
cv2
.
RANSAC
,
5.0
)
imgScan
=
cv2
.
warpPerspective
(
img
,
M
,(
w
,
h
))
imgShow
=
imgScan
.
copy
()
imgMask
=
np
.
zeros_like
(
imgShow
)
Data_list
=
[]
i
=
0
for
x
,
r
in
enumerate
(
roi
):
i
+=
1
cv2
.
rectangle
(
imgMask
,
((
r
[
0
][
0
]),
r
[
0
][
1
]),
((
r
[
1
][
0
]),
r
[
1
][
1
]),
(
0
,
255
,
0
),
cv2
.
FILLED
)
imgShow
=
cv2
.
addWeighted
(
imgShow
,
0.99
,
imgMask
,
0.1
,
0
)
imgCrop
=
imgScan
[
r
[
0
][
1
]:
r
[
1
][
1
],
r
[
0
][
0
]:
r
[
1
][
0
]]
# cv2.imshow(str(x), imgCrop)
plt
.
imsave
(
'Outputs
\\
'
+
fileName
[
0
]
+
str
(
i
)
+
'.png'
,
imgCrop
)
ri
.
main
()
# img = cv2.resize(img, (w//4,h//4), None, scale, scale)
# imgShow = cv2.resize(imgShow, (w//4,h//4), None, scale, scale)
# cv2.imshow(y+"2", imgShow)
# cv2.waitKey(0)
if
__name__
==
"__main__"
:
# An agent has been created here to monitor video-data folder. when a new video is uploaded to that folder,
# it automatically starts processing that video.
event_handler
=
LoggingEventHandler
()
event_handler
.
on_created
=
on_created
observer
=
Observer
()
observer
.
schedule
(
event_handler
,
img_path
,
recursive
=
True
)
observer
.
start
()
try
:
print
(
"Started"
)
while
True
:
time
.
sleep
(
1
)
finally
:
observer
.
stop
()
observer
.
join
()
\ 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