Changing Screen Capture Area - My Brain Won't Work :-)

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Changing Screen Capture Area - My Brain Won't Work :-)

Post by Phil Pendlebury » Thu Apr 02, 2009 6:30 pm

Greetings all,

I wasn't sure how best to word the title in order to make it clear that there is nothing wrong with MSched. :-)

I have set myself this problem and have been stuck on it all day with no luck.

Maybe someone can help out of they have time and inclination.

I am using screen capture successfully but I want to make some small changes to avoid ambiguity etc and to help with speed.

I get the screen resolution and take a shot of the screen - This shot is saved for reference.

I then scan the screen shot for a small graphic. When the graphic is found something happens. etc.

Then the actual graphic will change and the scan will start again.

OK so to the problem:

Because of the nature of my script - The next graphic (needle) to be found will inevitably be very close underneath the last graphic that was found.

Therefore there is no reason to scan the entire screen again.

What I have been trying to is when the small graphic is found I get the coordinates and then instead of taking a shot of the whole screen I only take shot of an small area:

-10pixels above and -10pixels the left
100pixels down and 50pixels to the right

Therefore the screen search will be even quicker but better still if the graphic appears anywhere else by chance, only the correct graphic will be found.

So I have tried for hours to get this to work with various mathematics but it has kind of beaten me.

I manage to get the new screen shot to be a small area which includes the found graphic and then next time round the coordinates of the found graphic change because they are relative to the new screen shot size.

After that it all goes wrong.

So let me explain it again in a slightly different way.

Imagine you have a notepad with 4 buttons underneath each other.


Top button lights up
Take Screen Shot
Find that button and it's coordinates
Do something
Top button becomes unlit

Next button lights up
Take screen shot of area only around the last button (as mentioned above)
Find that button and it's coordinates
Do something
This button becomes unlit

Repeat block 2 with next button

etc.

So basically the screen shot rectangle follows the coordinates of the last lit button.

I could post my existing code but it's very messy atm.

Anyway, I'll keep going with this but meantime if anyone has any ideas please feel free.

Thank you.

:-)
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Thu Apr 02, 2009 6:56 pm

Here's what I have so far:

It's almost there I'm sure but something is not quite right.

The code is messy due to tinkering obviously.

Code: Select all

Wait>2
GetScreenRes>xres,yres
Let>zerox=0
Let>zeroy=0
Let>Count=0

Label>Startpoint
ScreenCapture>zerox,zeroy,xres,yres,HAYSTACK.BMP
FindImagePos>NEEDLE.BMP,HAYSTACK.BMP,50,1,XArr,YArr,NumFound

MessageModal>%XArr_0%,%YArr_0%

Let>zerox={%zerox%+%XArr_0%-50}
Let>zeroy={%zeroy%+%YArr_0%-10}
Let>xres={%XArr_0%+110}
Let>yres={%YArr_0%+150}


Wait>1

**BREAKPOINT**
GOTO>Startpoint
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Thu Apr 02, 2009 7:13 pm

Oh blow me! Hang on I think I've got it!

Stand by me...
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Thu Apr 02, 2009 7:22 pm

Code: Select all

Let>zerox={%zerox%+%XArr_0%-50}
Let>zeroy={%zeroy%+%YArr_0%-10}
Let>xres={%zerox%+110}
Let>yres={%zeroy%+150}

Very close...
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Thu Apr 02, 2009 7:36 pm

Ok this pretty much does what I need, it has some anomalies but it works fine:

Code: Select all

Let>zerox={%zerox%+%XArr_0%-90}
Let>zeroy={%zeroy%+%YArr_0%-20}
Let>xres={%zerox%+200}
Let>yres={%zeroy%+200}

Would still be interested in anyone's thoughts on this of course.
Phil Pendlebury - Linktree

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts