Jump to content
slacky

My latest work (TBA in SLACKLIB)

Recommended Posts

Well, I've played around to night, and created some fun functions, and I just feel I should show my latest development. When I get am stable I will add am to SLACKLIB.

 

The first image represents the original image, the later two represents "FindContours", and then we have, two different "DetectEdges"-functions :)

Both Contours and edges can be looked upon very similar, as you can extract the contour (outline) from the edges-area, at least in my second "DetectEdges"-function, which also might be the most useful one (last two pictures).

Original.jpg

Contours1.jpg

Contours2.jpg

Edges1.jpg

Edges2.jpg

Edges3.jpg

Edges4.jpg

Edited by slacky
  • Confused 1
Link to comment
Share on other sites

So how do these functions work? You got me interested...They remind me of some Photoshop filters...

 

I'd imagine it involves distance grouping, color grouping(tol), then finding where two colors meet and etc.

 

Here's something I did:

 

vAnKQl3.png

 

And here's it in black:

 

aqf9ZoF.png

 

I looked in the SLACK library, didn't find those functions. Would love to know how you accomplished that.

Edited by LordJashin
Link to comment
Share on other sites

As soon as I get my Windows XP installation working 100% again, I can take the time to show you.

 

Try using SCAR Portable. Try using windows 7 on a VM. Maybe your settings are wrong, look up the error/settings on google for Win XP. VM's are a bit flakey sometimes.

 

I've dealt with plenty of Windows XP installations, and even on VM's. Are you using VMWare?

Edited by LordJashin
Link to comment
Share on other sites

I've spent a day (24 hours now) on cleaning up the register on my dualboot XP installation. I finally got it working perfectly (= I know XP almost as good as my backyard; been using XP the past 9 years, the two later years I've had it as a duaboot and in VBox. So there's no problem in fixing a corrupt installation, except the time it might take.

 

Win7 and 8 is never an alternative for me, id rather see my self burn down in flames (=

Link to comment
Share on other sites

Gotta love the automated driver install, updates, and support past 2014 lols. It depends if your computer is new or not. I'd never put win7/8 on an older Dual core Pentium computer lol. Windows XP is better for that, but it can cause more pain to mess with because its a little bit older (sometimes)...

 

Windows 8 is terrible, never go there. I've had to fix some License Key crap, and disk check issues with them....not to mention having NO START MENU...

Edited by LordJashin
Link to comment
Share on other sites

#From slacklib.scar

//Copy the client area as bitmap from X->Y2
function XGetScreenArea(XS,YS,XE,YE: Integer): TSCARBitmap;
begin 
 Result := GetClient.CaptureEx(XS,YS,XE,YE); 
end;

procedure XGetClientDimensions(var Width, Height: Integer);
begin
 GetBoxSize(GetClient.ImageArea, Width, Height);
end;

//Get all pixels (2D-array) from an area defined by TBox..
function XGet2DPixels(Area:TBox): T2DIntArray;
var
 BMP: TSCARBitmap; I: Integer; 
 TPA: TPointArray; TIA: TIntArray;
begin
 if ((Area.X1 <= Area.X2) and (Area.Y1 <= Area.Y2)) then 
 begin
   BMP := XGetScreenArea(Area.X1,Area.Y1,Area.X2,Area.Y2);
   SetLength(Result, BMP.Width); 
   for i:=0 to BMP.WIDTH-1 do begin
     TPA := TPAFromBox( Box(i, 0, i, BMP.HEIGHT - 1) );
     TIA := BMP.GetPixels(TPA);
     Result[i] := TIA;
   end; 
   BMP.Free;
 end;
end;

// Find the Edges in the client (colormode dependent).
function XExtractEdges(var TPA:TPointArray; minDiff:Integer): Boolean;
var
 W,H: Integer;
begin
 Result := False;  
 XGetClientDimensions(W, H);
 TPA := CXExtractEdges(XGet2DPixels(Box(0,0,W,H)), minDiff);
 if Length(TPA) > 0 then Result := True; 
end;

// Find the Edges in the client (Only using brightness).
function XExtractEdges2(var TPA:TPointArray; minDiff:Integer): Boolean;
var
 W,H: Integer;
begin
 Result := False;  
 XGetClientDimensions(W, H);
 TPA := CXExtractEdges2(XGet2DPixels(Box(0,0,W,H)), minDiff);
 if Length(TPA) > 0 then Result := True; 
end;

 

#From the unfinished XManipulation.pas:

function CXExtractEdges(ImgArr: T2DIntArray; minDiff: Integer): TPointArray; Stdcall;
var
 X,Y,Width,Height: Integer;  
begin
 Width := High(ImgArr);  
 Height := High(ImgArr[0]);

 for X:=0 to Width do begin
   for Y:=0 to Height do begin
     if (X + 2 < Width) then begin
       if not(XSimilarColors(ImgArr[X][Y], ImgArr[X+2][Y], MinDiff)) then
         Push(Result, Point(X,Y)); 
     end;

     if (Y + 2 < Height) then begin 
       if not(XSimilarColors(ImgArr[X][Y], ImgArr[X][Y+2], MinDiff)) then
         Push(Result, Point(X,Y));
     end; 
   end;   
 end;
end;

function CXExtractEdges2(ImgArr: T2DIntArray; minDiff: Integer): TPointArray; Stdcall;
var
 X,Y,Width,Height: Integer;  
 Color1,Color2: Byte;
begin
 Width := High(ImgArr);  
 Height := High(ImgArr[0]);

 for X:=0 to Width do begin
   for Y:=0 to Height do begin 
     if (X + 2 < Width) then begin
       XColorToLum(ImgArr[X][Y], Color1);
       XColorToLum(ImgArr[X+2][Y], Color2);
       if (Abs(Color1 - Color2) > MinDiff) then
         Push(Result, Point(X,Y)); 
     end;

     if (Y + 2 < Height) then begin
       XColorToLum(ImgArr[X][Y], Color1);
       XColorToLum(ImgArr[X][Y+2], Color2); 
       if (Abs(Color1 - Color2) > MinDiff) then
         Push(Result, Point(X,Y)); 
     end; 
   end;   
 end;
end;

 

Now that is the basic concept of the functions used to extract edges (It was only prototyped); Now the last file should be compiled, as it's resource hungry (loot of iterations).

It also uses XColorToLum and XSimilarColors, which is found in slacklib, but can be replaced by scar functions, or just compiled with slacklib.

XColorToLum = Grayscale color... (see color conversions in slacklib).

 

So those functions returns a TPA of all edge/contrast points. The resulting points depends on the given coloralgorithm. I used LCH for best result, but sure I bet you can use SCARS HSL(CTS2), maybe even RGB-euclidean (CTS1)! :P

Edited by slacky
Link to comment
Share on other sites

Aha! And I was just trying to make a SimilarColors function like this, yesterday: RemoveSimilarColors(var Colors: TIntArray; Tol: Integer) with all looping hell

 

Lols, yeah I glanced at your library yesterday too. Why not keep the outcome colored? I'm guessing all the color changing/algorithms effects the output greatly. I will definitely examine this in greater detail later and report back hehe.

 

I forget what LCH stands for...Lightness, Color, Hue? lols...Someone should make a table with all these abbreviations, and color modes and shit. HSL, HSB, RGB, XYZ, should just include the whole alphabet. RGA(A) lols.

 

Maybe try using this with SCAR's XYZ color mode (most accurate? human vision?).

 

Thanks!

 

I've taken photoshop classes, and web design. Should know all these color modes/models by now...we tend to only use some, and not even mess with the grayscaling/other things you can do (In Photoshop).

Edited by LordJashin
Link to comment
Share on other sites

The outcome is just a TPointArray, no colors are touched. The illustation-pictures is just me coloring the found points.

 

XYZ, is a ok representation of the human vision, but to just use XYZ with any normal formula to compare colors wont be. Now; That is why we have LCH, LAB and LUV which is all build on top of XYZ, to make it simpler to compute colors in space similar to the human eye. So in other words: I don't trust that SCARs CTS3 is a good representation of the human vision.

 

LCH is a 3-dimensional version of LAB which highlights Lightness, Chroma and Hue. It's similar to HSL, but HSL (Hue, Saturation, Lightness) builds on to of RGB-space. While LCH is a forumla on top of XYZ, so their outcome is slightly different.

Edited by slacky
Link to comment
Share on other sites

For the First Detect Edge function (Illustrations), I'd love to see what that looks like in Color instead of Black-Green or Black-Blue. If you don't post it, maybe I'll try copying that function, or using a modified SLACKLIB.

 

By outcome, I was sort of referring to the illustrations, reason for reference to colored. By the way, how did you color those illustrations, looks complicated if using canvas.pen or something...If you were using OSI with RS2's Debug functions (even set to one color) it wouldn't look like that...looks like photoshop to me...

 

Or possibly some advanced drawing/canvas library? Maybe a python one.

 

I don't trust that SCARs CTS3 is a good representation of the human vision.

 

So SCAR doesn't use LCH, LAB and LUV to compute color difference in CTS3? ._.

 

well this is what it says about CTS3 on the wiki...:

 

The fourth and currently last algorithm uses the XYZ color space to compare colors based on an approximation to human visual perception. This is currently the most accurate way to do color comparisons, however the algorithm is very slow because it has to convert the RGB values to the XYZ color space which requires very large calculations. This algorithm also provides a modifier that can be changed to set the sensitivity of the calculations, though the default setting is sufficient is most circumstances. It is not advised to use this algorithm in time critical scripts.

 

Doesn't say much. The link for XYZ on the wiki leads here: http://en.wikipedia.org/wiki/CIE_1931_color_space

Edited by LordJashin
Link to comment
Share on other sites

If you were using OSI with RS2's Debug functions (even set to one color) it wouldn't look like that...looks like photoshop to me...[/Quote]

Why the fuck would I use OSI for that? I avoid all dependencies as long as I can manage.

 

Just loop over the pixels and add a color, or even simpler for just ONE color... The reason it looks "smooth" is because the first versions of edge detection algo search in 45 degrees, resulting in fine/Brushstroke-like edges, but that version does not exist any more...

 

All i did was put the points to an image:

 XGetClientDimensions(W,H)
 SomeBitmap := XGetScreenArea(0,0,W,H)
 bmp := TSCARBitmap.Create(''); 
 bmp.SetSize(SomeBitmap.Width, SomeBitmap.Height);     
 TPA := EdgeDetection(SomeBitmap, 105);   //modified version to take Bitmap as param.

 Bmp.SetPixels(TPA, 15384483);
 DebugBitmap(BMP);

 

Now this is with colors in a meaningful manner, the colored area are ALL the points given by the TPA from EdgeDetection:

311xcua.jpg

 

2sbskud.jpg

 

-------------------------

 

I do not know how scar compares colors with XYZ, and as a matter of fact, I'm not that interested in knowing: I have tested scars CTS(3) in a bunch of cases, and the results ain't that great. The space in XYZ is not meaningful to the eye by just taking the euclidean distance, or any similar method. Ether you need to understand the inner workings (knowledge in the area) and have a set of math-skills, or you need to use one of the predefined colorspaces which builds on top of XYZ, and that is expensive/uses much more time (LAB,LCH,LUV, etc). So: NO, SCAR does not Use LCH, LAB or LUV. Simba uses LAB.

Edited by slacky
Link to comment
Share on other sites

Curious as to what this can actually be applied to for something useful

 

You can easily do color conversions in any color space you want if you port the space into a function with its math. SKy_Scripter did this all the time

 

Honestly I find it unnecessary... what do you actually plan on accomplishing here? Not so say that you can't... but seriously?

 

This is cool stuff don't get me wrong but any of the obvious uses (object detection) are far more suitable to do with standard practices.

Link to comment
Share on other sites

Curious as to what this can actually be applied to for something useful

 

It depends on the speed. Really need to test things out for any practical use.

 

Be useful if we could remove the GROUND PIXELS from the color searches we make on Runescape? Theoretically.

Edited by LordJashin
Link to comment
Share on other sites

Well I mean, if it works really fast. It looks like it would "minimize" the pixels we'd have to run our search functions on. If its precompiled in a library and runs at lets say 25ms to filter SCAR's bitmap it gets from RS2 or SMART...

 

Theoretically

 

SplitTPA is by Distance. And length. Yeah good. But it doesn't actually remove similar colors like in grass, or etc.

 

Their both really similar in nature though....

Edited by LordJashin
Link to comment
Share on other sites

There is a reason as to why I abandoned this (in SCAR). SplitTPA is far to slow when theres a big area of connecting pixels.

 

I planned to use the second for object recognition. The difference compared to just a SplitTPA and Length check is that it's not color very dependent. So lets say an object got 12 different colors, just FindColor + Clustering will be weak compared to feature extraction + Clustering... There will be close to no overlapping as well, and the whole object/shape could be extracted (not just parts)...

I'm not going to talk about the whole plan as SplitTPA was not fast enough for this anyway.

 

I'm using OpenCV for the same purpose in python, and I am able to do really good shape detection, with coordinates, very cool, and extremely useful (trees, ores, NPCs.. Just a few lines, and I got there shape and pos), and I can't say anything on the speed (blink of an eye)! :)

 

 

