<< return to Pixycam.com

how to detect BLOBS/blocks representing Color Codes (CC) by Arduino Sketch?

how can I detect BLOBS/blocks representing Color Codes (CC) by Arduino Sketch?
i.e., what is the Arduino Code for Color Codes?

I only can see
pixy.blocks[j].signature

but I miss
pixy.blocks[j].COLORCODE

where is it or how to poll it?

(tbh, the API documentation is REALLY worse than bad !!)

  • BUMP *

I still don’t see any Arduino code example how to recognize color codes, I just can detect signatures so far.
(I’m using SPi mode, but this shouldn’t actually matter)

so how to do it ??

sorry, I don’t understand the way how it works for CC at all…
In my understanding we have
a) detected single-color labels (== signatures) of different sizes and locations and
b) detected double-color labels (== ColorCodes) of different sizes and locations

Given I had 200 blocks for color signatures and may have 40 CC labels (7 different ones, but 3-10 multiples of them), i.e.
the various (e.g., number 1<=j<=200) single-color labels (== signatures) are related pixy.blocks[ j].signature,
somehow the various (number 1<=k<=40) detected double-color labels (== ColorCodes) are releated to pixy.blocks[ 0].signature

does pixy.blocks[ 0].signature 12 mean color signature number twelve?

The signatures (single-color-labels) come in with their coordinates by blocks[ 1]…blocks[ 200], sorted by colorID and by size.

I can read the coordinates and sizes by

 // 1 <= j <= 200
        blockS[j]= pixy.blocks[j].signature;
        blockX[j]= pixy.blocks[j].x;
        blockY[j]= pixy.blocks[j].y;
        blockW[j]= pixy.blocks[j].width;
        blockH[j]= pixy.blocks[j].height;

Now how do the 40 CC’s (double-color-labels) come in by their coordinates?

I don’t see how they all will be arranged when read by the Arduino.

the description is odd and weird and completely un-understandable to me :frowning:

some source code examples about how to read and store (x,y) coodinates of incoming CC-labels would be helpful.

any hints about just to detect e.g.,

3 CC’s:

yellow+blue
red+darkgreen
pink+lime

at 4 different (x,y) positions each
and store these overall 12 CC-positions (x,y) in variables

CCx[ 1]…[ 12], CCy[ 1]…[ 12]

??

In a previous post you asked if CC 12 was color signature 12. The CC numbers are reported as octal digits, where each digit is the color number. So if 12 was in decimal, the octal value is 14. That means the detected color code is made up of 2 colors, numbers 1 and 4.

In the last post you identified 3 combinations made up of 6 colors. Since there are 6 colors, it is possible that you will have more than 3 combinations, unless you are working in a very controlled area. The first time I tried working WITH CC I used red & green, and was surprised how many objects were detected. So I added another color, thinking that would make detection more limited. But it made it worse, since it detected all the 2 color combinations, and any 3 color combinations.

In your case it will detect 3, 4, and 5 color combinations as well. Then you will have to use the octal value of the CC number to pick out the ones you want. When programming, it would be best to know which Cc numbers you want, figure out the octal digits, and convert them to the number base your program uses, and just save locations with those values.

I am sorry, but I can’t give you Arduino example code since I don’t use that microprocessor.

Tom

thank you, this gives me an idea what I might not have understood yet, but unfortunately I’m not much wiser now how to detect CCs in my Arduino code - admittedly, regrettably.

It should work like detecting the x,y positions of signatures 1-7 which come in successively by
pixy.blocks[ j].x
pixy.blocks[ j].y

I expect to have access to something like
pixy.blocks[ j].x
pixy.blocks[ j].y
also for colorcodes 1-7, successively.

By PixyMon I can store 7 different CCs, and I want them to be detected just like I stored them!
and then I want all the positions on the Screen where they (and just they) might have appeared in the room.

Maybe just the developers can tell:

@developers++: how can I get all these in an easy, intuitive way by Arduino Sketch C code ?

Hi Helmut,
Like Tom described, the color codes signatures use base-8 representation (octal).

There are more than 7 color codes… there can be up to 5 color coded “digits”, each being signatures 1 through 7. This can be confusing. It’s a more advanced feature.

You’ve probably seen this page (but just in case)
http://cmucam.org/projects/cmucam5/wiki/Using_Color_Codes

The Arduino returns color coded blocks after the regular blocks. You can observe this when you run the hello_world example.

thanks!

so if I got 100 blocks by different signatures (pixy.blocks[ j], j<=100)
then the CCs are by pixy.blocks[ j], j >=101?

That is correct.

aah, ok, that makes sense.
another user wrote, the CCs are sent by pixy.blocks[ 0] what I couldn’t understand.

I’ll try and see immediately what readings I’ll get for the last polled ones then, not for the first one.

