'''QR 코드 검출
입력 영상에서 QR코드를 인식하려면 먼저 QR코드 세 모서리에 포함된 흑백 정사각형 패턴을 찾아 QR 코드
전체 영역의 위치를 알아야함
검출된 QR코드를 정사각형 형태로 투시변환
QR코드 내부에 포함된 흑백 격자무늬를 해석하여 문자열을 추출해야함
일련의 연산은 매우 복잡하고, 정교한 영상 처리를 필요로 함
'''
import cv2
import webbrowser
import numpy as np
path =('')
inputImage = cv2.imread(path + 'QRcode.png')
qrDecoder = cv2.QRCodeDetector()
# QR코드를 찾고 디코드해줍니다.
data, bbox, _ = qrDecoder.detectAndDecode(inputImage) # qr code 찾고 번역
if len(data) > 0:
print('Decoded Data: {}'.format(data))
if bbox is not None:
nrOfPoints = len(bbox)
bbox = bbox.astype(np.int)
cv2.line(inputImage, tuple(bbox[0][0]), tuple(bbox[0][1]), (0,0,255), 3)
cv2.line(inputImage, tuple(bbox[0][1]), tuple(bbox[0][2]), (0,0,255), 3)
cv2.line(inputImage, tuple(bbox[0][2]), tuple(bbox[0][3]), (0,0,255), 3)
cv2.line(inputImage, tuple(bbox[0][3]), tuple(bbox[0][0]), (0,0,255), 3)
# display
cv2.imshow('QR Code', inputImage)
cv2.waitKey()
cv2.destroyAllWindows()
cv2.waitKey(1)
# web browser
webbrowser.open(data) # data가 사이트면 웹브라우저를 이용해서 띄운다
else:
print('QR Code not detected')
'OpenCV' 카테고리의 다른 글
OpenCV- 얼굴 라이브 인식 (0) | 2022.11.22 |
---|---|
OpenCV - OBJECT DETECTION (0) | 2022.11.21 |
OpenCV - 디스크립터(Descriptor) (0) | 2022.11.16 |
OpenCV - CircleGrid (0) | 2022.11.15 |
OpenCV - 체스보드 패턴 코너점 검출 (0) | 2022.11.15 |