QR-code, Barcode를 open-cv로 읽어보겠습니다.
import cv2
import pyzbar.pyzbar as pyzbar
font = cv2.FONT_ITALIC
def read_frame(frame):
try:
barcodes = pyzbar.decode(frame)
for barcode in barcodes:
x, y, w, h = barcode.rect
barcode_info = barcode.data.decode('utf-8')
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.putText(frame, barcode_info, (x, y-20), font, 0.5, (255, 0, 0), 4)
except Exception as e:
print(e)
return frame
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if ret:
frame = read_frame(frame)
cv2.imshow('Barcode', frame)
if cv2.waitKey(10) & 0xFF == ord('q'):
cap.release()
cv2.destroyAllWindows()
Mac OSX 필수
pip install pyzbar X
brew install bar
arch -arm64 brew install zbar
conda install pyzbar
import Error 발생 시 설치 된 파일을 복사 후 옮겨줘야합니다.
cp /opt/homebrew/Cellar/zbar/0.23.90_1/lib/pkgconfig/zbar.pc /Users/{1}/miniforge3/envs/{2}/lib/pkgconfig
cp /opt/homebrew/Cellar/zbar/0.23.90_1/lib/libzbar.0.dylib /Users/{1}/miniforge3/envs/{2}/lib/
cd /Users/{1}/miniforge3/envs/{2}/lib
ln -s libzbar.0.dylib libzbar.dylib
import Clear 🥹