Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #16 from TheAwiteb/replace-zbar
Browse files Browse the repository at this point in the history
Replace `zbar` with `opencv`
  • Loading branch information
TheAwiteb authored Apr 6, 2022
2 parents 4f52d0f + c0cdcb2 commit 8ab5401
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
1 change: 0 additions & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get install zbar-tools
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
- name: Test with pytest
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
## Requirements

* [Python](https://Python.org/) >= 3.8
* [zbar-tools](http://zbar.sourceforge.net/)

## Installation

Expand Down
29 changes: 27 additions & 2 deletions fatoora/fatoora.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import json
from typing import Union, Optional
from PIL import Image
from pyzbar.pyzbar import decode
import cv2
from pydantic import validate_arguments
import validators
from datetime import datetime
Expand All @@ -21,6 +21,31 @@
iso8601_zulu_format = "%Y-%m-%dT%H:%M:%SZ"


def _decode(filename: str) -> str:
"""Returns the date of qrcode
Args:
filename (str): qrcode you want to get the date of it
Exception:
Exception: Invalid qrcode
Returns:
str: date of qrcodee
"""
image = cv2.imread(filename)
# initialize the cv2 QRCode detector
detector = cv2.QRCodeDetector()
# detect and decode
data, vertices_array, _ = detector.detectAndDecode(image)
# if there is a QR code
# print the data
if vertices_array is not None:
return data
else:
raise Exception("Invalid qrcode")


def is_valid_iso8601_zulu_format(string_date: str) -> bool:
"""Returns True if the string valid ISO 8601 Zulu format
Expand Down Expand Up @@ -96,7 +121,7 @@ def read_qrcode(cls, filename: str, dct: bool = False) -> Union[str, dict]:
Returns:
Union[str, dict]: content of qr code
"""
data = decode(Image.open(filename))[0].data.decode()
data = _decode(filename)

if dct:
return cls.base2dict(data)
Expand Down
2 changes: 1 addition & 1 deletion fatoora/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__all__ = "version", "version_info"

version = "2.1.3"
version = "3.0.0"


def version_info() -> str:
Expand Down
11 changes: 6 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
decorator==5.1.0
Pillow==9.0.1
pydantic==1.8.2
pyzbar==0.1.8
decorator==5.1.1
numpy==1.21.5
opencv-python==4.5.5.64
Pillow==9.1.0
pydantic==1.9.0
qrcode==7.3.1
six==1.16.0
typing-extensions==3.10.0.2
typing_extensions==4.1.1
uttlv==0.6.0
validators==0.18.2

0 comments on commit 8ab5401

Please sign in to comment.