We Are Going To Discuss About image path is valid but pyautogui.locateOnScreen is unable to read image file?. So lets Start this Python Article.
image path is valid but pyautogui.locateOnScreen is unable to read image file?
- How to solve image path is valid but pyautogui.locateOnScreen is unable to read image file?
The path is relative, but not relative to the file where imread() is used, it is relative from the folder where the py command was run
#Directories . ╚ test ╠ visual1.py ╠ visual2.py ╚ data ╠ 1.jpg ╚ 2.jpg
#./test/visual1.py import cv2 img_rgb = cv2.imread('data/2.jpg') template = cv2.imread('data/1.jpg')
#./test/visual2.py import cv2 img_rgb = cv2.imread('test/data/2.jpg') template = cv2.imread('test/data/1.jpg')
if you are in the main project folder and run:py test/visual1.py
you will get error, but if you run:py test/visual2.py
everything will be fine. - image path is valid but pyautogui.locateOnScreen is unable to read image file?
The path is relative, but not relative to the file where imread() is used, it is relative from the folder where the py command was run
#Directories . ╚ test ╠ visual1.py ╠ visual2.py ╚ data ╠ 1.jpg ╚ 2.jpg
#./test/visual1.py import cv2 img_rgb = cv2.imread('data/2.jpg') template = cv2.imread('data/1.jpg')
#./test/visual2.py import cv2 img_rgb = cv2.imread('test/data/2.jpg') template = cv2.imread('test/data/1.jpg')
if you are in the main project folder and run:py test/visual1.py
you will get error, but if you run:py test/visual2.py
everything will be fine.
Solution 1
The path is relative, but not relative to the file where imread() is used, it is relative from the folder where the py command was run
#Directories
.
╚ test
╠ visual1.py
╠ visual2.py
╚ data
╠ 1.jpg
╚ 2.jpg
#./test/visual1.py
import cv2
img_rgb = cv2.imread('data/2.jpg')
template = cv2.imread('data/1.jpg')
#./test/visual2.py
import cv2
img_rgb = cv2.imread('test/data/2.jpg')
template = cv2.imread('test/data/1.jpg')
if you are in the main project folder and run:
py test/visual1.py
you will get error, but if you run:
py test/visual2.py
everything will be fine.
Original Author Pipe Soto Of This Content
Solution 2
I cannot comment yet then please bear it. Try to change the name of file . I think in the converting of file name for library some characters can not be recognized. Do that comment the result and I will edit my post.
Original Author S.A.H Of This Content
Solution 3
As the error states did you try changing the permissions? Or try putting ./
infront of the folder
eg:
pos = pyautogui.locateOnScreen("./Images/新增.png")
Original Author MrHola21 Of This Content
Solution 4
Please try to install opencv-python library.
This is the line to install
pip install opencv-python
.
I tried to change the name off arquive too, sometimes is confuse for the system.
I was trying it and now is working for me.
Original Author Raphael Moral Piazera Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.