Edit: Optimized and compiled version ExtractEdges (the one in the last image show above) uses ~5ms om my PC. Clustering the points (SplitTPA) takes over 20sec.

Edited by slacky
Link to comment
Share on other sites

Thanks, you explained it beautifully right there! I was trying to explain that, I got stumped though lol.

 

Yeah these functions are definitely great, especially since they run fast! But I also look forward to trying out similar things with just SCAR's functionality...

 

OpenCV, nice.

 

last comment for now.

Link to comment
Share on other sites

Honestly I think you're exceeding the required resources, at least for Runescape applications. This is the same reason I don't believe in switching off PS/delphi going into other languages or bothering to learn Java etc (well that one for other various reasons)

 

Goodluck I hope your hard work unlocks new possibilities

 

If you're really interested in this type of stuff though I'd try to talk to someone like TriLez over at tribot or Timer over at powebot (or whatever the fuck that shit is called now) (both of whom are inactive OSI developers) they explore different resources and methods like this daily like Java, OpenGL etc.

Link to comment
Share on other sites

I prefer to avoid hooking/injecting/reflecting it takes away all the fun (I just don't find it interesting), just reading the data can be done by anyone... I just find a bigger challenge and use in developing functions related to computer vision.

 

"Honestly I think you're exceeding the required resources"

- Maybe I am, not that it matters for most people. But I enjoy creating shit like this, just for the hack of it! :-)

 

But then we have rule 37 which states:

> There is no overkill. There is only 'open fire', and 'time to reload'

Edited by slacky
Link to comment
Share on other sites

I prefer to avoid hooking/injecting/reflecting it takes away all the fun (I just don't find it interesting), just reading the data can be done by anyone... I just find a bigger challenge in developing functions related to computer vision.

 

"Honestly I think you're exceeding the required resources"

- Maybe I am, not that it matters for most people. But I enjoy creating shit like this, just for the hack of it! :-)

 

I agree, it helps you learn too. Also to appreciate applications like photoshop that have things that do a lot of this for you. Eventually I'm going to learn more on these subjects, and programming with image libraries, etc. There's books out there.

Link to comment
Share on other sites

I prefer to avoid hooking/injecting/reflecting it takes away all the fun (I just don't find it interesting), just reading the data can be done by anyone... I just find a bigger challenge in developing functions related to computer vision.

 

"Honestly I think you're exceeding the required resources"

- Maybe I am, not that it matters for most people. But I enjoy creating shit like this, just for the hack of it! :-)

 

There's more to those bots than reading information. iBot, Tribot, and powerbot all utilized different color hybrid technologies in addition to things like opengl, injection, and reflection.

Link to comment
Share on other sites

Yeah, I get it :) But: Still not interested, on a side note, I can't stand Java (I find far to many reasons to dislike it).

 

Edit: I find RuneScape a fine area to learn about computer vision, test different techniques relative to simple AI, not just for botting, but creating smarter, better bots, not just "working bots with hard-coded rules". In "real life" there is no such thing as hooking, and therefor I avoid it: EG: It can't be used in my RPI and Arduino robots to make am smarter, there is nothing to hook, but I can how ever read colors, and work with feature extraction.

Edited by slacky
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...