thanks!

Helmut,
When I tried ColorCodes, I found that because I was using a slow interface, that before I received any CC that the Frame had restarted and all I got was regular color signatures. So I started using color code mode 2 – ColorCodes only.

Since you get 100 color signatures it seems like you are using a fast interface. But if you don’t need the regular color signatures (or just want to test colorcodes), you might try mode 2.

Tom

hi, thank you for your hint!
actually I’m working in a real-life environment - my house and my garden.

1st: how do you drop signature detection and just get CC data?

2nd, FYI, this is some information about the invironment:
Targeting some big objects by the cam like a green sofa or blue pillows (or for better weather outside, green leaves), most of the 100 blocks are mostly artefacts like colored mosaics caused by shadows and light efffects.
In between and around are multiple different colored objects.
Soeme of them are objects or interest though, like red Coke cans or green wine bottles.

Nevertheless, on the walls and on the floor there are CCs to be detected (charging station, doors, path marks, target points).
I have to avoid red sofas and red pillows and brown and black furniture, but I have to figure out where the CCs are - and the Coke cans and the wine bottles.

The link below (from the wiki) at the end shows the color code modes.

http://www.cmucam.org/projects/cmucam5/wiki/Using_Color_Codes

In pixymon go to the expert tab and set the color code mode to 2 (color codes only). The default is 1 - colorcodes enabled, which also shows the color signatures that are not color codes.

Instead if you read both normal color signatures and color codes, you would have to check the sync word. If it is aa56 it is a color code. The color code number will also be at least a 2 digit octal number.

tom

ah, thank you! I never detected an expert’s tab.
About the sync word thing:
this is not clear to my yet how to use it - I needed many more examples about that to see how to apply it to my own code.

I strongly hope that the developers will provide us with many more code examples for all this stuff!
No hobby programmer is supposed to figure out all these details just on his own !

Many people have found the porting guide to be helpful — it walks you through porting Pixy to a new controller including code examples:
http://cmucam.org/projects/cmucam5/wiki/Porting_Guide

thank you,
I already realized all this starting at “serial protocol”
http://cmucam.org/projects/cmucam5/wiki/Porting_Guide#The-serial-protocol

  • but I honestly don’t understand a single word. This is far too low-level and high-tech.

I don’t even know what a frame is and why to count 10 or 50 or what getword or back-to-back or sync or g_blocktype are needed for or why I have to fiddle around with little endians (I heard of it, but nevertheless that’s not the programming skill I’m used to).

What I understand is just

typedef struct  
{
  uint16_t signature; 
  uint16_t x;
  uint16_t y;
  uint16_t width;
  uint16_t height;
  uint16_t angle; // angle is only available for color coded blocks
} Block;

anything else is far too complicated. I’m not interested in frames and syncs and endians or indians.

I would need a high level API just like by hello_world.ino, but more detailed about sorting of signatures and colorcodes.
I’m not interested in how the cam or the serial interface works, I just want to poll and sort blobs (blocks) and want to track them in case they are moving.

Maybe a tutorial providing some sceen shots of the cooked video of PixyMon, showing some colored objects and some ColorCodes.
And then showing the related data which come in to Arduino by which order of colorID and colorcode and size and location using a function just like in hello_world.ino repeatedly.

Hi Helmut,
The hello_world example is the best place to start (that’s why it’s called hello world!) You just plug Pixy into your Arduino and run it. Start there! Take this program and modify it. You don’t need to understand any protocols to use it and you don’t even need to be a skilled programmer to understand what it’s doing.

Still, there are some notes about its code structure here:
http://cmucam.org/projects/cmucam5/wiki/Hooking_up_Pixy_to_a_Microcontroller_(like_an_Arduino)

If you have specific questions about the hello_world program, please ask them. It’s likely that you aren’t the first person with these questions, so ask, but try to be specific.

Look at the output of hello_world. Teach Pixy some color codes, notice how the output changes. Change some config parameters (like the color code mode) and see how the output changes…

I’m not sure what your setup is — you are using an Arduino, I know that, but you’ve been asking questions about getting multiple Arduinos communicating over SPI. This is more complicated! If you are uneasy about programming, tackling these more advanced use cases (like multiple pixys) is probably going to be overwhelming. Start simple!

thanks!

no, I’m not using many Arduinos all at once - why do think I’d do?
Of course I started by hello_world: I mentioned that several times!
But I can’t clearaly see, at what time I’m receiving signature data and when - which - colorcode data.
Addionally there seem to be cc issues about the current FW.
this is my code - it displays the block data on a local TFT .
Just tell me how to insert 1 line or 2, how to identify cc IDs and cc (x,y) block positions:

// pixy-cam LCDTFT monitoring program
// pixyTFTSPI
// Pixy Cam connected by SPI
// version 0008

