FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythoncode-tutorials/general/barcode-reader/barcode_reader.py at master · erreci/pythoncode-tutorials · GitHub
erreci
/
pythoncode-tutorials
Public
forked from
x4nth055/pythoncode-tutorials
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythoncode-tutorials
/
general
/
barcode-reader
/
barcode_reader.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (37 loc) · 1.42 KB
Breadcrumbs
pythoncode-tutorials
/
general
/
barcode-reader
/
barcode_reader.py
Copy path
File metadata and controls
45 lines (37 loc) · 1.42 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from
pyzbar
import
pyzbar
import
cv2
def
decode
(
image
):
# decodes all barcodes from an image
decoded_objects
=
pyzbar
.
decode
(
image
)
for
obj
in
decoded_objects
:
# draw the barcode
print
(
"detected barcode:"
,
obj
)
image
=
draw_barcode
(
obj
,
image
)
# print barcode type & data
print
(
"Type:"
,
obj
.
type
)
print
(
"Data:"
,
obj
.
data
)
print
()
return
image
def
draw_barcode
(
decoded
,
image
):
# n_points = len(decoded.polygon)
# for i in range(n_points):
# image = cv2.line(image, decoded.polygon[i], decoded.polygon[(i+1) % n_points], color=(0, 255, 0), thickness=5)
# uncomment above and comment below if you want to draw a polygon and not a rectangle
image
=
cv2
.
rectangle
(
image
, (
decoded
.
rect
.
left
,
decoded
.
rect
.
top
),
(
decoded
.
rect
.
left
+
decoded
.
rect
.
width
,
decoded
.
rect
.
top
+
decoded
.
rect
.
height
),
color
=
(
0
,
255
,
0
),
thickness
=
5
)
return
image
if
__name__
==
"__main__"
:
from
glob
import
glob
barcodes
=
glob
(
"barcode*.png"
)
for
barcode_file
in
barcodes
:
# load the image to opencv
img
=
cv2
.
imread
(
barcode_file
)
# decode detected barcodes & get the image
# that is drawn
img
=
decode
(
img
)
# show the image
cv2
.
imshow
(
"img"
,
img
)
# cv2.imwrite("barcode_detected.png", img)
cv2
.
waitKey
(
0
)
Back
|
FazBrowse Home
|
New Git URL