Skip to content
조회 수 75754 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

한우경매낙찰 유튜브 영상의 이미지에서 특정 문자 가져와서 저장하기

 


from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
import time
from PIL import Image #이미지정확도필요없을때
from PIL import ImageGrab #이미지정확도필요할 때
import pyautogui
 
import easyocr
def extract_numbers_from_image(image):
    reader = easyocr.Reader(['en'])  # 언어 설정을 필요에 따라 조정하세요 (예: 'ko' 또는 'en')
    results = reader.readtext(image)
   
    extracted_text = ""
    for (bbox, text, prob) in results:
        extracted_text += text + " "
   
    return extracted_text.strip()
 
# 이후 코드는 이전과 동일합니다.    
 
# Chrome 드라이버 경로를 설정합니다.
driver_path = 'e:/python/py_code/chromedriver.exe'  # 여기서 '/path/to/chromedriver'를 실제 드라이버 경로로 변경하세요.
 
# ChromeDriver의 Service 객체를 생성합니다.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')  # 필요한 경우, 브라우저를 화면에 표시하지 않고 실행할 수 있습니다.
chrome_options.add_argument('--start-maximized')
 
# 자동 플레이 활성화
prefs = {"profile.default_content_setting_values.autoplay": 1}
chrome_options.add_experimental_option("prefs", prefs)

# 크롬 서비스 객체를 생성합니다.
chrome_service = webdriver.chrome.service.Service(executable_path=driver_path)
 
# 크롬 웹 드라이버를 시작합니다.
driver = webdriver.Chrome(service=chrome_service)

# 동적 페이지의 URL을 엽니다.
url = 'https://www.youtube.com/watch?v=AZHK3AFE6Hg'
driver.get(url)
 
# 페이지가 로드될 때까지 잠시 대기합니다. (필요에 따라 대기 시간을 조정하세요)
driver.implicitly_wait(10)

# 찾고자 하는 이미지 파일 경로 설정
tar_nack = r'C:\Users\Administrator\chuck\3.png'  # '낙찰금액' 대상 이미지 파일 경로로 변경하세요.
tar_youc = r'C:\Users\Administrator\chuck\4.png' # '유찰되었습니다' 한글 사용시 인식안됨.

extracted_text_list1 = [] #번호저장
extracted_text_list2 = [] #금액저장
 
def s_img(tar_img,per):
    # 대상 이미지 로드
 
    screenshot = ImageGrab.grab()
    target_image = Image.open(tar_img)
 
    # 화면 캡처 및 전체 화면 이미지 가져오기
    screenshot = pyautogui.screenshot()
 
    # 이미지 매칭 수행
    location = pyautogui.locateOnScreen(tar_img, confidence=per)
    print('정보 출력', location)
 
    if location:
        # 이미지 일치 위치 출력
        print("이미지 일치 위치:", location)
       
        # 이미지 일치 위치를 변수에 할당
        left, top, width, height = location
        print("left:", left)
        print("top:", top)
        print("width:", width)
        print("height:", height)

        # 화면 캡처
        screenshot1 = capture_screen(x = 125, y = 370, width = 210, height = 110)
       
        # 이미지 보정
        screenshot1 = screenshot1.convert('L')  # 그레이스케일로 변환
        screenshot1 = screenshot1.filter(ImageFilter.SHARPEN)  # 선명도 향상
        screenshot1 = ImageEnhance.Contrast(screenshot1).enhance(2.0)  # 대비 향상 (필요에 따라 조절)
        screenshot1.save('img1.png')
        #screenshot1.show()  # 캡처된 이미지 표시 (테스트용)
       
        screenshot2 = capture_screen(x = 125, y = 610, width = 210, height = 90)
        screenshot2 = screenshot2.convert('L')  # 그레이스케일로 변환
        screenshot2 = screenshot2.filter(ImageFilter.SHARPEN)  # 선명도 향상
        screenshot2 = ImageEnhance.Contrast(screenshot2).enhance(2.0)  # 대비 향상 (필요에 따라 조절)
        screenshot2.save('img2.png')
        #screenshot2.show()  # 캡처된 이미지 표시 (테스트용)
 
        time.sleep(2)
       
        extracted_text = extract_numbers_from_image('img1.png')
        extracted_text_list1.append(extracted_text)
        print("easyOCR로 추출된 숫자:", extracted_text)
        print(extracted_text_list1)
               
        extracted_text = extract_numbers_from_image('img2.png')
        extracted_text_list2.append(extracted_text)
        print("easyOCR로 추출된 숫자:", extracted_text)        
        print(extracted_text_list2)
       

        #위의 코드는 특정 화면 좌표 (x, y)에서 시작하여 너비 width와 높이 height의 영역을 화면 캡처한 후, 추출된 이미지에서 텍스트를 추출합니다. 이 코드를 실행하면 해당 좌표에서 숫자를 추출할 수 있을 것입니다.
        #참고로, pytesseract를 사용하면 이미지의 텍스트 추출 정확도는 이미지 품질 및 글꼴에 따라 다를 수 있습니다. 때로는 이미지 전처리를 통해 정확성을 높일 수도 있습니다.
        time.sleep(1)





 
from PIL import ImageGrab, Image
import pytesseract
from PIL import Image, ImageEnhance, ImageFilter, ImageDraw




 
# 화면 캡처 함수
def capture_screen(x, y, width, height):
    screenshot = ImageGrab.grab(bbox=(x, y, x + width, y + height))
    return screenshot
 
       
while True:
    s_img(tar_nack,per=0.9)
    s_img(tar_youc,per=0.9)








 
   
print('타임슬립10초')
time.sleep(60)

# 웹 드라이버를 종료합니다.
driver.quit()

 

로그인 후 댓글쓰기가 가능합니다.

?

  1. 17
    Jun 2011
    15:27

    호스트 / 서버운영자가 가볼만한 사이트

    Category컴퓨터잡담 Views5423
    Read More
  2. 30
    Jun 2009
    15:36

    현재 쿠키,세션 값 전부 보기

    Category컴퓨터잡담 Views32612
    Read More
  3. 17
    Sep 2012
    08:21

    현재 Excel 파일 이름을 셀에 삽입

    CategoryExcel Views24559
    Read More
  4. 08
    Jan 2012
    13:58

    해외속도테스트 사이트 speedtest.net

    Category컴퓨터잡담 Views5843
    Read More
  5. 25
    Jan 2011
    08:37

    함수와변수

    CategoryVisual C++ Views17750
    Read More
  6. 14
    Sep 2023
    22:34

    한우경매낙찰 유튜브 영상의 이미지에서 특정 문자 가져와서 저장하기

    Category파이썬 Views75754
    Read More
  7. 21
    Sep 2009
    10:49

    한글프로그램 메뉴-모양-세로쓰기

    Category컴퓨터잡담 Views15752
    Read More
  8. 08
    Jan 2021
    16:06

    한글입력이 안될때(how to hangul ...)

    Category컴퓨터잡담 Views2839
    Read More
  9. 14
    Dec 2011
    18:10

    한글입력이 안될때 의심해봐야 할 파일 imm32.dll

    Category컴퓨터잡담 Views5995
    Read More
  10. 22
    Jan 2013
    12:07

    한글(hwp) msvcr71.dll 오류 해결방법

    Category컴퓨터잡담 Views6699
    Read More
  11. 17
    Mar 2010
    13:35

    한글 HEX 코드표

    Category컴퓨터잡담 Views29525
    Read More
  12. 19
    Jun 2012
    14:55

    한 셀에 있는 특정 문자의 갯수 구하기

    CategoryExcel Views11244
    Read More
  13. 14
    Mar 2012
    06:04

    하드 디스크 드라이브(HDD) 숨기기

    Category컴퓨터잡담 Views7330
    Read More
  14. 19
    Mar 2012
    09:48

    하드 공유폴더 해제하기

    Category컴퓨터잡담 Views8182
    Read More
  15. 21
    Sep 2017
    18:26

    핑테스트(PINGINFOVIEW)와 TCPVIEW

    Category컴퓨터잡담 Views2326
    Read More
  16. 01
    Sep 2015
    08:59

    핑테스트 프로그램

    Category컴퓨터잡담 Views1043
    Read More
  17. 17
    Oct 2012
    18:01

    프린터 내용 파일로 저장하기 doPDF

    Category컴퓨터잡담 Views4706
    Read More
  18. 16
    Mar 2011
    18:19

    프록시 서버 만들기

    Category컴퓨터잡담 Views14936
    Read More
  19. 21
    Jan 2010
    10:38

    프로세스 숨기고 복구하기

    Category컴퓨터잡담 Views7199
    Read More
  20. 07
    Feb 2011
    08:38

    프로세스

    Category프로세스 Views312175
    Read More
Board Pagination Prev 1 2 3 4 5 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소