Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
osie
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
nexedi
osie
Commits
56f0b922
Commit
56f0b922
authored
Oct 05, 2020
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add first OCR implementation which can track countours in image.
parent
97a4bb0b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
+73
-0
eggs/osie_plc/osie_ocr.py
eggs/osie_plc/osie_ocr.py
+73
-0
No files found.
eggs/osie_plc/osie_ocr.py
0 → 100644
View file @
56f0b922
import
cv2
import
numpy
as
np
def
nothing
(
x
):
# any operation
pass
cap
=
cv2
.
VideoCapture
(
1
)
cv2
.
namedWindow
(
"Trackbars"
)
cv2
.
createTrackbar
(
"L-H"
,
"Trackbars"
,
0
,
180
,
nothing
)
cv2
.
createTrackbar
(
"L-S"
,
"Trackbars"
,
66
,
255
,
nothing
)
cv2
.
createTrackbar
(
"L-V"
,
"Trackbars"
,
134
,
255
,
nothing
)
cv2
.
createTrackbar
(
"U-H"
,
"Trackbars"
,
180
,
180
,
nothing
)
cv2
.
createTrackbar
(
"U-S"
,
"Trackbars"
,
255
,
255
,
nothing
)
cv2
.
createTrackbar
(
"U-V"
,
"Trackbars"
,
243
,
255
,
nothing
)
font
=
cv2
.
FONT_HERSHEY_COMPLEX
while
True
:
_
,
frame
=
cap
.
read
()
hsv
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2HSV
)
l_h
=
cv2
.
getTrackbarPos
(
"L-H"
,
"Trackbars"
)
l_s
=
cv2
.
getTrackbarPos
(
"L-S"
,
"Trackbars"
)
l_v
=
cv2
.
getTrackbarPos
(
"L-V"
,
"Trackbars"
)
u_h
=
cv2
.
getTrackbarPos
(
"U-H"
,
"Trackbars"
)
u_s
=
cv2
.
getTrackbarPos
(
"U-S"
,
"Trackbars"
)
u_v
=
cv2
.
getTrackbarPos
(
"U-V"
,
"Trackbars"
)
lower_red
=
np
.
array
([
l_h
,
l_s
,
l_v
])
upper_red
=
np
.
array
([
u_h
,
u_s
,
u_v
])
mask
=
cv2
.
inRange
(
hsv
,
lower_red
,
upper_red
)
kernel
=
np
.
ones
((
5
,
5
),
np
.
uint8
)
mask
=
cv2
.
erode
(
mask
,
kernel
)
# Contours detection
if
int
(
cv2
.
__version__
[
0
])
>
3
:
# Opencv 4.x.x
contours
,
_
=
cv2
.
findContours
(
mask
,
cv2
.
RETR_TREE
,
cv2
.
CHAIN_APPROX_SIMPLE
)
else
:
# Opencv 3.x.x
_
,
contours
,
_
=
cv2
.
findContours
(
mask
,
cv2
.
RETR_TREE
,
cv2
.
CHAIN_APPROX_SIMPLE
)
for
cnt
in
contours
:
area
=
cv2
.
contourArea
(
cnt
)
approx
=
cv2
.
approxPolyDP
(
cnt
,
0.02
*
cv2
.
arcLength
(
cnt
,
True
),
True
)
x
=
approx
.
ravel
()[
0
]
y
=
approx
.
ravel
()[
1
]
if
area
>
400
:
cv2
.
drawContours
(
frame
,
[
approx
],
0
,
(
0
,
0
,
0
),
5
)
if
len
(
approx
)
==
3
:
cv2
.
putText
(
frame
,
"Triangle"
,
(
x
,
y
),
font
,
1
,
(
0
,
0
,
0
))
elif
len
(
approx
)
==
4
:
cv2
.
putText
(
frame
,
"Rectangle"
,
(
x
,
y
),
font
,
1
,
(
0
,
0
,
0
))
elif
10
<
len
(
approx
)
<
20
:
cv2
.
putText
(
frame
,
"Circle"
,
(
x
,
y
),
font
,
1
,
(
0
,
0
,
0
))
cv2
.
imshow
(
"Frame"
,
frame
)
cv2
.
imshow
(
"Mask"
,
mask
)
key
=
cv2
.
waitKey
(
1
)
if
key
==
27
:
break
cap
.
release
()
cv2
.
destroyAllWindows
()
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