Results 1 to 15 of 15

Thread: ColorToleranceSpeed and XYZ

  1. #1
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default ColorToleranceSpeed and XYZ

    I'm not explaining what XYZ means, I'll just show you how to use it in functions and its properties.

    XYZ is the fourth color tolerance speed, to call it, you have to use the procedure ColorToleranceSpeed(3). Here is the order:
    CTS 0(Color32) = Extremely fast, but not accurate at all.
    CTS 1(RGB) = Fast, Accurate.
    CTS 2(HSL) = More accurate than CTS1, but less faster.
    CTS 3(XYZ) = Extremely accurate, not fast at all.

    Note: about the fastness, the difference is not big, between 40 - 100 ms.

    The more accurate a CTS is, the less tolerance you have to use.
    example:
    CTS 0 Tol = 20
    CTS 1 Tol = 15
    CTS 2 Tol = 10
    CTS 3 Tol = 5


    Now, I'll compare them(finding a tree):

    CTS 0:


    CTS 1:


    CTS 2:


    CTS 3:


    So, CTS 3 was the most accurate picture.


    Functions used with XYZ:

    1:
    SCAR Code:
    Procedure ColorToleranceSpeed(3)
    Calls XYZ. Default CTS is 1 (for setting it back).

    2:
    SCAR Code:
    Procedure SetColorSpeed3Modifiers(Sensitivity : Integer)
    Have you ever heard of SetColorSpeed2Modifiers? This does the same thing, but with other value. The higher a sensitivity is, the lower tolerance you should use. Default sensitivity is 4 (for setting it back).
    An example:
    SCAR Code:
    Function FindRockPoints: TPointArray;
    Begin
      ColorToleranceSpeed(3);
      SetColorSpeed3Modifiers(10);
      FindColorsSpiralTolerance(MSCX, MSCY, Result, RockColor, MSX1, MSY1, MSX2, MSY2, 2);
      SetColorSpeed3Modifiers(4);
      ColorToleranceSpeed(1);
    End;
    Note: SetColorSpeed3Modifiers just influence the tolerance you need to input, nothing more. So it is your choose to use it, but I'll use it in the tutorial.

    3:
    SCAR Code:
    Procedure ColorToXYZ(Color : TColor; Var X, Y, Z : Extended)
    Gets the XYZ values of a color, mostly used in autocoloring(minimap). In autocoloring, you have to use these values to compare them other values, like I did in my last tutorial(my sig):
    SCAR Code:
    Function FindWaterColor: Integer;
    Var
      TPA : TPointArray;
      I, H : Integer;
      X, Y, Z, X2, Y2, Z2 : Extended;
      TIA : TIntegerArray;
    Begin
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, WaterColor, MMX1, MMY1, MMX2, MMY2);
      ColorToXYZ(WaterColor, X, Y, Z);
      If Length(TPA) = 0 Then
        Exit;
      H := High(TPA);
      TIA := GetColors(TPA);
      For I := 0 To H Do
      Begin
        ColorToXYZ(TIA[I], X2, Y2, Z2),
        If ((X2 - X) < 4) And ((X2 - X) > 2) Then
          If ((Y2 - Y) < 2) And ((Y2 - Y) > 0) Then
            If ((Y2 - Y) < 5) And ((Y2 - Y) > 3) Then
            Begin
              Writeln('WaterColor = ' + IntToStr(TIA[I]);
              Result := TIA[I];
              Exit;
            End;
      End;
    End;
    You can use this while finding objects in the main screen, like ACA2 does with RGB and HSL.


    4:
    SCAR Code:
    Function XYZToColor(X, Y, Z : Extended): Integer
    Transforms XYZ values to a color.




    These are all the functions related to XYZ in SCAR. How a function would look:
    SCAR Code:
    Function FindChicken(Var CX, CY : Integer): Boolean;
    Var
      TPA : TPointArray;
      ATPA : T2DPointArray;
      I, H, J : Integer;
      X, Y, Z, X2, Y2, Z2 : Extended;
    Begin
      ColorToleranceSpeed(3);
      SetColorSpeed3Modifiers(10);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, ChickenColor, MSX1, MSY1, MSX2, MSY2, 3);
      SetColorSpeed3Modifiers(4);
      ColorToleranceSpeed(1);
      ColorToXYZ(ChickenColor, X, Y, Z);
      ATPA := TPAtoATPAex(TPA, 5, 5);
      H := High(ATPA);
      For I := 0 To H Do
        For J := 0 To High(ATPA[i]) Do
        Begin
          ColorToXYZ(GetColor(ATPA[i][J].X, ATPA[I][J].Y), X2, Y2, Z2);
          If ((X2 - X) < 4) And ((X2 - X) > 2) Then
            If ((Y2 - Y) < 2) And ((Y2 - Y) > 0) Then
              If ((Y2 - Y) < 5) And ((Y2 - Y) > 3) Then
              Begin
                CX := ATPA[i][J].X;
                CY := ATPA[i][J].Y;
                Writeln('ChickenColor = ' + IntToStr(GetColor(ATPA[i][J])));
                Result := True;
                Exit;
              End;
        End;
    End;
    Note: You should add a uptext checker for a more accurate result.

    Freddy's words:
    Quote Originally Posted by Freddy1990
    The fourth tolerance mode compares colors based on the human eye, so if you think a color looks alike, so will SCAR using that mode, making it extremely sensitive and accurate. You can also change the sensitivity which will make it so you have to use a higher or lower tolerance to achieve a similar effect.
    Final Note : What to do with XYZ? experiment with it! compare ranges, differences, distances, sizes, tolerances, lengths, etc.


  2. #2
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    afaik no color algorithm can 100% exclude grass when looking for tree's..
    Verrekte Koekwous

  3. #3
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by mastaraymond View Post
    afaik no color algorithm can 100% exclude grass when looking for tree's..
    My debugger does not say the same...
    SCAR Code:
    program New;

    //Wizzup?
    Function DebugTPA(Points: TPointArray; BmpName: String): Boolean;

    Var
       Width, Height, ClientBMP, I: Integer;
       xs, ys, xe, ye: Integer;

    Begin
      Try
      Begin
        xe := xs xor xs;
        ye := ys xor ys;
        xs := 1 shl 20;
        ys := 1 shl 20;

        For I := 0 To High(Points) Do
        Begin
          xs := Min(xs, Points[i].X);
          ys := Min(ys, Points[i].Y);

          xe := Max(xe, Points[i].X);
          ye := Max(ye, Points[i].Y);
        End;

        Width := xe - xs;
        Height := ye - ys;

        DisplayDebugImgWindow(0, 0);
        DisplayDebugImgWindow(Width, Height);
        ClientBMP := BitmapFromString(Width, Height, '');

        CopyClientToBitmap(ClientBMP, xs, ys, xe, ye);
        For I := 0 To High(Points) Do
          FastSetPixel(ClientBMP, Points[i].X - xs, Points[i].Y - ys, 255);
        If BmpName <> '' Then
          SaveBitmap(ClientBMP, ScriptPath + BmpName + '.bmp');
        SafeDrawBitmap(ClientBMP, GetDebugCanvas, 0, 0);
        DisplayDebugImgWindow(Width, Height);

        FreeBitmap(ClientBMP);
      End
      Except
        FreeBitmap(ClientBMP);
      End;
      Result := True;
    End;

    Procedure DebugTree;
    Var
      TPA : TPointArray;
      I : Integer;
    Begin
      For I := 0 To 3 Do
      Begin
        ColorToleranceSpeed(CTS);
        FindColorsTolerance(TPA, 2053706, MSX1, MSY1, MSX2, MSY2, 10);
        DebugTPA(TPA, 'cts ' + inttostr(I));
      End;
    End;

    begin
      ActivateClient;
      Wait(500);
      DebugTree;
    end.
    Try it with a tree and look at the pics saved in the script's folder.


  4. #4
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    afaik no color algorithm can 100% exclude grass when looking for tree's..
    I shit my pants too when CTS 3 was released, I found willows in draynor, without any confusing to with grass

  5. #5
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    I shit my pants too when CTS 3 was released, I found willows in draynor, without any confusing to with grass
    I've had XYZ + CMYK color finding way before it was released in scar. Yet I couldn't 100% exclude the grass. Simply for one reason, it was identical to colors in the trees.
    Of course 99/100 times it didn't find the grass, but yet that doesn't make 100%.
    I might have got the BMP somewhere on my harddisk..
    Verrekte Koekwous

  6. #6
    Join Date
    Dec 2007
    Posts
    2,766
    Mentioned
    2 Post(s)
    Quoted
    37 Post(s)

    Default

    When you talk about speed... When is it slower ?

  7. #7
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice tutorial, Cazax. I really like people who keep posting useful stuff even after receiving a cup, that proves that they're not only after glory.

    Rep+ for you.

    Quote Originally Posted by Dr D. Dervish View Post
    When you talk about speed... When is it slower ?
    A thumb rule is, the higher CTS, the slower it gets.

    Edit: Lol, Dervish, did you even read the tutorial?
    Very first part of tutorial:

    CTS 0(Color32) = Extremely fast, but not accurate at all.
    CTS 1(RGB) = Fast, Accurate.
    CTS 2(HSL) = More accurate than CTS1, but less faster.
    CTS 3(XYZ) = Extremely accurate, not fast at all.

  8. #8
    Join Date
    Dec 2007
    Posts
    2,766
    Mentioned
    2 Post(s)
    Quoted
    37 Post(s)

    Default

    I mean, when while color finding is it slower. In which moment ? In the actual finding..?

  9. #9
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh, I see.

    Well, CTS is basically different color comparison modes. Basically, they define which colorspace to use when comparing colors in a search for a color with tolerance.
    CTS 1 compares the colors within the tolerance range with RGB, which is faster than using HSL for comparison, as CTS 2 does. Naturally, CTS 3 is the slowest, as it uses XYZ.

    Did I explain it clearly enough?

  10. #10
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    your findchicken doesn't even compile...

  11. #11
    Join Date
    Aug 2007
    Location
    Where do you live?
    Posts
    934
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    This:
    SCAR Code:
    XYZToColor(GetColor(ATPA[i][J]), X2, Y2, Z2);
    Should be this:
    SCAR Code:
    ColorToXYZ(GetColor(ATPA[i][J].x, ATPA[i][J].y), X2, Y2, Z2);

    because X2, Y2, and Z2 all don't have any values set to them... so the color you will get from:
    SCAR Code:
    XYZToColor(X2, Y2, Z2); //the RIGHT way to call this function
    color will be 0 (or rubbish depending on default values)

    I'm assuming it was just a typo, but it's nice to have working functions in tuts like GetColor for example, should look like this:
    SCAR Code:
    GetColor(ATPA[i][J].x, ATPA[i][J].y) // need the x and y values

    Other than that, good tut

  12. #12
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by nose_smasher View Post
    This:
    SCAR Code:
    XYZToColor(GetColor(ATPA[i][J]), X2, Y2, Z2);
    Should be this:
    SCAR Code:
    ColorToXYZ(GetColor(ATPA[i][J].x, ATPA[i][J].y), X2, Y2, Z2);

    because X2, Y2, and Z2 all don't have any values set to them... so the color you will get from:
    SCAR Code:
    XYZToColor(X2, Y2, Z2); //the RIGHT way to call this function
    color will be 0 (or rubbish depending on default values)

    I'm assuming it was just a typo, but it's nice to have working functions in tuts like GetColor for example, should look like this:
    SCAR Code:
    GetColor(ATPA[i][J].x, ATPA[i][J].y) // need the x and y values

    Other than that, good tut
    Thanks for finding those typos glad you like this


  13. #13
    Join Date
    Aug 2007
    Location
    Where do you live?
    Posts
    934
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Np

    Question, with this:
    SCAR Code:
    If ((X2 - X) < 4) And ((X2 - X) > 2) Then
          If ((Y2 - Y) < 2) And ((Y2 - Y) > 0) Then
            If ((Y2 - Y) < 5) And ((Y2 - Y) > 3) Then
    Where you get those numbers from? random? or is there a special way to figure out what the ranges should be?

  14. #14
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by nose_smasher View Post
    Np

    Question, with this:
    SCAR Code:
    If ((X2 - X) < 4) And ((X2 - X) > 2) Then
          If ((Y2 - Y) < 2) And ((Y2 - Y) > 0) Then
            If ((Y2 - Y) < 5) And ((Y2 - Y) > 3) Then
    Where you get those numbers from? random? or is there a special way to figure out what the ranges should be?
    Use ColorToXYZ() with the original color to get the numbers, then you can look for similar ranges


  15. #15
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Procedure ColorToleranceSpeed(3)

    maybe want to change it to:

    procedure ColorToleranceSpeed(x: Integer);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Custom TPA Finding & ColorToleranceSpeed(2) Modifiers!
    By Goobs in forum OSR Advanced Scripting Tutorials
    Replies: 38
    Last Post: 05-19-2012, 06:40 AM
  2. Replies: 2
    Last Post: 11-07-2008, 09:17 PM
  3. Small Tut. (ColorToleranceSpeed)
    By Wizzup? in forum OSR Advanced Scripting Tutorials
    Replies: 4
    Last Post: 04-19-2007, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •