一、介绍几个函数
1、把区域里的二维码传换成 RGB, 并把它转换成 pil 里面的图像
pil= Image.fromarray(frame).convert('L')#转换成 L 模式, 即灰度模式
width, height = pil.size
raw = pil.tobytes()
2、调用 zbar 二维码识别库函数
zarimage = zbar.Image(width, height, 'Y800', raw)#把图像装换成数据
scanner.scan(zarimage)#扫描器进行扫描
二、示例代码
首先需要输入以下代码,进行安装zbar
库
sudo apt-get install python-zbar
import cv2
import numpy as np
import zbar
from PIL import Image
# create a reader
scanner = zbar.ImageScanner()
# configure the reader
scanner.parse_config('enable')
font=cv2.FONT_HERSHEY_SIMPLEX
camera=cv2.VideoCapture(0)
while(Tr