« Previous - Version 6/27 (diff) - Next » - Current version
Rich LeGrand, 01/15/2015 04:11 pm

Teach Pixy an Object

Teaching Pixy an object is super easy, but first let's talk about which objects will work well with Pixy. Pixy uses a hue-based color filtering algorithm to detect objects. Since Pixy uses hue (color), the object needs to have a distinct hue. Here are some objects that are good because they have good, distinct hues.

Here are some bad objects because either there is no hue (black, white or gray) or the hue is not distinct.

Keeping these guidelines in mind, choose an object to teach Pixy. (Apply power to Pixy via battery or USB cable if you haven't already. When you power up Pixy, it will go through a series of LED flashes. Wait for the led to turn off before teaching Pixy.) Hold down the button on top of Pixy. After about 1 second, the LED will turn on, first white, then red, then other colors, but when it turns red, release the button.

When you release the button, Pixy will enter what's called "light pipe" mode, where the LED color is the color of the object that Pixy has "locked" onto. Pixy will lock onto objects in the center of its video frame, so hold the object directly in front of pixy between 6 and 20 inches from the lens. Pixy uses a region growing algorithm to try to determine which pixels are part of your object and which pixels are part of the background. Pixy uses these pixels to create a statistical model of your object so it can detect it reliably under different lighting conditions. Use the LED color as feedback to determine if Pixy has a good lock on the object, and use the following guidelines to judge:

  1. When Pixy has locked onto your object, the LED color should match the color of your object.
  2. The brighter the LED, the better the lock. Move the object a little and see if you can maximize the LED brightness.

A good lock means a good statistical model of your object. When you are satisfied, press and release the button, like you'd click your mouse. The LED will flash a couple times indicating that Pixy has now "learned" your object. It will now start tracking your object (or objects).

The video below is a good short "how-to" regarding teaching Pixy objects.


Multiple Signatures

Pixy can learn up to seven color signatures. We can teach Pixy the 1st color signature by releasing the button when the LED turns red. If we continue to hold down the button, the LED will turn orange, yellow, etc., indicating the remaining color signatures. Here are the signatures in order:

  1. Red
  2. Orange
  3. Yellow
  4. Green
  5. Cyan (light blue)
  6. Blue
  7. Violet

The color signature number is determined by when you release the button. Release the button when the LED is yellow and you're teaching signature 3. Release the button when the LED is blue and you're teaching signature 6. These colors are not related to the hue of the object. The colors are used only to indicate the signature number. So, for example, signature 1 can be a yellow object, even though signature 1 is indicated by a red LED, and signature 2 could be a pink object even though signature 2 is indicated by an orange LED.

Other Notes

After you teach Pixy a signature, it saves the signature in flash, so when you power cycle your Pixy, it will remember the signatures you taught it and continue to track objects that match these signatures.

If you accidentally find yourself teaching signature 2 when you meant to teach signature 1 (i.e. you released the button when it was orange instead of read), for example, just hold down the button until the LED turns off. This is how you tell Pixy to cancel teach mode. You can then start over by holding the button down again.

White Balance

Some types of lighting (such as incandescent) have a reddish hue and others (such as fluorescent) have a bluish hue. The lighting can affect your color signatures. For example, if you teach an object under incandescent lighting and move into a room with fluorescent lighting, the color signatures will likely no longer work as well. You can either re-teach all signatures or you can adjust the white balance.

When you first apply power to Pixy, it will spend the first 5 or so seconds determining the correct white balance to use. It will then disable automatic white balance. If you wish to readjust the white balance, hold down the button until the LED turns white and release. It happens quickly, so be prepared! Pixy is now in automatic white balance mode. You can hold a white sheet of paper in front of Pixy so Pixy can adjust the white balance. It only takes 2 or 3 seconds to adjust the white balance, after which you can press and release the button (like a mouse click). The LED will flash, indicating success, and now Pixy is "rebalanced".

Teach through PixyMon

You can also teach Pixy an object through PixyMon. This may be useful if the object you want to teach is small or if you want more control over which pixels are used for teaching. Begin by plugging in the USB cable between Pixy and your computer and running PixyMon.

Now hold the object you want to teach in front of Pixy and select Action➜Set signature 1 from the pulldown menu.

Now select you region you want Pixy to use to learn the object.

That's it! After you select the region, Pixy will "learn" the object and automatically go into "cooked" video mode so can verify how well your color signature is working.

Signature tuning

You can teach Pixy other objects in this way, up to seven total color signatures are possible. Note that Pixy always saves color signatures in flash, so they will be available the next time you apply power to Pixy.

If you haven't already, from here you might be interested in hooking Pixy up to a microcontroller.