Skip to content

Instantly share code, notes, and snippets.

@songwutk
Created August 27, 2021 08:54
Show Gist options
  • Save songwutk/ce27e4284df4bab5e2fac611ec916efd to your computer and use it in GitHub Desktop.
Save songwutk/ce27e4284df4bab5e2fac611ec916efd to your computer and use it in GitHub Desktop.
Python scan QR code and OCR
import sys, cv2 # opencv
from PIL import Image # Python Imaging Library
from pyzbar.pyzbar import decode # python zbarcode
fdemo=sys.argv[1] # get filename from command line
img=Image.open(fdemo) # open file
width, height=1800,400 # specify crop img size
x ,y = 50, 10 # start coordinate
area=(x,y,x+width,y+height)
cropped_img=img.crop(area) # crop
cropped_img.save('opt.jpg') # save to new file
data = decode(cropped_img) # QR code decoder
print(data) # print decode data from QR Code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment