OCR -tesseract-ocr

Yeseul Han·2024년 8월 14일
0
# 우분투 서버
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev
sudo apt-get install tesseract-ocr-kor tesseract-ocr-eng
find /usr/share -name "kor.traineddata"
export TESSDATA_PREFIX=/usr/share/tesseract-ocr/5/tessdata/
echo 'export TESSDATA_PREFIX=/usr/share/tesseract-ocr/5/tessdata/' >> ~/.bashrc
source ~/.bashrc

simple ocr app

import streamlit as st
from PIL import Image
import pytesseract

# Tesseract 실행 파일 경로 설정 (일반적으로 Ubuntu에서는 /usr/bin/tesseract에 설치됩니다)
pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'

# Streamlit 애플리케이션
st.title("이미지 OCR 추출기")

# 이미지 업로드
uploaded_file = st.file_uploader("이미지를 업로드 하세요", type=["jpg", "png", "jpeg"])

if uploaded_file is not None:
    # 이미지를 열고 화면에 표시
    image = Image.open(uploaded_file)
    st.image(image, caption='업로드한 이미지', use_column_width=True)

    # 버튼을 눌러 OCR 수행
    if st.button("텍스트 추출"):
        # OCR 수행
        text = pytesseract.image_to_string(image, lang='kor')  # 언어를 'kor'로 설정
        # 추출된 텍스트 출력
        st.write("추출된 텍스트:")
        st.text_area("OCR 결과", text, height=200)

결과 상당히 정확하지 않음. 인식률 5%~10% 정도??
내가 세팅을 잘 못한걸지도

profile
코딩 잘하고 싶다

0개의 댓글