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
shuffling the elements of a list after converting to binary #8460
Comments
Can you provide full minimal example that reproduces the problem? |
Sure, When I run my code in pycharm: [Box(left=1413, top=654, width=66, height=38) after .exe: [Box(left=1154, top=753, width=66, height=38) I'm using the same code and the same image in this test |
That's not a reproducible example. We can't run it nor can we audit the source code for causes of indeterminism. |
If you cannot share a reproducible example, you'll need to audit the code that generates this list yourself, and determine why it is generated differently. |
Ok, full code: from botcity.core import DesktopBot class Bot(DesktopBot):
Open arena.png (first image) in scale 100% and leave this image in the foreground Create a "sources" folder an put "arena_150.png" (2nd image) inside Run code - it will produce a list in the order in which the elements are found on the screen after the .exe the list becomes random |
Hmm, I cannot reproduce this. On my test Windows system, the unfrozen and frozen variant return:
and
respectively. The sort order seems to be determined by the template-match score: Can you try inserting the following print in your local copy of [...]
# Order results before sending back
ordered = sorted(zip(matchx, matchy), key=lambda p: result[p[1]][p[0]], reverse=True)
for x, y in ordered:
print(f"Box: x={x}, y={y}, w={needle_width}, h={needle_height}, score={result[y][x]}") # Added
yield Box(x, y, needle_width, needle_height) Then rebuild the frozen application and run both unfrozen script and frozen application again. This should print the box info together with their scores; can you check if the scores are identical in the frozen and unfrozen version? In my case, they are:
|
Tkx for u assistante: It founds 6 objects (there are only 5, its "double-checking" one of them "+150 in arena.png") this "duplicate" object could be the cause of the order shuffle .py version: Box: x=1370, y=766, w=52, h=29, score=0.9999566078186035 |
Yeah, I can see the same duplicate in my output, but it happens in both .py and .exe version. |
On my .exe the changes made to botcity/core/cv2 find.py were not printed |
you got it right, in .py objects are shown in the order they appear on the screen, after .exe they are shown by best score |
Have you rebuilt the program (maybe with added
Hmm, but in your ".py version" output above, they were sorted by score, were they not? |
Yeh, u right. It was changed on botcity-core v0.4.0. Isnt a pyinstaller problem. I will search for a solution to list the objets in the order they appear, not by score |
the error is the divergence of versions between the .py and the generated .exe. When running the .py it uses version 0.3.0 of botcity core which lists the objects in the order they appear on the screen, when I generate the .exe it is using version 0.4.0 which lists the objects by score. That's why the changes I make in cv2 don't appear in the .exe (print(f"Box: x={x}, y={y}, w={needle_width}, h={needle_height}, score={result[y][x]}") # Added) |
So in other words, you are using a different python environment when running PyInstaller compared to when you are running/developing your .py program, and those two environments have different versions of botcity-core installed. |
I'm going to study the environments to try to correct this divergence between .py and .exe |
A strange problem after compiling with pyinstaller(auto-py-to-exe)
When Im running a code on Pycharm it finds the items in the stipulated order, but after compiling in .exe the order of the objects simply changes. Code follows:
Objects are correctly identified in pycharm, but after compiling in .exe the order changes completely.
plays =0
elements = self.find_all(label="arena_150", matching=0.7, waiting_time=3000, grayscale=True)
elements_list = list(elements)
number_of_elements = len(elements_list)
print('Energy available: ' + str(number_of_elements))
for _ in range(int(number_of_elements)):
x = elements_list[plays].left
y = elements_list[plays].top
self.mouse_move(x, y)
pyautogui.click()
plays +=1
time.sleep(3)
The text was updated successfully, but these errors were encountered: