For reference if anyone needs it:
# Use the Tool->Machine Vision->Threshold Editor to determine these
dice_color=(30, 100, -40, 0, -10, 10)
pip_color=(30, 100, -40, 0, -10, 10)
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(10)
sensor.set_auto_whitebal(False)
clock = time.clock()
green = (0, 210, 0)
black = (0, 0, 0)
blue = (0, 0, 200)
while(True):
clock.tick()
img = sensor.snapshot()
blobs = img.find_blobs([dice_color])
total = 0
if blobs:
for b in blobs:
pipcount = 0
pips = img.find_blobs([pip_color], roi=b.rect())
for p in pips:
img.draw_rectangle(p.rect(), color=blue, thickness=1)
pipcount+=1
img.draw_rectangle(b.rect(), color=blue, thickness=1)
img.draw_cross(b.cx(), b.cy(), color=blue, thickness=1)
img.draw_string(b.x(), b.y(), str(pipcount), color=black)
total+=pipcount
img.draw_string(10, 10, "total=%d" % total, color=black, monospace=False)
print(clock.fps())