| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
根据Opencv的描述,OpenCV3.4.4以上版本支持二维码检测和识别!
Opencv在对象检测模块中 QRCodeDetector 有两个相关API分别实现二维码检测与二维码解析。
points = QRCodeDetector.detect(img)
其中:
straight_qrcode = QRCodeDetector.decode(img, points)
其中:
points,straight_qrcode = QRCodeDetector.detectAndDecode(img)
其中:
整体检测识别的代码如下:
import cv2
import numpy as np
# 读取二维码
src = cv2.imread("qrcode.png")
gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
# 设置检测器
qrcoder = cv2.QRCodeDetector()
# 检测识别二维码
codeinfo, points, straight_qrcode = qrcoder.detectAndDecode(gray)
result = np.copy(src)
cv2.drawContours(result, [np.int32(points)], 0, (0, 0, 255), 2)
# 输出识别二维码的信息
print("qrcode information is : \n%s"% codeinfo)
# 显示图片
cv2.imshow("result", result)
cv2.imshow("qrcode roi", np.uint8(straight_qrcode))
cv2.waitKey(0)
cv2.destroyAllWindows()输出:
qrcode information is : Hello, this is Jimmy, thanks for your little star~
原图:
检测:
ROI图:
| Back | FazBrowse Home | New Git URL |