example = 1
        else:
            example += 1
    else:
        threshold += threshold_step

    if example == 1:
        image = image.erode(threshold)
        text = "Erode Morphology Example: img.erode(" + str(threshold) + ")"

    elif example == 2:
        image = image.dilate(threshold)
        text = "Dilate Morphology Example: img.dilate(" + str(threshold) + ")"

    elif example == 3:
        image = image.morph_open()
        text = "Open Morphology Example: img.morph_open()"

    elif example == 4:
        image = image.morph_close()
        text = "Close Morphology Example: img.morph_close()"

    elif example == 5:
        image = image.morph_gradient()
        text = "Gradient Morphology Example: img.morph_gradient()"
    else:
        text = ''

    image.dl().text(text, (10, 10), color=Color.RED)
    image.show()
Exemplo n.º 2
0
    pills_img = pack.hue_distance(pillcolor, minsaturation=saturation_threshold)
    pills_img = pills_img.binarize(127, inverted=True)

    pills = pills_img.find(Blob, minsize=pill_size)
    if not pills:
        continue

    for p in pills:
        p.image = pack
        p.convex_hull.draw(color=Color.RED, width=5)
    i.dl().blit(pack.apply_layers(), packblobs[idx].points[0])
    packblobs[idx].convex_hull.draw(color=Color.BLUE, width=5)

    pillcount = len(pills)
    if pillcount != expected_pillcount:
        print "pack at %d, %d had %d pills" % (packblobs[idx].x, packblobs[idx].y, pillcount)
        i.dl().text('ERROR', (packblobs[idx].x, packblobs[idx].y + 150), color=Color.RED)
        i.dl().text("Pills Found: " + str(pillcount),
                    (packblobs[idx].x, packblobs[idx].y + 170), color=Color.RED)
        i.dl().text("Pills Expected: " + str(expected_pillcount),
                    (packblobs[idx].x, packblobs[idx].y + 190), color=Color.RED)
    else:
        i.dl().text('OK', (packblobs[idx].x, packblobs[idx].y + 150), color=Color.GREEN)


# Continue to show the image
while True:
    i.show()

Exemplo n.º 3
0
    pills = pills_img.find(Blob, minsize=pill_size)
    if not pills:
        continue

    for p in pills:
        p.image = pack
        p.convex_hull.draw(color=Color.RED, width=5)
    i.dl().blit(pack.apply_layers(), packblobs[idx].points[0])
    packblobs[idx].convex_hull.draw(color=Color.BLUE, width=5)

    pillcount = len(pills)
    if pillcount != expected_pillcount:
        print "pack at %d, %d had %d pills" % (packblobs[idx].x,
                                               packblobs[idx].y, pillcount)
        i.dl().text('ERROR', (packblobs[idx].x, packblobs[idx].y + 150),
                    color=Color.RED)
        i.dl().text("Pills Found: " + str(pillcount),
                    (packblobs[idx].x, packblobs[idx].y + 170),
                    color=Color.RED)
        i.dl().text("Pills Expected: " + str(expected_pillcount),
                    (packblobs[idx].x, packblobs[idx].y + 190),
                    color=Color.RED)
    else:
        i.dl().text('OK', (packblobs[idx].x, packblobs[idx].y + 150),
                    color=Color.GREEN)

# Continue to show the image
while True:
    i.show()
print __doc__

import time
from simplecv.api import Color, Image


sleep_for = 3  # seconds to sleep for
text_point = (20, 20)
font_size = 24
draw_color = Color.YELLOW

while True:
    image = Image("orson_welles.jpg", sample=True)
    image.dl().set_font_size(font_size)
    image.dl().text("Original Size", text_point, color=draw_color)
    image.show()
    time.sleep(sleep_for)

    rot = image.rotate(45)
    rot.dl().set_font_size(font_size)
    rot.dl().text("Rotated 45 degrees", text_point, color=draw_color)
    rot.show()
    time.sleep(sleep_for)

    rot = image.rotate(45, scale=0.5)
    rot.dl().set_font_size(font_size)
    rot.dl().text("Rotated 45 degreesand scaled", text_point, color=draw_color)
    rot.show()
    time.sleep(sleep_for)

    rot = image.rotate(45, scale=0.5, point=(0, 0))
Exemplo n.º 5
0
"""
This program basically functions like a greenscreen that typically
a weather or news reporter would use.  It allows you to super impose
anything standing in front of a "green screen" in front of another image
this should even work with a camera is the user is standing in front
of a green background
"""
print __doc__

import time
from simplecv.api import Image, Color


gs = Image("greenscreen.png", sample=True)
gs.show()
time.sleep(3)
background = Image("icecave.png", sample=True)
background.show()
time.sleep(3)
matte = gs.hue_distance(color=Color.GREEN, minvalue=100).binarize(inverted=True).to_bgr()
matte.show()
time.sleep(3)
result = (gs - matte) + (background - matte.invert())
result.show()
time.sleep(3)
img = Image('coins.jpg', sample=True)
coins = img.invert().find(Blob, minsize=200)

# Here we compute the scale factor
if coins:
    c = coins[-1]
    diameter = c.radius * 2
    size_ratio = quarter_size / diameter

# Now we print the measurements back on the picture
for coin in coins:
    # get the physical size of the coin
    size = (coin.radius * 2) * size_ratio
    # label the coin accordingly
    if 18 < size < 20:
        coin_type = "penny"
    elif 20 < size < 23:
        coin_type = "nickel"
    elif 16 < size < 18:
        coin_type = "dime"
    elif 23 < size < 26:
        coin_type = "quarter"
    else:
        coin_type = "unknown"

    text = "Type: {}, Size: {}mm".format(coin_type, size)
    img.dl().text(text, (coin.x + 45, coin.y + 45), color=Color.BLUE)

img.show()
time.sleep(10)
layer.text("Use w/s keys to change intensity", (50, 50), Color.BLACK)
layer.text("a/d keys to change angle", (50, 75), Color.BLACK)

#draw 6 innocent looking dots
layer.circle((125, 200), 25, Color.RED, 1, True)
layer.circle((250, 200), 25, Color.BLUE, 1, True)
layer.circle((375, 200), 25, Color.GREEN, 1, True)
layer.circle((125, 300), 25, Color.YELLOW, 1, True)
layer.circle((250, 300), 25, Color.ORANGE, 1, True)
layer.circle((375, 300), 25, Color.CYAN, 1, True)

# apply layer
img.add_drawing_layer(layer)
img = img.apply_layers()

img.show()
power = 1
angle = 0
while True:
    key = cv2.waitKey(1)
    if key == -1:
        continue
    print chr(key)

    # detect w,a,s,d key presses and modify power, angle
    if key == ord('w'):
        power += 10
        blur = img.motion_blur2(power, angle)
        blur.show()
    if key == ord('s'):
        power = max(power - 10, 1)