이미지에 들어간 문자 인식하여 번역
1. 이미지에서 텍스트 추출: 먼저 이미지에서 텍스트를 추출해야 합니다. 이를 위해 Tesseract OCR 라이브러리를 사용할 수 있습니다.
2. 언어 감지: 추출된 텍스트의 언어를 감지하는 단계에서는 langdetect나 langid 같은 언어 감지 라이브러리를 사용할 수 있습니다.
pip install pytesseract Pillow langdetect
from PIL import Image
import pytesseract
from langdetect import detect
# 이미지에서 텍스트 추출
def extract_text_from_image(image_path):
# 이미지에서 텍스트를 추출
img = Image.open(image_path)
text = pytesseract.image_to_string(img)
return text
# 추출한 텍스트의 언어 감지
def detect_language(text):
try:
# 언어 감지
language = detect(text)
return language
except:
return "언어 감지 실패"
# 이미지 경로 지정
image_path = 'your_image_path.png'
# 이미지에서 텍스트 추출
extracted_text = extract_text_from_image(image_path)
print(f"추출된 텍스트: {extracted_text}")
# 텍스트의 언어 감지
detected_language = detect_language(extracted_text)
print(f"감지된 언어: {detected_language}")
# 감지된 언어 출력 (ko: 한국어, en: 영어, zh-cn: 중국어 간체, zh-tw: 중국어 번체)
if detected_language == 'ko':
print("한글로 표기된 텍스트입니다.")
elif detected_language == 'en':
print("영어로 표기된 텍스트입니다.")
elif detected_language in ['zh-cn', 'zh-tw']:
print("중국어로 표기된 텍스트입니다.")
else:
print("알 수 없는 언어입니다.")
에러
tesseract is not installed or it's not in your PATH. See README file for more information.
brew install tesseract
맥북에서 설치방법


