qr code segmentaion 发表于 2017-04-08 | 分类于 program | qr code segmentaion 有群友问到灰度二维码的分割,我简单用cv2实现了下,记录水文一篇。 先放效果图,原始二维码vs边缘提取图: 代码如下: 1234567891011121314151617import cv2import numpy as npimg = cv2.imread("qr.jpg", flags=cv2.CV_LOAD_IMAGE_GRAYSCALE)# cv2.imshow("qr", img)print img.shapedest = np.zeros([img.shape[0], img.shape[1]])ret, binary = cv2.threshold(img, 70, 255,cv2.THRESH_BINARY)cv2.imshow("binary", binary)contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)cv2.drawContours(dest, contours, -1, 255, 5)cv2.imwrite("qrseg.jpg",dest)# cv2.imshow("img", dest)# cv2.waitKey(0) 本文由foolyc创作和发表,采用BY-NC-SA国际许可协议进行许可 转载请注明作者及出处,本文作者为foolyc 本文标题为qr code segmentaion 本文链接为http://foolyc.com//2017/04/08/qr-code-segmentaion/.