Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to read AutoSave.jpg error because missing #15

Open
Dschingan opened this issue Apr 23, 2024 · 11 comments
Open

Failed to read AutoSave.jpg error because missing #15

Dschingan opened this issue Apr 23, 2024 · 11 comments
Assignees

Comments

@Dschingan
Copy link

Dschingan commented Apr 23, 2024

Ok the TCMLobbyBBQ is about to begin!

Make sure that TCM is running, and that your mouse is actively 'clicked' on the monitor where TCM is running.

I'll give you 7 seconds to do that, then I'm starting automatically!

[ WARN:[email protected]] global loadsave.cpp:248 cv::findDecoder imread_('pics/autosave.jpg'): can't open/read file: check file path/integrity
Traceback (most recent call last):
  File "C:\Users\trcen\Desktop\tcm.py", line 154, in <module>
    pyautogui.locateOnScreen('pics/autosave.jpg', confidence=0.8)
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\__init__.py", line 172, in wrapper
    return wrappedFunction(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\__init__.py", line 210, in locateOnScreen
    return pyscreeze.locateOnScreen(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 405, in locateOnScreen
    retVal = locate(image, screenshotIm, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 383, in locate
    points = tuple(locateAll(needleImage, haystackImage, **kwargs))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 231, in _locateAll_opencv
    needleImage = _load_cv2(needleImage, grayscale)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 193, in _load_cv2
    raise IOError(
OSError: Failed to read pics/autosave.jpg because file is missing, has improper permissions, or is an unsupported or invalid format

Did I miss something? (I'm playing on XBOX PC)

@7MinSec
Copy link
Owner

7MinSec commented Apr 23, 2024

Hello,

I was able to recreate your error by running tcm.py without having the pics subfolder in the same directory.

I'm wondering - did you download the whole project zip file and then extract to a folder on your hard drive? When you run tcm.py it assumes that all of the picture files it references are in the pics subfolder beneath it. Like this:

image

@7MinSec 7MinSec self-assigned this Apr 23, 2024
@Dschingan
Copy link
Author

Dschingan commented Apr 23, 2024

Sorry I didn't see the pics folder in the project. I have very little knowledge about Python, thanks for the quick answer and this project.

@7MinSec
Copy link
Owner

7MinSec commented Apr 23, 2024

No problem at all! Please let me know if that solves it for you. I love that people are using the script and want to make sure the install/use instructions are clear, etc.

@Dschingan
Copy link
Author

Dschingan commented Apr 23, 2024

The 'Auto Save' box was NOT found, which means you must be on another screen within TCM.
Moving on!

Traceback (most recent call last):
  File "C:\Users\trcen\Desktop\TCMLobbyAuto\tcm.py", line 175, in <module>
    pyautogui.locateOnScreen('pics/thetexascsm.jpg', confidence=0.8)
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\__init__.py", line 172, in wrapper
    return wrappedFunction(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\__init__.py", line 210, in locateOnScreen
    return pyscreeze.locateOnScreen(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 405, in locateOnScreen
    retVal = locate(image, screenshotIm, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 383, in locate
    points = tuple(locateAll(needleImage, haystackImage, **kwargs))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 241, in _locateAll_opencv
    raise ValueError('needle dimension(s) exceed the haystack image or region dimensions')
ValueError: needle dimension(s) exceed the haystack image or region dimensions

It didn't work again for some reason it doesn't see the word AUTO. I clicked on the game screen several times. By the way, I'm using ReShade, if that has any effect.

@7MinSec
Copy link
Owner

7MinSec commented Apr 23, 2024

Hrmm...that's odd.

I'm curious, what happens if you don't have the game running at all and you just run the script (and choose whether you want to run as family or victim)? Does the script fire correctly like this?

image

@Dschingan
Copy link
Author

Dschingan commented Apr 23, 2024

The 'Auto Save' box was NOT found, which means you must be on another screen within TCM.
Moving on!

Traceback (most recent call last):
  File "C:\Users\trcen\Desktop\TCMLobbyBBQ-main\tcm.py", line 175, in <module>
    pyautogui.locateOnScreen('pics/thetexascsm.jpg', confidence=0.8)
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\__init__.py", line 172, in wrapper
    return wrappedFunction(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyautogui\__init__.py", line 210, in locateOnScreen
    return pyscreeze.locateOnScreen(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 405, in locateOnScreen
    retVal = locate(image, screenshotIm, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 383, in locate
    points = tuple(locateAll(needleImage, haystackImage, **kwargs))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\trcen\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyscreeze\__init__.py", line 241, in _locateAll_opencv
    raise ValueError('needle dimension(s) exceed the haystack image or region dimensions')
ValueError: needle dimension(s) exceed the haystack image or region dimensions

Same error as above

@7MinSec
Copy link
Owner

7MinSec commented Apr 23, 2024

Interesting. I'm going to do some homework on this. Reading through articles like this one it seems that maybe my code needs to make considerations for the resolution of the monitor the game is running on, otherwise it can have a tough time matching the pictures to what's happening on TCM.

Do you know what resolution you're running at? I developed all this on a monitor running at 2560x1440.

@Dschingan
Copy link
Author

Dschingan commented Apr 23, 2024

I have a 1920x1080 monitor. I tried Full Screen instead of Windowed Full Screen, no luck. Python codes always end in failure for me, anyway good luck!

@7MinSec
Copy link
Owner

7MinSec commented Apr 23, 2024

Ok sorry let me back up to a previous question. If you don't have TCM running and you fire off tcm.py and choose victim or family, the script still bombs out with that error you shared about needle dimension(s) exceed the haystack image or region dimensions?

@Dschingan
Copy link
Author

Dschingan commented Apr 24, 2024

Yes I just ran tcm.py without running the game, I chose Victim:

You chose: victim! (Maybe pick Danny or Virginia - they're P2W FTW, amirite? LOL)

Ok the TCMLobbyBBQ is about to begin!

Make sure that TCM is running, and that your mouse is actively 'clicked' on the monitor where TCM is running.

I'll give you 7 seconds to do that, then I'm starting automatically!

The 'Auto Save' box was NOT found, which means you must be on another screen within TCM.
Moving on!

After the AutoSave error a lot of text appears and the last line has the error needle dimension(s) exceed the haystack image or region dimensions

@7MinSec
Copy link
Owner

7MinSec commented Apr 24, 2024

Thank you for the update. I resized my monitor to 1920x1080 and had the same problem you did! So I read up and found this article which includes a response from the author of pyautogui (which does the screen captures):

I'm the creator of PyAutoGUI. The problem you have isn't with the screen resolution, but the screen scaling. Your program will work fine on monitors at different resolutions. But at high resolutions, the text and buttons of your programs become too small and so Windows and macOS fix this with "screen scaling", which can increase the size of UI elements like text and buttons by 150% or 200%. If you have multiple monitors, each monitor can have it's own screen scaling setting; for example one monitor at 100% and another at 150%.

If you take a screenshot while a monitor is at, for example, 100% and then try to use it on a monitor that is scaled at 200%, the image won't match because the screenshot is literally half the width and length of what it would have been on the 200% monitor
So far, there is no work around for this. Resizing the screenshot might not work because there could be subtle differences and the screenshot mechanism currently needs a pixel-perfect match. You just need to retake the screenshots on the monitor with the different screen scaling setting._

Based on this, it looks like I'd have to have a set of reference screenshots for every resolution in order to make this work for everybody. That might be a ton of work considering there are so many resolution combinations. I also read this article which hints that maybe I could incorporate some code to do resizing on the fly. And YouTube videos like this one hint at some pyautogui tweaks to help it find images of various resolutions.

Long story short: I'll work on this and get back to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants