SRL Archive - Help and Support

problem... with colors :p


Dark_Sniper

2007-04-23 01:08:27

now this is going to sound weird…

you know how findcolor… works it searches for a specific color…

now lets say you have a 50 pixel by 50 pixel box….

and it has the same color(s) constantly….
but a Random color comes in there…

how do i make scar detect this Random color in the 50 pixel x 50 pixel box of the same color(s)

picture examples:

this has the same colors in it

now this has a random color(right now its white but it could be any color).


{ if you know that colors in the area… but a new one comes in… and it could be any other color… how do i make scar know that the new color is there…}


now if that random color comes in how do i make scar detect that it is there?
i can see great uses for this.

Boreas

2007-04-23 02:17:04

program New;
type BmpCom=record
bmp,inc,w,h,NumberOfColors:integer;
ColorArray:array of tpoint;
SkipArray:array of integer;
end;

var tmpres,tx,ty:integer;
var inccounter,iter,iter2,NumberOfCombos,NumberOfBmps,x,y,parray,tmpcolor,tmpal:integer;
Bmps:array of BmpCom;
Combos:array of array of integer;
AnswerArray,AnswerArray2:array of tpoint;

procedure DeclareBmps;
begin
NumberOfBmps:=1;
setarraylength(bmps,NumberofBmps);
bmps[0].bmp:=loadbitmap(apppath+'/lpc.bmp');
end;






{*******************************************************************************
function InIntArray(TheInt:integer;TheArray:array of integer):boolean;
By: Boreas
Description: Returns true if TheInt is a member of TheArray
******************************************************************************}
function InIntArray(TheInt:integer;TheArray:array of integer):boolean;
var i:integer;
begin
if getarraylength(thearray)<>0 then
repeat
if TheArray[i]=TheInt then
result:=true;
i:=i+1;
until ((i=getarraylength(TheArray)) or (result));
end;
function CountColorbmp(thebmp,color,x1,y1,x2,y2:integer):integer;
var x,y,tmpres:integer;
begin
tmpres:=0;
for x:=x1 to x2 do
begin
for y:=y2 to y2 do
begin

if FastGetPixel(thebmp,x,y)=color then tmpres:=tmpres+1;
writeln(inttostr(x)+' '+inttostr(y)+' '+inttostr(FastGetPixel(thebmp,x,y))+' '+inttostr(tmpres));
end;
end;
result:=tmpres;
end;




function LowestTolSimColors(TheArray:array of integer):integer;
var parray:integer;
begin
for parray:=0 to getarraylength(TheArray)-2 do
begin
repeat
result:=result+1;
until SimilarColors(TheArray[parray],TheArray[parray+1],result);
end;
end;

function RearrangeTPA(thearray:array of tpoint; startpt, endpt:integer; dox,up:boolean):array of tpoint;
var
temp, pArray : integer;
done : boolean;
ttp:tpoint;
tmpTPA : array of tpoint;
begin
setarraylength(tmpTPA,getarraylength(thearray));
tmpTPA:=thearray;
setarraylength(result,endpt+1-startpt);

if not(up) then
begin

if dox then
begin
repeat
done := true;
for pArray := 0 to (getarraylength(thearray) - 2) do
begin
if(tmpTPA[pArray].x < tmpTPA[pArray + 1].x) then
begin
ttp := tmpTPA[pArray];
tmpTPA[pArray] := tmpTPA[pArray + 1];
tmpTPA[pArray + 1] := ttp;
done := false;
end;
end;
until(done);
end;

if not(dox) then
begin
repeat
done := true;
for pArray := 0 to (getarraylength(thearray) - 2) do
begin
if(tmpTPA[pArray].y < tmpTPA[pArray + 1].y) then
begin
ttp := thearray[pArray];
tmpTPA[pArray] := tmpTPA[pArray + 1];
tmpTPA[pArray + 1] := ttp;

done := false;
end;
end;
until(done);
end;

end;

if up then
begin

if dox then
begin
repeat
done := true;
for pArray := 0 to (getarraylength(thearray) - 2) do
begin
if(tmpTPA[pArray].x > tmpTPA[pArray + 1].x) then
begin
ttp := tmpTPA[pArray];
tmpTPA[pArray] := tmpTPA[pArray + 1];
tmpTPA[pArray + 1] := ttp;

done := false;
end;
end;
until(done);
end;

if not(dox) then
begin
repeat
done := true;
for pArray := 0 to (getarraylength(thearray) - 2) do
begin
if(tmpTPA[pArray].y > tmpTPA[pArray + 1].y) then
begin
ttp := tmpTPA[pArray];
tmpTPA[pArray] := tmpTPA[pArray + 1];
tmpTPA[pArray + 1] := ttp;


done := false;
end;
end;
until(done);
end;

end;

pArray:=startpt-1;
for temp:=0 to getarraylength(result)-1 do
begin
pArray:=pArray+1;
result[temp]:=tmpTPA[pArray];
end;

end;

function RemoveDupsFromTPASingle(var StartTPA: array of Tpoint; DoX:boolean): array of Tpoint;
var
ArrayLength, pFindDups, pBubbleUp: integer;
tpSwap:tpoint;
begin
ArrayLength:=getarraylength(StartTPA);
// result:=RearrangeTPA(StartTPA,0,ArrayLength-1,true,true);
if DoX then
begin
result:=RearrangeTPA(StartTPA,0,ArrayLength-1,true,true);
//for pFindDups := 0 to (ArrayLength - 2) do
// begin
pFindDups:=0; //
repeat //
if(result[pFindDups].x = result[pFindDups + 1].x) then
begin
for pBubbleUp := pFindDups to (ArrayLength-2) do
begin
tpSwap := result[pBubbleUp];
result[pBubbleUp] := result[pBubbleUp+1];
result[pBubbleUp+1] := tpSwap;
end;
ArrayLength := ArrayLength-1;
setarraylength(result, ArrayLength);
pFindDups:=pFindDups-1;
end;
pFindDups:=pFindDups+1; //
until pFindDups>(ArrayLength - 2);//
//end;
end;
if not DoX then
begin
result:=RearrangeTPA(StartTPA,0,ArrayLength-1,false,true);
for pFindDups := 0 to (ArrayLength - 2) do
begin
if(result[pFindDups].y = result[pFindDups + 1].y) then
begin
for pBubbleUp := pFindDups to (ArrayLength-2) do
begin
tpSwap := result[pBubbleUp];
result[pBubbleUp] := result[pBubbleUp+1];
result[pBubbleUp+1] := tpSwap;
end;
ArrayLength := ArrayLength-1;
setarraylength(result, ArrayLength);
end;
end;
end;
end;


begin {
bmp1:= BitmapFromString(32, 57, 'z78DAED99DB72EB2A0C865' +
'F090771BA1402DEFF9116415CC8439D8D9BFAB0672CCFFCED3869' +
'FC490849A44A3DF6D8638F3DF6D863FF6DA42285D4952844C57A8' +
'E610829D057FC89306AD6E49325907A0EFF375E9023C0906CD2B4' +
'B0F29DA3E336F2FFEE33A1807A9141F05AB3F29DA3C9FFCA0B932' +
'06A6315646DBB171AF42B9F43BEC53FF3AC1492232B35630E59B1' +
'FED5FA7EC3FFF989A9A44479A5949022658A1122C510DCD1E433F' +
'CE3D36585E1DDDAB510452BF568F2BD5E041BB47369A11C512AFA' +
'9AFA2644678DEB9AEBCF741F7E266725248725A22F3660F4DA2AB' +
'4AE98CCEAB34D46CD54D10BE24F35A989969850317FD7C57B0B98' +
'BCB1F5B58801AF9A073EF33BAA4BF08A1A8BCF4CDB994B78D9C81' +
'A7C30CEDF8D9C150054BD9A86E2D02006BF9852B36AA975DF41AD' +
'FD67E6FC0CB95526D40B0DD4CB9B57BD9ADA978906A5CA5721830' +
'7772D7F8D682D902619572F0508684C9D0E0A7B24B593B7F733B9' +
'D4ABBCE8E44D21BEC3CFFA03F90DF8472F985C678D1A7BFC59D92' +
'FCE28A17DA2139EB25E558B98B353B54872FE8CE4929F7DBC0F3F' +
'33FC10FF416FC7CFD166E5BD2CB3BD716EFE2DEF856BF9999333A' +
'47931BF37A5EF67324BB69E3FAD2B8D3593EF4F45A0E949CC1B79' +
'BE229FAE8DC7F18F99C019DB09DB84207300169D74EA2B7229FF2' +
'AC21FBB2A33775AFEBDA9F3F5D40B33FCDDEB3FE2EF35442A4F32' +
'0379EFAD1C6D31B3D50680EF09ED3DB37DAE3F2B2FDA4E89BE1ED' +
'87E3997F227ACA6AF0DE6919FD53B5B3B019FAD78DA9FE7EF9D1D' +
'5C3629285BF6ACC5D83767C847FEAEC30ACE93B0EF7EB11ABCAB7' +
'B4BE729F2893C3987FF97FB94BBCF50037793CB5E7C706F5A4569' +
'A386EF203F9D5F4E5F9BFCC3E9A99FA1467239F3C813D644FF3D9' +
'07F7E15FE87FCAB33EFA04793B38DF1DC9DF3929CA78813A7FAAF' +
'AACDA0D79E6A7F58918DDC58A99891EE709EDA8CFFB843B9F60E9' +
'39EBAD436F9376AFB5567A8D15C3465FDBD8DD43E9F785777E999' +
'13C20EFE36B18FCCD278AAA425C0FBFBEFEBB365C5DFE6760A01D' +
'DC2FAF93DEA66E6EAEC0F8BFCFFC856FC59D5638F3DF6D84EFB07' +
'C14271C3'); }

