Pip Counting Code

OpenMV related project discussion.
User avatar
kwagyeman
Posts: 3209
Joined: Sun May 24, 2015 2:10 pm

Pip Counting Code

Postby kwagyeman » Sun Feb 24, 2019 11:52 pm

For reference if anyone needs it:

Code: Select all

# 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())
Nyamekye,
merriecook
Posts: 1
Joined: Thu Mar 14, 2019 8:49 am

Re: Pip Counting Code

Postby merriecook » Thu Mar 14, 2019 8:52 am

I will be following your code using the tool, thanks for sharing. I appreciate your kind assistance! Pip counting methods are becoming popular nowadays!
User avatar
Clemz
Posts: 6
Joined: Sat Feb 16, 2019 9:45 am
Location: Rennes
Contact:

Re: Pip Counting Code

Postby Clemz » Fri Mar 15, 2019 9:19 am

yes thx Kwagyeman !

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests