Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
M
materials
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
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
osak
materials
Commits
33e79afc
Commit
33e79afc
authored
Oct 03, 2012
by
Björn Guth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added qr reader to repository
parent
d0af37b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
139 additions
and
0 deletions
+139
-0
qr_reader/qrreader.py
qr_reader/qrreader.py
+139
-0
No files found.
qr_reader/qrreader.py
0 → 100755
View file @
33e79afc
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import
sys
,
os
,
re
,
subprocess
,
httplib
from
threading
import
Timer
import
pygtk
,
gtk
,
gobject
import
pygst
pygst
.
require
(
"0.10"
)
import
gst
import
zbar
,
Image
,
string
,
urllib
class
GTK_Main
:
def
__init__
(
self
):
self
.
clean
()
window
=
gtk
.
Window
(
gtk
.
WINDOW_TOPLEVEL
)
window
.
set_title
(
"Webcam-Viewer"
)
window
.
set_default_size
(
500
,
400
)
window
.
connect
(
"destroy"
,
gtk
.
main_quit
,
"WM destroy"
)
vbox
=
gtk
.
VBox
()
window
.
add
(
vbox
)
self
.
movie_window
=
gtk
.
DrawingArea
()
vbox
.
add
(
self
.
movie_window
)
hbox
=
gtk
.
HBox
()
vbox
.
pack_start
(
hbox
,
False
)
hbox
.
set_border_width
(
10
)
hbox
.
pack_start
(
gtk
.
Label
())
self
.
button
=
gtk
.
Button
(
"Quit"
)
self
.
button
.
connect
(
"clicked"
,
self
.
exit
)
hbox
.
pack_start
(
self
.
button
,
False
)
self
.
button_restart
=
gtk
.
Button
(
'Restart'
)
self
.
button_restart
.
connect
(
'clicked'
,
self
.
restart
)
hbox
.
pack_start
(
self
.
button_restart
,
True
)
hbox
.
add
(
gtk
.
Label
())
window
.
show_all
()
# Set up the gstreamer pipepile
self
.
player
=
gst
.
parse_launch
(
"""v4l2src !
tee name=t ! queue ! autovideosink t.
! queue ! videorate ! video/x-raw-yuv, width=800, height=600, framerate=1/1
! jpegenc ! multifilesink location=snapshot-%03d.jpg"""
)
bus
=
self
.
player
.
get_bus
()
bus
.
add_signal_watch
()
bus
.
enable_sync_message_emission
()
bus
.
connect
(
'message'
,
self
.
on_message
)
bus
.
connect
(
'sync-message::element'
,
self
.
on_sync_message
)
self
.
player
.
set_state
(
gst
.
STATE_PLAYING
)
self
.
scan
()
def
exit
(
self
,
widget
,
data
=
None
):
self
.
t
.
cancel
()
self
.
clean
()
gtk
.
main_quit
()
def
restart
(
self
,
widget
,
data
=
None
):
self
.
clean
()
self
.
scan
()
def
on_message
(
self
,
bus
,
message
):
t
=
message
.
type
if
t
==
gst
.
MESSAGE_EOS
:
self
.
player
.
set_state
(
gst
.
STATE_NULL
)
self
.
button
.
set_label
(
"Start"
)
elif
t
==
gst
.
MESSAGE_ERROR
:
err
,
debug
=
message
.
parse_error
()
print
"Error: %s"
%
err
,
debug
self
.
player
.
set_state
(
gst
.
STATE_NULL
)
self
.
button
.
set_label
(
"Start"
)
def
on_sync_message
(
self
,
bus
,
message
):
if
message
.
structure
is
None
:
return
message_name
=
message
.
structure
.
get_name
()
if
message_name
==
'prepare-xwindow-id'
:
# Assign the viewport
imagesink
=
message
.
src
imagesink
.
set_property
(
'force-aspect-ratio'
,
True
)
imagesink
.
set_xwindow_id
(
self
.
movie_window
.
window
.
xid
)
def
scan
(
self
):
files
=
os
.
listdir
(
"."
)
files
=
filter
(
lambda
x
:
re
.
search
(
'^snapshot-[0-9]*.jpg$'
,
x
)
!=
None
,
files
)
for
f
in
files
:
print
(
"processing image: "
+
str
(
f
))
self
.
process_qr
(
str
(
f
))
os
.
remove
(
f
)
self
.
t
=
Timer
(
3.0
,
self
.
scan
)
self
.
t
.
start
()
def
process_qr
(
self
,
picture
):
scanner
=
zbar
.
ImageScanner
()
scanner
.
parse_config
(
'enable'
)
pil
=
Image
.
open
(
picture
).
convert
(
'L'
)
width
,
height
=
pil
.
size
raw
=
pil
.
tostring
()
image
=
zbar
.
Image
(
width
,
height
,
'Y800'
,
raw
)
scanner
.
scan
(
image
)
no_qr
=
True
result
=
''
for
symbol
in
image
:
url
=
symbol
.
data
print
(
url
)
if
url
.
find
(
'http://fsmpi.rwth-aachen.de/lip/view/'
)
>=
0
:
os
.
system
(
'firefox -new-tab '
+
url
)
else
:
self
.
invalid_code
()
no_qr
=
False
del
(
image
)
if
no_qr
:
print
(
'
\033
[1;31mno QR code found
\033
[1;m'
)
else
:
exit
()
def
stop
(
self
):
exit
()
def
clean
(
self
):
files
=
os
.
listdir
(
"."
)
files
=
filter
(
lambda
x
:
re
.
search
(
'^snapshot-[0-9]*.jpg$'
,
x
)
!=
None
,
files
)
for
f
in
files
:
os
.
remove
(
f
)
def
invalid_code
(
self
):
print
(
'
\033
[1;41m _ _ _ _ _ ___ _ _ ___ ___ ___ ___ ___ ___ ___
\033
[1;m'
)
print
(
'
\033
[1;41m | || \| || | |/ - \| | | || \ / \| - | / _|/ \| \| __|
\033
[1;m'
)
print
(
'
\033
[1;41m | || \ || | || | || |_ | || | | | | || \ | (_ | | || | || __|
\033
[1;m'
)
print
(
'
\033
[1;41m |_||_\__| \_/ |_|_||___||_||___/ \__\_|_|\_\ \___|\___/|___/|___|
\033
[1;m'
)
print
(
'
\033
[1;41m
\033
[1;m'
)
g
=
GTK_Main
()
gtk
.
gdk
.
threads_init
()
gtk
.
main
()
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