48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import time
|
|
import pytesseract
|
|
from PIL import ImageGrab
|
|
|
|
# Tesseract 실행 파일 경로 설정
|
|
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
|
|
|
|
|
|
def find_text_in_screen(max_duration=20, interval=0.5):
|
|
# 검색할 텍스트 설정
|
|
target_texts = ["실시간", "영역을"]
|
|
|
|
# Chrome 창에서 스크린샷을 찍을 위치 (대략적인 좌표)
|
|
base_x, base_y = 400, 140
|
|
width, height = 440, 200
|
|
end_time = time.time() + max_duration
|
|
|
|
i = 1
|
|
while time.time() < end_time:
|
|
# 스크린샷 찍기
|
|
screenshot = ImageGrab.grab(bbox=(base_x, base_y, base_x + width, base_y + height))
|
|
|
|
# 스크린샷 저장
|
|
print(f"감지중...")
|
|
|
|
# OCR 적용
|
|
text = pytesseract.image_to_string(screenshot, lang='kor', config='--psm 6')
|
|
|
|
# 타겟 텍스트 확인
|
|
for target_text in target_texts:
|
|
if target_text in text:
|
|
print(f"찾은 텍스트: '{target_text}'")
|
|
return target_text # 텍스트를 찾으면 반환
|
|
|
|
i =+ 1
|
|
# 지정된 간격만큼 대기
|
|
time.sleep(interval)
|
|
|
|
print("텍스트를 찾지 못했습니다.")
|
|
return None
|
|
|
|
# 사용 예제
|
|
found_text = find_text_in_screen()
|
|
if found_text:
|
|
print(f"검색 성공: {found_text}")
|
|
else:
|
|
print("검색 실패")
|