Skip to content

Instantly share code, notes, and snippets.

@mohankumargupta
Last active July 25, 2018 15:02
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohankumargupta/243aeb6787123cc17f1c10338bd4a82f to your computer and use it in GitHub Desktop.
Save mohankumargupta/243aeb6787123cc17f1c10338bd4a82f to your computer and use it in GitHub Desktop.
#installed zbar with difficulty, main steps taken from https://github.com/NaturalHistoryMuseum/gouda
#what worked for me (executed from anaconda command prompt)
#conda update --all
#conda update --all
#python -m pip install --upgrade pip
#python <Anaconda dir>\Scripts\pywin32_postinstall.py -install
#python -m pip install pathlib
#python -m pip install numpy
#python -m pip install Pillow
#conda install -c menpo opencv
#python -m pip install https://github.com/NaturalHistoryMuseum/zbar-python-patched/releases/download/v0.10/zbar-0.10-cp27-none-win32.whl
import cv2
import zbar
from PIL import Image
cv2.namedWindow("#iothack15")
cap = cv2.VideoCapture(0)
scanner = zbar.ImageScanner()
scanner.parse_config('enable')
# Capture frames from the camera
while True:
ret, output = cap.read()
if not ret:
continue
gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY, dstCn=0)
pil = Image.fromarray(gray)
width, height = pil.size
raw = pil.tobytes()
image = zbar.Image(width, height, 'Y800', raw)
scanner.scan(image)
for symbol in image:
print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
cv2.imshow("#iothack15", output)
# clear stream for next frame
#rawCapture.truncate(0)
# Wait for the magic key
keypress = cv2.waitKey(1) & 0xFF
if keypress == ord('q'):
break
# When everything is done, release the capture
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment