foolyc

qr code segmentaion

有群友问到灰度二维码的分割,我简单用cv2实现了下,记录水文一篇。

先放效果图,原始二维码vs边缘提取图:

img

img

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import cv2
import numpy as np
img = cv2.imread("qr.jpg", flags=cv2.CV_LOAD_IMAGE_GRAYSCALE)
# cv2.imshow("qr", img)
print img.shape
dest = 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/.