flat assembler
Message board for the users of flat assembler.

Index > Windows > image search library?

Author
Thread Post new topic Reply to topic
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 06 Aug 2020, 22:03
hey,

im wondering if there is any image search library for win32 applications, and it have functions like search the whole screen or specific region or rectangle on my screen.

so basically i give the library a .png file or .bmp or whatever, and it search for it and then returns the screen based coordinates.

also i tolerance would be nice too, i.e. similarity.

_________________
Asm For Wise Humans
Post 06 Aug 2020, 22:03
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 07 Aug 2020, 21:58
opencv? That's what Sikuli uses, which can recognize objects on the screen. Not sure how much opencv provides off the bat, but it's been around a while.

Links:
Post 07 Aug 2020, 21:58
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 08 Aug 2020, 19:44
thank you donn, it seems i have to use this library to code my own image recognition.

which is not really what i want, and this library (openCV) is quite large so finding the functions requires is hard.

_________________
Asm For Wise Humans
Post 08 Aug 2020, 19:44
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 09 Aug 2020, 19:16
In the past, I've used a hash of a small block to quickly scan a region. In this case, the image data was constant - exactly RGB values - just needed to find the position. Another case was more complex because of transparent overlays. Yet, I was still able to construct a hash that worked in a fuzzy way based on rough hue calculation. It used a 4x4 array of 2x2 pixels, but only some of the outer groups needed to match.
Post 09 Aug 2020, 19:16
View user's profile Send private message Visit poster's website Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 09 Aug 2020, 19:51
if the pixels (in my case) had fixed RGB values then it might easier to do GetPixel function in a loop, however in my case pixels have dynamically applied gray scale so that is not an easy thing to me as i have absolutely no idea how to implement this that is why i was searching and asking for pre-made dll for these stuff.

also 4x4 if relatively small grid.

_________________
Asm For Wise Humans
Post 09 Aug 2020, 19:51
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 09 Aug 2020, 20:35
I scanned the whole screen, 4x4 (actually 8x8, because of 2x2 pre-processing) is just the size to identify an object on the screen. In a single pass, I could identify a large number of objects. Grayscale doesn't matter when matching only the hue. Sorry, I can't share any code of this project, but it did work quite well.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 09 Aug 2020, 20:35
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 10 Aug 2020, 16:16
I looked at OpenCV, and yes I was lost also. May be possible to define your own image recognition by scanning grid regions as you were just discussing.

If you give up, OpenCV seems like it can solve the problem, however. There are some tutorials you can look up. Depending on what kind of tolerances you are looking for, things can get overcomplicated quickly.

References:

    -https://circuitdigest.com/tutorial/object-detection-using-python-opencv
    -https://www.docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html
    -https://www.elliotlaketoday.com/ (stop sign image comes from here)


I made some slight modifications to the first link above and tested it works.

Code:
import cv2
import numpy as np

image=cv2.imread('image.jpg')
cv2.imshow('image',image)
cv2.waitKey(0)
gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)


template=cv2.imread('image_subset.jpg',0)
#template=cv2.imread('image_subset2.jpg',0)
#result of template matching of object over an image
result=cv2.matchTemplate(gray,template,cv2.TM_CCOEFF)
sin_val, max_val, min_loc, max_loc=cv2.minMaxLoc(result)

top_left=max_loc
#increasing the size of bounding rectangle by 50 pixels
bottom_right=(top_left[0]+171,top_left[1]+151)
cv2.rectangle(image, top_left, bottom_right, (0,255,0),5)

cv2.imshow('object found',image)
cv2.waitKey(0)
cv2.destroyAllWindows()    


Key function is matchTemplate.


Description:
Filesize: 12.61 KB
Viewed: 8841 Time(s)

image_subset.jpg


Description:
Filesize: 93.84 KB
Viewed: 8841 Time(s)

image.jpg


Description: Change ext to .py before running with python mult_2.py
Download
Filename: mult_2.py.txt
Filesize: 671 Bytes
Downloaded: 452 Time(s)

Post 10 Aug 2020, 16:16
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 10 Aug 2020, 16:18
Alternate template to search for. Could only attach 3 files per post.


Description:
Filesize: 15.27 KB
Viewed: 8840 Time(s)

image_subset2.jpg


Post 10 Aug 2020, 16:18
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 12 Aug 2020, 00:22
thank you, i will convert this to assembly and post the results as soon as i finish other things.

_________________
Asm For Wise Humans
Post 12 Aug 2020, 00:22
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 13 Aug 2020, 09:20
so i downloaded opencv library, and found that "opencv_world440.dll" is what i need.

i found these functions from export section of the dll:
cvCvtColor
cvDestroyAllWindows
cvMatchTemplate
cvMinMaxLoc
cvRectangle
cvWaitKey

however there is no "imread", i also searched other DLLs included in the package but non of them contain that image loading function.

not sure if it resides in the static library that meant to be linked (.lib file) and if so then i have to give it a try using C language. (the only language i know other than x86asm.)

_________________
Asm For Wise Humans
Post 13 Aug 2020, 09:20
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 13 Aug 2020, 18:17
I think imread is the C++ function name. The C functions include:


Code:
C: IplImage* cvLoadImage(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR )    


See a lot of posts talking about converting to grayscale, so this may be acceptable:

Code:
CV_LOAD_IMAGE_GRAYSCALE - If set, always convert image to the grayscale one    


References:


I've seen comments in their source discussing differences in the C and C++ APIs, and have seen imread used in the cv namespace. Not sure exactly where each is defined yet.
Post 13 Aug 2020, 18:17
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 732
Ali.Z 14 Aug 2020, 01:16
donn wrote:
C and C++ APIs


you are right, honestly i did not know there is different APIs for C and C++.

at first i downloaded the wrong library, which is the 4.4.0 which is the C++ one.

https://opencv.org/releases/

the one i needed is 3.4.11 (C API), and their release page said absolutely nothing about it.

and yes, it have all the functions needed.
so i will start testing.

_________________
Asm For Wise Humans
Post 14 Aug 2020, 01:16
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.