DeclareBmps;
for iter:=0 to NumberofBmps-1 do
begin
GetBitmapSize(bmps[iter].bmp,bmps[iter].w,bmps[iter].h);


for x:=0 to bmps[iter].w-1 do
begin
for y:=0 to bmps[iter].h-1 do
begin
tmpcolor:=fastgetpixel(bmps[iter].bmp,x,y);


if not( InIntArray(tmpcolor,bmps[iter].SkipArray)) and (tmpcolor<>0) then
begin
tmpAL:= GetArrayLength(bmps[iter].SkipArray);
SetArrayLength(bmps[iter].SkipArray,tmpAL+1);
SetArrayLength(bmps[iter].ColorArray,tmpAL+1);
bmps[iter].SkipArray[tmpAL]:=tmpcolor;
bmps[iter].ColorArray[tmpAL].x:=tmpcolor;
tmpres:=0;
for tx:=0 to bmps[iter].w-1 do
begin
for ty:=0 to bmps[iter].h-1 do
begin
if FastGetPixel(bmps[iter].bmp,tx,ty)=tmpcolor then tmpres:=tmpres+1;
end;
end;

bmps[iter].ColorArray[tmpAL].y:= tmpres;
//bmps[iter].ColorArray[tmpAL].y:=CountColorbmp(bmps[iter].bmp,tmpcolor,0,0,31,56);
//bmps[iter].ColorArray[tmpAL].y:= CountColor(tmpcolor,0,0,31,56);
end;
end;
end;
bmps[iter].ColorArray:=RearrangeTPA(bmps[iter].ColorArray,0,getarraylength(bmps[iter].ColorArray)-1,false,true);
writeln(inttostr(bmps[iter].ColorArray[0].x));
freebitmap(bmps[iter].bmp);

end;


end.

Written on SCAR 3.02. Save the bitmaps in SCAR folder and put names in DeclareBmps. Will give you color with lowest pixelcount for each bitmap. Ignores 0.



EDIT: I just read your post again. Do you mean you want a motion detector?

Dark_Sniper

2007-04-23 02:30:17

no…

now motion… just need to identify that there is a color in the search area that shouldnt be there.

like a solid black box.. with a random diffrent pixel color in it… how do i get scar to detect the random color is there… and the random color can be in a random place to :p







like a Only Find Colors in the area…

if it finds only the specified colors in the area it is returned true.

if it finds more than the colors specified then returns false…

Boreas

2007-04-23 02:40:12

Ah ok.

{*******************************************************************************
function InIntArray(TheInt:integer;TheArray:array of integer):boolean;
By: Boreas
Description: Returns true if TheInt is a member of TheArray
******************************************************************************}
function InIntArray(TheInt:integer;TheArray:array of integer):boolean;
var i:integer;
begin
if getarraylength(thearray)<>0 then
repeat
if TheArray[i]=TheInt then
result:=true;
i:=i+1;
until ((i=getarraylength(TheArray)) or (result));
end;


for x:=x1 to x2 do
begin
for y:=y1 to y2 do
begin
tmpint:=getcolor(x,y);
if not(InIntArray(tmpint,ArrayOfColors)) then
tmpbool:=true;
if tmpbool then break;
end;
if tmpbool then break;
end;
writeln(inttostr(tmpint)+' at '+inttostr(x)+','+inttostr(y));

Dark_Sniper

2007-04-23 11:22:14

ya i was getting stuff like that….

thanks i think i can mod it from there.

c0de

2007-04-24 13:36:16

If you know the color?


repeat
wait
until weirdcolorisfound

Dark_Sniper

2007-04-24 15:39:11

hint hint… random color…

i mght be able to put like a more comon color found….. and put higher tols.. mabye that will work.

Bam Bam

2007-04-25 18:48:52

Could you use the HSL features of Divi?

Dark_Sniper

2007-04-25 20:08:43

… man it would be nicce if i could just say…

if only findcolor() and findcolor() and findcolor() then …..

Boreas

2007-04-25 23:20:34

From: Dark_Sniper
… man it would be nicce if i could just say…

if only findcolor() and findcolor() and findcolor() then …..


untested:
function IfOnlyFindColorsIn (Colors: array of integer; x1,y1,x2,y2: integer): boolean;
var tx, ty, tmpint: integer;
begin
result:=true;
for tx:=x1 to x2 do
begin
for ty:=y1 to y2 do
begin
tmpint:=getcolor(tx,ty);
if not(InIntArray(tmpint,Colors)) then
result:=false;
if not result then break;
end;
if not result then break;
end;
end;