AdriaGual / marvel-snap-bot

A computer vision bot made with OpenCV and ADB.
106 stars 27 forks source link

Error when opening Hand_cards.py #88

Closed paperc07 closed 1 year ago

paperc07 commented 1 year ago

File "C:\Users\paper\marvel-snap-bot\start.py", line 72, in clear_tmp.clear() File "C:\Users\paper\marvel-snap-bot\clear_tmp.py", line 9, in clear os.remove(f) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\paper\marvel-snap-bot\tmp\17.png'

paperc07 commented 1 year ago

Had to change the false to true in detect my cards and detect fields

paperc07 commented 1 year ago

Now this just happens and its like always saying not responding @AdriaGual can you point me in the right direction for opening the auto gui or gert cards or anything I dont see a gui or know how to do the screenshots

image
AdriaGual commented 1 year ago

Use the print scripts (print_fields, print_hand_cards), they do the same.

paperc07 commented 1 year ago

@AdriaGual When I hit print_hand_cards.py it closes out my start.py instance as soon as it hits end turn so how do I run them simultaneously because that's exactly what I want it was printing all the images in the tmp folder

And I tried to run start.py in git bash and then run the print cards or print fields in python and that's when I replicated the same error again so it's not liking something

File "C:\Users\paper\marvel-snap-bot\start.py", line 72, in clear_tmp.clear() File "C:\Users\paper\marvel-snap-bot\clear_tmp.py", line 9, in clear os.remove(f) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\paper\marvel-snap-bot\tmp\1.png'

whats even more strange is if once it crashes if you leave the print _hand_cards.py instance open it will still print images back to back to back in the tmp folder, but the bot isn't running anymore so it just sits there and prints pictures something definitely isn't right

Anyways let me know, I wanna fix this going to make another guide and then probably make an all in one mega guide

paperc07 commented 1 year ago

@AdriaGual ok im gonna try this a new way, since the bot automatically keeps taking screenshots and then deletes them chat gpt says I can add this

import os
import glob
import config

def clear():
    pass

to replace

import os
import glob
import config

def clear():
    files = glob.glob(config.tmp_path+'/*')
    for f in files:
        os.remove(f)

If I want to keep the files so I don't mind it running all night or day or even for a couple hours just to collect pretty much all the screenshots I need, so im gonna try it and report back. My question to you is if I have a picture like this do I just use the sniping tool make the copy

hand_cards_17

EDIT: Ok literally after 30 secs it seems to be working lmao I already even got some new ones that I am assuming I can take and use it also printed the fields automatically too here they all are BUTTTTTTTTT it's not going to be ideal cause im already up to 4gbs of files lmao

the_vault washington_dc weirdworld

Here is the new cards it got just after first round hand_cards_4

hand_cards_3 hand_cards_4

Looks like we even got some errors it didn't print sanctum santorium, I also noticed it's not closing out when I have the print fields.py open anymore since there both not using the delete tmp path anymore but it's also bot printing all the fields when this is open either EDIT: well probably cause there's no image in the fields folder hmm ok

next_2_turns next_turn

image

SO ALL I HAVE TO DO IS THIS??

image

Or is that too big and I have to use this one

Screenshot 2023-02-17 203603

I was also able to snag these

249 1060

Screenshot_20230217_090345 Screenshot_20230217_090432
paperc07 commented 1 year ago

God this is so annoying now it is just closing out no error or nothing since I added the new images and updated the field_list.py EDIT: I deleted the locations and removed names out of field_list.py and now it's working so what is it the images? there's no way to like debug it?

nidavellir flooding dark_dimension isle_of_silence ego vibranium_mines sanctum_sanctorum Screenshot_20230217_084231 bar_with_no_name elysium image

02/17/2023 09:35:36 PM Connection result: already connected to 127.0.0.1:5555

02/17/2023 09:35:37 PM [get_turn] Time elapsed: 0:00:00.026200 02/17/2023 09:35:38 PM [get_turn] Time elapsed: 0:00:00.031325 02/17/2023 09:35:38 PM [get_turn] Time elapsed: 0:00:00.026528 02/17/2023 09:35:39 PM [get_turn] Time elapsed: 0:00:00.025609 02/17/2023 09:35:40 PM [get_turn] Time elapsed: 0:00:00.027967 02/17/2023 09:35:41 PM [get_turn] Time elapsed: 0:00:00.027682 02/17/2023 09:35:42 PM [get_turn] Time elapsed: 0:00:00.025865 02/17/2023 09:35:43 PM [get_turn] Time elapsed: 0:00:00.025843 02/17/2023 09:35:44 PM [get_turn] Time elapsed: 0:00:00.034192 02/17/2023 09:35:45 PM [get_turn] Time elapsed: 0:00:00.027726 02/17/2023 09:35:46 PM [get_turn] Time elapsed: 0:00:00.027402 02/17/2023 09:35:47 PM [get_turn] Time elapsed: 0:00:00.026587 02/17/2023 09:35:48 PM [get_turn] Time elapsed: 0:00:00.029378 02/17/2023 09:35:49 PM [get_turn] Time elapsed: 0:00:00.021683 02/17/2023 09:35:50 PM [get_turn] Time elapsed: 0:00:00.021472 02/17/2023 09:35:51 PM [get_turn] Time elapsed: 0:00:00.022350 02/17/2023 09:35:52 PM [get_turn] Time elapsed: 0:00:00.022101 02/17/2023 09:35:53 PM --------------------------- 02/17/2023 09:35:53 PM Picture: 0 02/17/2023 09:35:53 PM Turn: 1 02/17/2023 09:35:53 PM [get_mana] Time elapsed: 0:00:00.004473 02/17/2023 09:35:53 PM Mana: 1 02/17/2023 09:35:55 PM [get_my_hand_cards] Time elapsed: 0:00:01.913079 02/17/2023 09:35:55 PM Hand_cards: 02/17/2023 09:35:55 PM antman 02/17/2023 09:35:55 PM armor 02/17/2023 09:35:55 PM bishop 02/17/2023 09:35:55 PM sunspot

paperc07 commented 1 year ago

@AdriaGual if you could help me out I would appreciate it I know im so close

AdriaGual commented 1 year ago

Here are some tips I would do: 1 - Playing a match and praying the changes will work is really time consuming and hard to debug. 2 - Instead, you should create a new script, that takes a screenshot and saves it (there's a function call take_screenshot xD) and with cv2, read the image (cv2.imread()) 3 - Then test your new fields (just call the detect_fields function and check if it's returning what it needs) 4 - Check also the names of the fields and the fields_list.py list

paperc07 commented 1 year ago

So a new script that does that wouldn't it be

from PIL import ImageGrab

# capture screenshot
screenshot = ImageGrab.grab()

# save screenshot as PNG file
screenshot.save('screenshot.png')

OR

global_utils.click([284, 46])
    # Take a screenhot and get its dimensions
    screenshot = global_utils.take_screenshot("tmp\\"+str(counter)+".png")
    screenshot_dimensions = screenshot.shape

THIS LOOKS MORE LEGIT BUT DOESNT THIS BOT NOT USE IMAGE GRAB

import numpy as np
import cv2
from PIL import ImageGrab
import global_utils

# click on a specific point on the screen
global_utils.click([284, 46])

# take screenshot and save as PNG file
screenshot = ImageGrab.grab()
screenshot.save('screenshot.png')

# read screenshot image with OpenCV
screenshot_cv2 = cv2.imread('screenshot.png')

# display screenshot image with OpenCV
cv2.imshow('Screenshot', screenshot_cv2)
cv2.waitKey(0)
cv2.destroyAllWindows()

Also its so hard to test the fields cause there's what 121 of them so I have to hope one of them comes up and it recognizes it also when I added the 10 above in this discussion it didn't work I added the images from the print_fields.py and used snipping tool to get just the names and then I added them in the field_list.py and it would just close out the start.py I believe cause it didn't recognize them.

I also noticed a bunch of times it doesn't even get the active field, and idk if its cause of the screenshot or what, cause lets say it doesn't read The Space Throne, well if I can identify that I don't mind taking a picture and snipping a screen shot or two or three and throwing it in the images\fields folder and then retesting it or when I see that location again. I will literally sit and watch this bot for hours, but it gets frustrating when I think im making changes and helping and then it either doesn't work or the bot just closes

EDIT: like look at this perfect example the bot says there's only one active field when clearly there's 3 and there all out but it only reads the space throne. Is it due to screenshot image????

image image
paperc07 commented 1 year ago

Here are some tips I would do: 1 - Playing a match and praying the changes will work is really time consuming and hard to debug. 2 - Instead, you should create a new script, that takes a screenshot and saves it (there's a function call take_screenshot xD) and with cv2, read the image (cv2.imread()) 3 - Then test your new fields (just call the detect_fields function and check if it's returning what it needs) 4 - Check also the names of the fields and the fields_list.py list

im gonna mess wiith that today and tomorrow

im also wondering if it would be easier and less chance of suspension having two dummy accounts and battle moding them