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

Optimized searching for specified colors in image_recognition.py with cv::inRange() #106

Closed
wants to merge 3 commits into from

Conversation

ComictypX
Copy link
Contributor

Iterating through a Python array with two nested for-loops is not as fast as openCV/Numpy can do it vectorized.
Therefore, I replaced the two for-loops by the OpenCV function cv::inRange() and the python array given by PIL with a numpy one.

I tried my best measuring the improvements with measuring the execution time of call_appropriate_fishing_action():

Before: ~0,3534 seconds
After: ~0,09526 seconds
== 3,71 times faster (median average bit smaller: 3,62)

Just the color finding part without template matching is ~175 - 200 times faster.

Another Upside: we now have all the color matching pixels and could do some math on them to get the area, e.g. for optimized reeling (all white pixels in mask).

@Siterizer
Copy link
Owner

@ComictypX Wow, i did not know that cv2 has such a functions XD. Thank you very much, i will try to test it and give you an feedback

@Siterizer Siterizer added the enhancement New feature or request label Oct 13, 2021
@53m1k0l0n
Copy link

Tested this. Works really well and fast. Good work thank you.

@4rak007
Copy link

4rak007 commented Oct 14, 2021

Iterating through a Python array with two nested for-loops is not as fast as openCV/Numpy can do it vectorized. Therefore, I replaced the two for-loops by the OpenCV function cv::inRange() and the python array given by PIL with a numpy one.

I tried my best measuring the improvements with measuring the execution time of call_appropriate_fishing_action():

Before: ~0,3534 seconds After: ~0,09526 seconds == 3,71 times faster (median average bit smaller: 3,62)

Just the color finding part without template matching is ~175 - 200 times faster.

Another Upside: we now have all the color matching pixels and could do some math on them to get the area, e.g. for optimized reeling (all white pixels in mask).

Hello, Which file did u edit ? and if u could upload the file would be nice ty .

@53m1k0l0n
Copy link

Iterating through a Python array with two nested for-loops is not as fast as openCV/Numpy can do it vectorized. Therefore, I replaced the two for-loops by the OpenCV function cv::inRange() and the python array given by PIL with a numpy one.
I tried my best measuring the improvements with measuring the execution time of call_appropriate_fishing_action():
Before: ~0,3534 seconds After: ~0,09526 seconds == 3,71 times faster (median average bit smaller: 3,62)
Just the color finding part without template matching is ~175 - 200 times faster.
Another Upside: we now have all the color matching pixels and could do some math on them to get the area, e.g. for optimized reeling (all white pixels in mask).

Hello, Which file did u edit ? and if u could upload the file would be nice ty .

Look here: xD
Files

@raverecursion
Copy link

Can confirm, huge performance improvement. Today we eat oysters for dinner 😎

@Logonius
Copy link

It does not work for me, it throws it, but it catches nothing and does not pull the line. I don’t even know, the code was copied exactly.

@raverecursion
Copy link

raverecursion commented Oct 14, 2021

I don’t even know, the code was copied exactly.

The answer is probably in your comment

@Logonius
Copy link

Checked all 10 times, every line, no errors.
And he also leaves the game in the AFK, it is no longer possible to catch.

@raverecursion
Copy link

Checked all 10 times, every line, no errors. And he also leaves the game in the AFK, it is no longer possible to catch.

Copy and replace the code from here:

https://raw.githubusercontent.com/Siterizer/new-world-fishing-bot/646cc7f0dbcdac65e5312e12bfc4d9b84da60917/functionality/image_recognition.py

If it's not working, dunno

@Logonius
Copy link

Yes, I copied from here, there can be no mistakes, but he does not hook or pull anything. ¯_(ツ)_/¯

@ComictypX
Copy link
Contributor Author

@Logonius are you running your game still in 1080p? What is the bot logging to console? Only "[INFO] Cast fishing rod" ?

@SynaX1
Copy link

SynaX1 commented Oct 15, 2021

Yes, I copied from here, there can be no mistakes, but he does not hook or pull anything. ¯_(ツ)_/¯

yeah.. i do the same, with the same result, not pulling

@Mpaulo
Copy link

Mpaulo commented Oct 19, 2021

is working for me, i'll do more tests to see, but it really is better

@RobertMCortese
Copy link

@ComictypX Can you build and put up in your repository so I can test?

@ComictypX
Copy link
Contributor Author

@mitmiisnix
Copy link
Contributor

Works great!

@aim2kill
Copy link

from reeling at 1/2 when to 1/4 ish

@ITgamers
Copy link

ITgamers commented Oct 22, 2021

Is this something that has been added to your updated version or is it something that I need to update manually ? Thank you all for all you smart brains.. can't wait to learn. Python in a couple weeks for a college class 👍

@ComictypX
Copy link
Contributor Author

@ITgamers If you download it from my "BetterColorSearch" branch it will be included. Otherwise you should use the release in my repo or patch the image_recognition.py manually :)

@Siterizer
Copy link
Owner

@Siterizer Siterizer closed this Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Issues
Backlog
Development

Successfully merging this pull request may close these issues.

None yet