#include  
#include 
#include 

// UTFT myGLCD(Model,SDA,SCL,CS,RST,RS)
// adjust the model parameter to suit the display module!
UTFT     myGLCD(QD220A,43,42,41,0,40); 
extern   uint8_t   SmallFont[];
uint8_t    ScrRatio;

Pixy pixy;

void setup()
{

  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);

  pixy.init();
  //pixy.blocks[i].x The x location of the center of the detected object (0 to 319)
  //pixy.blocks[i].y The y location of the center of the detected object (0 to 199)
  // Pixy_maxSize/(GLCD_maxSize-frame)
  ScrRatio=max(320/(myGLCD.getDisplayXSize()-20), 200/(myGLCD.getDisplayYSize()-20) )+1;

  myGLCD.clrScr(); 
  Serial.begin(19200);

}

uint16_t sigcolor( uint8_t signature) {  // <<<<<<<<<<<<<<< customize !! <<<<<<<<<<
  uint16_t color;
  if(signature==1) color=VGA_RED;      // light red
  else
  if(signature==2) color=VGA_AQUA;     // light blue
  else
  if(signature==3) color=VGA_YELLOW;   // just yellow ;)
  else
  if(signature==4) color=VGA_LIME;     // light green
  else
  if(signature==5) color=VGA_FUCHSIA;  // light pink 
  else
  if(signature==6) color=VGA_BLUE;     // dark blue
  else
  if(signature==7) color=VGA_PURPLE;   // dark pink
  else
  color=VGA_WHITE;
  return color;
}

char sbuf[240];
#define maxblocks  64
uint8_t    blockS[maxblocks];
uint8_t    blockX[maxblocks];
uint8_t    blockY[maxblocks];
uint8_t    blockW[maxblocks];
uint8_t    blockH[maxblocks];

void loop()
{
  static int i = 0;
  int j;
  uint16_t   nblocks;
  uint8_t    x1,y1,x2,y2; 

  nblocks = pixy.getBlocks();

  if (nblocks)
  {
    i++;

    if (i % 10==0)
    {
      myGLCD.clrScr();
      sprintf(sbuf, "Detected %d:\n", nblocks);
      Serial.print(sbuf);
      for (j=0; j<min(nblocks,maxblocks); j++)
      {       

        sprintf(sbuf, "  block %d: ", j);
        Serial.print(sbuf);
        pixy.blocks[j].print();   

        blockS[j]= pixy.blocks[j].signature;
        blockX[j]= pixy.blocks[j].x;
        blockY[j]= pixy.blocks[j].y;
        blockW[j]= pixy.blocks[j].width;
        blockH[j]= pixy.blocks[j].height;

        myGLCD.setColor(sigcolor(blockS[j])); myGLCD.setBackColor(VGA_BLACK);
        x1=blockX[j]-blockW[j]/2;
        x2=blockX[j]+blockW[j]/2;
        y1=blockY[j]-blockH[j]/2;
        y2=blockY[j]+blockH[j]/2;
        myGLCD.drawRect(x1/ScrRatio, y1/ScrRatio, x2/ScrRatio, y2/ScrRatio );

        sprintf(sbuf, "%d", blockS[j]); 
        myGLCD.print(sbuf, (x1+10)/ScrRatio,(y1+10)/ScrRatio);

      }
    }
  } 
}

I’m not aware of any color code issues with the current firmware (please describe).

It sounds like you are asking how to tell regular blocks from color coded blocks? Sorry — I’m still having trouble understanding what your question is… posting your code without any other comments is not helpful!

The color code blocks have signature numbers greater than 7, ie

if (blocks[j].signature > 7)
serial.println(“color code block!”);
else
serial.println(“regular block!”);

yes I want to seperate signatures from CCs.The problem is that you haven’t documented these details unequivocally in any code example besides hello_world.ino.

Anyone posted that signature 7 don’t work.

ok, if CCs have signatures >7 then signature 7 is no issue.

I think my question should be easy to be understood -
my code displays the block data on a local TFT .
Just tell me how to insert 1 line or 2, how to identify cc IDs and cc (x,y) block positions!

I’d need a function to decode the CC number into the 2 related colors and the concerning stored CC ID (I don’t understand this “octal” thing and what I’ll get as a result).
And I want to detect them by position (x,y) and by it’s CC number when a CC is detected like in this foto:

!http://i74.photobucket.com/albums/i241/cmucam/cc_zps767834e4.jpg!

In PixyMon I can see there are 7 “codes” to store color codes, just like 7 signatures to store colors.

And now imagine I have multiples of either CC and multiples of different CCs.
Unfortunately you don’t provide a guide and code how to define, how to retrieve and how to handle these CC data e.g. in order to display them on a local display and make them appear like on the PixyMon screenshot above.