思路
1)二值化
2)膨胀与腐蚀
3)找到所有矩形并进行筛选(筛选过程可以加入上一篇文章)
4)对所有满足条件的矩形进行二维码检测
import cv2
import copy
import numpy as np
import pyzbar.pyzbar as pyzbar
def prethreatment(img0):
#read img and copy
img = copy.deepcopy(img0)
##cv2.imshow('img',img)
#make img into gray
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
##cv2.imshow('gray',gray)
#threshold
ret,thre=cv2.threshold(gray,100,255,cv2.THRESH_BINARY)
##cv2.imshow('thre',thre)
#erode
kernel = np.ones((5,5),np.uint8)
erosion = cv2.erode(thre,kernel)
erosion = cv2.erode(erosion,kernel)
#cv2.imshow('erosion',erosion)
#findContours
imgc,contours,hier=cv2.findContours(erosion,
cv2.RET