-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathwechatqrcode.py
34 lines (29 loc) · 1.57 KB
/
wechatqrcode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# This file is part of OpenCV Zoo project.
# It is subject to the license terms in the LICENSE file found in the same directory.
#
# Copyright (C) 2021, Shenzhen Institute of Artificial Intelligence and Robotics for Society, all rights reserved.
# Third party copyrights are property of their respective owners.
import numpy as np
import cv2 as cv # needs to have cv.wechat_qrcode_WeChatQRCode, which requires compile from source with opencv_contrib/modules/wechat_qrcode
class WeChatQRCode:
def __init__(self, detect_prototxt_path, detect_model_path, sr_prototxt_path, sr_model_path, backendId=0, targetId=0):
self._model = cv.wechat_qrcode_WeChatQRCode(
detect_prototxt_path,
detect_model_path,
sr_prototxt_path,
sr_model_path
)
if backendId != 0 and backendId != 3:
raise NotImplementedError("Backend {} is not supported by cv.wechat_qrcode_WeChatQRCode()".format(backendId))
if targetId != 0:
raise NotImplementedError("Target {} is not supported by cv.wechat_qrcode_WeChatQRCode()")
@property
def name(self):
return self.__class__.__name__
def setBackendAndTarget(self, backendId, targetId):
if backendId != 0 and backendId != 3:
raise NotImplementedError("Backend {} is not supported by cv.wechat_qrcode_WeChatQRCode()".format(backendId))
if targetId != 0:
raise NotImplementedError("Target {} is not supported by cv.wechat_qrcode_WeChatQRCode()")
def infer(self, image):
return self._model.detectAndDecode(image)