QReader
QReader는 Python에서 이미지 내의 어렵고 까다로운 QR 코드를 읽기 위한 강력하고 직관적인 솔루션입니다. YOLOv8 모델로 구동됩니다.
이 라이브러리는 두 가지 주요 구성 요소로 구성되어 있습니다.
이 QR 감지기에서 추출한 정보를 사용하여 QReader는 Pyzbar 위에 투명하게 다양한 이미지 전처리 기술을 적용하여 어려운 이미지의 디코딩 속도를 극대화합니다.
Install
On Linux:
On Mac OS X:
리소스가 매우 제한된 서버의 경우 CPU 버전의 PyTorch 를 설치하는걸 추천. pip install torch --no-cache-dir
API Reference
This is the main class of the library. Please, try to instantiate it just once to avoid loading the model every time you need to detect a QR code.
-
model_size
: str. The size of the model to use. It can be- 'n' (nano)
- 's' (small)
- 'm' (medium)
- 'l' (large)
- Larger models could be more accurate but slower.
- Recommended: 's' (#37). Default: 's'.
ROI 그리기
from qreader import QReader
import cv2
from numpy import ndarray
qreader = QReader()
ori = cv2.imread("test2.jpg")
image = cv2.cvtColor(ori, cv2.COLOR_BGR2RGB)
# decoded_text = qreader.detect_and_decode(image=image, return_detections=True)
# print(decoded_text)
detections = qreader.detect(image=image, is_bgr=True)
decoded_qrs = []
for detection in detections:
assert isinstance(detection, dict)
assert isinstance(detection['confidence'], float)
assert isinstance(detection['bbox_xyxy'], ndarray)
assert isinstance(detection['bbox_xyxyn'], ndarray)
assert isinstance(detection['cxcy'], tuple)
assert len(detection['cxcy']) == 2
assert isinstance(detection['cxcyn'], tuple)
assert len(detection['cxcyn']) == 2
assert isinstance(detection['wh'], tuple)
assert len(detection['wh']) == 2
assert isinstance(detection['whn'], tuple)
assert len(detection['whn']) == 2
assert isinstance(detection['polygon_xy'], ndarray)
assert isinstance(detection['polygon_xyn'], ndarray)
assert isinstance(detection['quad_xy'], ndarray)
assert isinstance(detection['quad_xyn'], ndarray)
assert isinstance(detection['padded_quad_xy'], ndarray)
assert isinstance(detection['padded_quad_xyn'], ndarray)
assert isinstance(detection['image_shape'], tuple)
assert len(detection['image_shape']) == 2
decoded_qr = qreader.decode(image=image, detection_result=detection)
assert isinstance(decoded_qr, str)
print(decoded_qr)
decoded_qrs.append(decoded_qr)
roi = detection['bbox_xyxy'].tolist()
p1 = int(roi[0]), int(roi[1])
p2 = int(roi[2]), int(roi[3])
ori = cv2.rectangle(ori, p1, p2, (0, 0, 255), 2, cv2.LINE_AA)
cv2.imwrite("result2.jpg", ori)
See also
- QRCode
- BarCode
- libzbar - QR Code scanner engine for QR+Emoji
- zbar-py - zbar package
- pyzbar - Read one-dimensional barcodes and QR codes from Python 2 and 3.
- QReader - Robust and Straight-Forward solution for reading difficult and tricky QR codes within images in Python. Supported by a YOLOv8 QR Segmentation model.
- cv2.QRCodeDetector - OpenCV 에 내장된 QR 코드 검출기.