Help on OpenMV output

Hello,

I am just getting started with OpenMV, sorry if some of these questions are basic.

I was previously using a Pixy communicating over I2C to a teensy 3.1.

I would like to do a similar thing with OpenMV – track color codes and output x,y and width,height of the tracked color codes over I2C or another interface.

So far:

I’ve successfully run the marker tracking script, and modified the color ranges so that I am getting excellent color code identification!

  1. Can someone explain how the color code identifiers get built? I have tried a 4 color combination (red,green,blue,orange) and when the OpenMV cam identifies it, it gets labeled “15” – is this some octal result?
  2. Could someone help with some sample code of how I could set up multiple different color codes? For example when red/green is identified that would be one code, and when blue/orange gets identified that would be another?
    3.Finally, I would really appreciate if someone could give some example of how to output the x,y and width,height of the color codes over i2c or another interface.

Thanks so much!

OK, I see this now:

Each blob that find_blobs returns has a bit in a bitmask set for the color

that blob was produced by which was passed to find_blobs. E.g. if you pass

find blobs 3 colors then you’ll get blobs with possibly a color value of

(2^0), (2^1), or (2^2). These color values can be or’ed togheter because

they are a single bit each to represent a mutli-colored blob which you

can then classify as a marker.

but still could use some help with it, and the other issues.
Is there a list somewhere of what each component of “b” represents? I.e. b[6] is y coordinate of center.

Thanks for using the system out! We’re like brand new right now which means everything is kinda not documented that well. Anyway,

https://openmv.io/docs/library/omv.image.html#image.image.find_blobs

There’s the doc page.

As for picking the color ranges, the GUI makes this really easy. Just select the color you want to track in the view finder and you’ll see the color histogram. Then you just set the color bounds to be wider than the histogram and you’re done.

As for multiple color code, just pass the find_blobs function four color tuples:

[(lMin, lMax, aMin, aMax, bMin, bMax), (lMin, lMax, aMin, aMax, bMin, bMax), (lMin, lMax, aMin, aMax, bMin, bMax), (lMin, lMax, aMin, aMax, bMin, bMax)]

For red, green, blue and orange. Then call the find_markers function on the output of the find_blobs function to combine overlapping blobs.

Red/green colors will then have a color code of 3 and blue/orange colors will have a color code of 12.

As for the I2C interface. First, you need to add pull ups to the pins. Once you do that, check out the I2C example script (under board control) for how to send I2C data. E.g. in more detail: https://openmv.io/docs/library/pyb.I2C.html.

It’s the same as the MP library for the pyboard.

Thanks for the quick reply!

I could use a little more guidance on the i2c part.

What should the code on the teensy (arduino) end?

Where in the code

print("\n[")
for i in range(16):
    print("\t[", end='')
    for j in range(16):
        print("%03d" % mem[(i*16)+j], end='')
        if j != 15: print(", ", end='')
    print("]," if i != 15 else "]")
print("]")

do i put the data that I want to send out?
Is it continually sending out or do I need to send a request from the master? An example of both ends (openMV and arduino) would really help me out.

The I2C command is in the one line that does the memory read. It’s near the top of the script.

Di you read the help link? https://openmv.io/docs/library/pyb.I2C.html.

See another example here: https://openmv.io/docs/openmvcam/quickref.html#i2c-bus.

Anyway, I don’t have a teensy. So, I can;t help on that part. I do know that the OpenMVCam has to be the master. So, I’d code the OpenMV Cam to keep sending the data out.

Make sure to add pull ups to the I2C lines.

I can try to make a demo this weekend.

Could you use async serial? That works really well for this.

Thanks for the reply - a demo would be really helpful.

Teensy is just a high performance arduino, so code would essentially be the same as an arduino on that end- any help there would be greatly appreciated as well.

Serial could possibly work, would appreciate any help on that too.

Okay, I’ll give you a serial example tonight.

Was quite happy when writing this example. Everything worked well… yay!

# Import modules...
import pyb, sensor, image, time

# User Thresholds
red_threshold   = (   35,   60,   55,   85,   35,   65)
blue_threshold  = (    5,   40,  -15,   40,  -70,    5)
green_threshold = (   15,   35,  -65,    0,    5,   40)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(10)

# You need to turn this off.
sensor.set_whitebal(False)

uart = pyb.UART(3, 115200) # BAUD RATE
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()

    blobs = img.find_markers(img.find_blobs([red_threshold, blue_threshold, green_threshold]))
    if blobs:
        uart.write("Blobs Found\r\n")
        for b in blobs:
            # Draw a rect around the blob.
            img.draw_rectangle(b[0:4]) # rect
            img.draw_cross(b[5], b[6]) # cx, cy
            # Draw the color label. b[8] is the color label (documentation is wrong here).
            img.draw_string(b[0]+2, b[1]+2, "%d" % b[8])
            uart.write("x %d,y %d,w %d,h %d,pixels %d,cx %d,cy %d,angle %f,code %d,blobs %d\r\n" % b)
    else:
        uart.write("No Blobs Found\r\n")

    # Print FPS
    print(clock.fps())

blobs_0.jpg
blobs_1.jpg
blob_and_serial_tracking.py (1.19 KB)

Thanks! I’ll work with this and let you know how it goes.