Ask Your Question
-1

Detect image on screen

asked 2017-07-20 17:15:08 -0600

programs gravatar image

I have found that OpenCV can detect image from images: http://docs.opencv.org/2.4/doc/tutori...

But can it find a picture from my screen i currectly running ( browser, game, watching video ... ) I meant detect image not by file, but real time?

edit retag flag offensive close merge delete

Comments

take a look at "How to capture the desktop" https://stackoverflow.com/q/14148758/...

sturkmen gravatar imagesturkmen ( 2017-07-21 04:00:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-07-21 03:30:57 -0600

Raki gravatar image

updated 2017-07-21 03:35:47 -0600

You are talking about template matching, in which one provides a template and a scene, and OpenCV outputs the matches. However, for this to work, you need to provide static images as templates. It does not matter if your scene is dynamic, but your templates should be static.

If your game is continuously running, this means it changes its frames every second and gets always new frames, how do you expect OpenCV to match the template(s) over thousands of frames? You need a match, if you do not have any commonality between your template (sample frames from your game) and your scene (your real time running game in this case), then do not expect OpenCV to achieve what you want. Remember, what you are looking for in the scene, should have something in common with the template. If you are looking for a character in your game screen for instance, and if that character is always present, then you can achieve this with template matching, like here in the bottom there is an example from a Mario game. But the whole frame you cannot match, since there would not be any commonality between your template frames and real-time frames.

So the answer to your question is no.

However, if all you want is to detect the window where your game is running, this is an easier task, and in that case the question should be rephrased. Or if your question is to detect an object or a character that is always present in your game screen, that can also be achieved, but you cannot match the whole frame without any commonality between the template.

edit flag offensive delete link more

Comments

I need need OpenCV to search entire screen, there is some static portion in running application who will not change.

  img_rgb = cv2.imread('mario.png')
    template = cv2.imread('mario_coin.png',0)

This just compared 2 pictures. And what I should put inside imread() method or maybe use diffrend method?

programs gravatar imageprograms ( 2017-07-21 04:13:29 -0600 )edit

Then cut out that static part of the frame and save it as a .png file, then feed it as a template in that mario example. The coin in that example will be your static part in your game.

The scene will be constantly flowing frames coming from the window of the application which you want to run. And that, I am afraid is the challenging part. You cannot directly get a frame from a window, it is not a straightforward task. You may want to utilize linux commands to focus on the game window, but even then. you need to somehow record that game flow and feed it into OpenCV. I am not sure how to do that, and this is a different question already: How to capture frames from a real-time application window?

Raki gravatar imageRaki ( 2017-07-21 05:12:19 -0600 )edit

You are right, you even made better question then me.

programs gravatar imageprograms ( 2017-07-21 15:57:05 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-20 17:14:25 -0600

Seen: 15,294 times

Last updated: Jul 21 '17