Searchng libs

07/07/2017 18:44 ssamko#1
Hello guys I am working on new searching libraries for C# bots.
Right now I have pixel-imagesearch which can find an image in cca 5-7ms on the other hand there are more advanced emgu OpenCV libs(for C#) which make better matches(with min. side effects)...but my fastest search there was 390ms.

Can be this speed somehow improved ? Or it is unavoidable price for such good matching results ? Do you have some recommendations ?
07/08/2017 13:35 Shawak#2
If you want to impove the speed, use a good c++ lib or write the implementation by your own and reduce the code/complexity/runtime to fit your minimum needs.
07/08/2017 20:36 atom0s#3
Use threading. If you are pixel searching, break up the screen into sections and have each thread handle a single section itself. If one of the threads finds what is needed trigger an event to kill the other threads and collect the result as needed.
07/08/2017 22:33 ssamko#4
Quote:
Originally Posted by Shawak View Post
If you want to impove the speed, use a good c++ lib or write the implementation by your own and reduce the code/complexity/runtime to fit your minimum needs.
OpenCV is written in C++ and I use Emgu wrapper for that...I found out that function I have written run on CPU...now I am trying to rewrite it to using GPU in order to boost speed

Quote:
Originally Posted by atom0s View Post
Use threading. If you are pixel searching, break up the screen into sections and have each thread handle a single section itself. If one of the threads finds what is needed trigger an event to kill the other threads and collect the result as needed.
but when you split source img to lets say 5 smaller images and run it on more threads there comes 1 problem...what those object which are split also ? so on 1 split part will be a half of searched object...and on the 2nd will be the second part...what in this case ?
07/08/2017 22:38 .Scy#5
Quote:
Originally Posted by ssamko View Post
but when you split source img to lets say 5 smaller images and run it on more threads there comes 1 problem...what those object which are split also ? so on 1 split part will be a half of searched object...and on the 2nd will be the second part...what in this case ?
I'd say it depends on the images you are given. If your goal is to find certain things, that are rather small on the overall image and you know that the objects you are looking for are more common in certain areas, you could simply split up the image in fitting pieces and try running the search, if there is no result, either take an overlap of your pieces or simply search the whole picture.


that'll help if you have enough data on the images you'll search, otherwise you shouldn't split the image.
07/11/2017 19:17 YatoDev#6
[Only registered and activated users can see links. Click Here To Register...]

Edit:
Don't even try bit manipulation to speed up the comparing if's. This simply doesnt work well with c#.
This is in case the fastest way i could imagine with c# (without killing oop completely)

Edit 2:
This "screenshot" function works perfect but it's pretty slow. You could copy the bits of the bitmap quite earlier but i didn't find how
07/11/2017 21:44 ssamko#7
Quote:
Originally Posted by .Scy View Post
I'd say it depends on the images you are given. If your goal is to find certain things, that are rather small on the overall image and you know that the objects you are looking for are more common in certain areas, you could simply split up the image in fitting pieces and try running the search, if there is no result, either take an overlap of your pieces or simply search the whole picture.


that'll help if you have enough data on the images you'll search, otherwise you shouldn't split the image.
Objects I am searching can be on random place on desktop(+ there can be more than 1) so I would say that splitting is not the best idea


Quote:
Originally Posted by YatoDev View Post
[Only registered and activated users can see links. Click Here To Register...]

Edit:
Don't even try bit manipulation to speed up the comparing if's. This simply doesnt work well with c#.
This is in case the fastest way i could imagine with c# (without killing oop completely)

Edit 2:
This "screenshot" function works perfect but it's pretty slow. You could copy the bits of the bitmap quite earlier but i didn't find how
I have already had searching func with unsafe code which can find result in cca 5-7ms but what you have sent me has more modes...thnx....yes...this is the fastest way...but searched objects which have lets say another rotation or have same shape but another color is harder to detect this way(+with bigger tollerancy there come some false-positive results)...thats why I try to use more advanced libs
07/12/2017 09:33 atom0s#8
Quote:
Originally Posted by ssamko View Post
but when you split source img to lets say 5 smaller images and run it on more threads there comes 1 problem...what those object which are split also ? so on 1 split part will be a half of searched object...and on the 2nd will be the second part...what in this case ?
You can use percentage based matching then allowing for parts of the image to be validated in one thread and then ensuring the rest is matched in another thread. There are different ways to go about it, just like pattern scanning in any other method such as strings, bytes of data, etc.


OpenCV is your best bet probably in this case. It has GPU capabilities already built into it:
[Only registered and activated users can see links. Click Here To Register...]
07/12/2017 10:14 ssamko#9
Quote:
Originally Posted by atom0s View Post
You can use percentage based matching then allowing for parts of the image to be validated in one thread and then ensuring the rest is matched in another thread. There are different ways to go about it, just like pattern scanning in any other method such as strings, bytes of data, etc.


OpenCV is your best bet probably in this case. It has GPU capabilities already built into it:
[Only registered and activated users can see links. Click Here To Register...]
OpenCV itself can be used only in java,python or c++ i think...I am using Emgu C# wrapper for that. Right now I have finally done CPU and also GPU searching algorithm(quite fast) but the result gives me only 1 location(when on the source pic is more than 1 objects same like template)...function MinMax....I have read something about FloodFill with which can be this best match somehow rewritten/deleted and running MinMax again will give 2nd best location. Do somebody have experiences with OpenCV 3.2 or EmguCV wrapper in order to help me to make this work?

My stack-overflow topic with source-code preview: [Only registered and activated users can see links. Click Here To Register...]
07/12/2017 22:35 YatoDev#10
Quote:
Originally Posted by ssamko View Post
I have already had searching func with unsafe code which can find result in cca 5-7ms but what you have sent me has more modes...thnx....yes...this is the fastest way...but searched objects which have lets say another rotation or have same shape but another color is harder to detect this way(+with bigger tollerancy there come some false-positive results)...thats why I try to use more advanced libs
i don't see why iterating an array of pixels/images isn't an option.
Or you could compile image mutations at runtime.

never had issues with that. Invoking the gpu typically does not give any performance gain for such a small task.
07/12/2017 23:00 ssamko#11
Quote:
Originally Posted by YatoDev View Post
i don't see why iterating an array of pixels/images isn't an option.
Or you could compile image mutations at runtime.

never had issues with that. Invoking the gpu typically does not give any performance gain for such a small task.
I have played with normal ImageSearch for a long time and I can see some problems there. I can give you an example:
In game Dark Orbit is ore named Palladium which is blue(each ore can have 1 of 25 blue color comblinations) + it is rotating + behind it is blue background...so with small tollerancy it detects lets say every 4th palla...but with bigger it detects all+it detects ship and background also(false-positive results)...thats why I wanna use some advanced lib which can see shape and it is not just searchin through pixel array.

To that GPU performance. My new advanced algorithm was 2x faster made on GPU than on CPU