Skip to content

Commit

Permalink
fix bug: decode qrcode when file is not a image
Browse files Browse the repository at this point in the history
  • Loading branch information
zfb132 committed May 5, 2022
1 parent 6eb1688 commit eb58b0b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pyqt5_qr_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ def scan(root, name, cut_path, operation):
npfile = fromfile(img_name, dtype=uint8)
if npfile.size == 0:
logging.error(f"{img_name} 是空文件!")
return [4, op_status]
return [4, op_status, qrcode]
img = imdecode(npfile, IMREAD_UNCHANGED)
if img is None:
logging.warning(f"{img_name} 不是一个图片!")
return [4, op_status]
return [4, op_status, qrcode]
# if img.empty():
if img.size == 0 :
logging.error(f"{img_name} 不是一个合法图片!")
return [3, None]
return [3, op_status, qrcode]
try:
res, points = detector.detectAndDecode(img)
except Exception as e:
print(repr(e))
return [None, None]
return [None, op_status, qrcode]
if res == None or len(res) < 1:
logging.info(f"{img_name} 不包含二维码")
img_status = 2
Expand Down

0 comments on commit eb58b0b

Please sign in to comment.