Last active
October 27, 2016 04:58
-
-
Save bakketun/1f8db75a783d16e3c638 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import zbar | |
import Image | |
import StringIO | |
from PySide import QtCore, QtGui | |
from PySide.QtCore import QBuffer | |
app = QtGui.QApplication(sys.argv) | |
buffer = QBuffer() | |
qimage = QtGui.QPixmap.grabWindow(QtGui.QApplication.desktop().winId()).save(buffer, "png") | |
png = buffer.data().data() | |
del(buffer) | |
# create a reader | |
scanner = zbar.ImageScanner() | |
# configure the reader | |
scanner.parse_config('enable') | |
# obtain image data | |
pil = Image.open(StringIO.StringIO(png)).convert('L') | |
del(png) | |
width, height = pil.size | |
raw = pil.tostring() | |
# wrap image data | |
image = zbar.Image(width, height, 'Y800', raw) | |
# scan the image for barcodes | |
scanner.scan(image) | |
# extract results | |
for symbol in image: | |
# do something useful with results | |
print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data | |
# clean up | |
del(image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment