공유 블로그

because file is missing, has improper permissions, or is an unsupported or invalid format

한글 경로가 있으면 이런 오류가 나타납니다..

 


해결방법은 numpy -> opencv -> pyautogui로 해결하면 됩니다.

 

 

Tree구조는 이렇습니다.

 

 

import os
import pyautogui
import numpy as np

import cv2

path=os.path.dirname(os.path.realpath(__file__))
img = os.path.join(path,'이미지','img_002.png')

n = np.fromfile(img, np.uint8)
img = cv2.imdecode(n, cv2.IMREAD_COLOR)

i=pyautogui.locateOnScreen(img)
print(i)

 

출처 : https://jangjy.tistory.com/337

 

 

--- 참고 ---

더보기

pyautogui 이미지 인식관련해서는 차피 opencv로 구성되어 있기 때문에 오류가 나면 pyautogui로 검색 하는 것보다 opencv로 검색하는것이 잘 나옵니다..

 

추가로 함수로 함 만들어 봤습니다.

import os
import cv2
import numpy as np
import pyautogui


# pyautogui 이미지 한글이름 함수
def imread(path,filename, flags=cv2.IMREAD_COLOR, dtype=np.uint8):
    try:
        here_IMG = os.path.join(path,filename)
        n = np.fromfile(here_IMG, dtype)
        img = cv2.imdecode(n, flags)
        i=pyautogui.locateOnScreen(img)
        
        return i
    
    except Exception as e:
        print(e)
        
        return None
    

#테스트
path=os.path.dirname(os.path.realpath(__file__))
path = os.path.join(path,'이미지')

print(imread(path,'img_002.png'))

 

 

 

 

공유하기

facebook twitter kakaoTalk naver band kakaostory Copy URL