SRL Archive - Jr. Member General Help and Discussion

Detecting Pixelshift in ATPA


Clarity

2014-01-23 14:09:30

Couldn't connect to IRC or Skype so posting here:
I'm trying to detect objects that are moving versus objects that are not (like a shaking box vs. not shaking box, etc.)

Both versions are identical in colors pretty much.

Currently my object find is working perfectly, and creates an ATPA of all the found objects, shaking or not shaking.
I assume pixelshift would be the ideal way to distinguish between the two kinds, and so I see these functions in the include:


function getPixelShiftAverage(atpa: T2DPointArray; waitPerLoop, maxTime: integer): TIntegerArray; overload;

function getPixelShift(atpa: T2DPointArray; time: integer): TIntegerArray; overload;

They both return TIntegerArrays and I'm wondering how exactly this integer array can be used to replace the ATPA of everything into an ATPA of just the shaking objects. I'm not sure what to do with it.

Thanks for taking the time to help a newb out, a cool new script is on the way hopefully!

Foundry

2014-01-23 14:54:58

It returns an integer array with indexes corresponding to the original atpa. All you would need to do is iterate through the integer array, pick out the ones with the desired pixel shift, and make a new atpa. Here's an example:

EDIT: Removed unnecessary code.

function returnMovingObject(atpa: T2DPointArray): T2DPointArray;
var
i, j: Integer;
pixelshifts: TIntegerArrray;
begin
pixelshifts := getPixelShift(atpa, WHATEVER_TIME);
for i := 0 to high(pixelshifts) do
begin
if pixelshifts[i] > MINIMUM_TO_BE_DEEMED_MOVING then
begin
setLength(result, j + 1);
result[j] := atpa[i];
inc(j);
end;
end;
end;

Wrote that up real fast in browser so it may not compile right after you fill in everything. Hope this helps.

Clarity

2014-01-23 14:57:43

From: Foundry
It returns an integer array with indexes corresponding to the original atpa. All you would need to do is iterate through the integer array, pick out the ones with the desired pixel shift, and make a new atpa. Here's an example:

function returnMovingObject(atpa: T2DPointArray): T2DPointArray;
var
i, j: Integer;
hits, pixelshifts: TIntegerArrray;
begin
pixelshifts := getPixelShift(atpa, WHATEVERTIME);
for i := 0 to high(pixelshifts) do
begin
if pixelshifts[i] > MINIMUMTOBEDEEMEDMOVING then
begin
setLength(hits, j + 1);
hits[j] := i;
inc(j);
end;
end;
j := 0;
for i := 0 to high(hits) do
begin
setLength(result, j + 1)
result[j] := atpa[hits[i]];
inc(j);
end;
end;

Write that up real fast in browser so it may not compile right after you fill in everything. Hope this helps.


Dude thank you a ton for the fast reply, gonna use this right away!
Also unrelated, I donated to SRL a bit ago, do you need to PM someone about it, or is your profile automatically updated at some point?

Kevin

2014-01-23 15:11:52

From: acredelta
Dude thank you a ton for the fast reply, gonna use this right away!
Also unrelated, I donated to SRL a bit ago, do you need to PM someone about it, or is your profile automatically updated at some point?


PM Hobbit with a picture showing the donation. Or Daniel. Or… other people whose names don't come up to mind offhand.

Clarity

2014-01-23 15:12:40

Alright sounds good, thanks again!

Foundry

2014-01-23 15:57:45

From: acredelta
Dude thank you a ton for the fast reply, gonna use this right away!
Also unrelated, I donated to SRL a bit ago, do you need to PM someone about it, or is your profile automatically updated at some point?


I took a second look and removed some unnecessary code. It's in the edited post.

Clarity

2014-01-23 16:05:35

yep I wrote my own version in my script just now, so no worries! I didn't know how to work with TIntegerArrays in general hehe, you definitely saved me a lot of time.