Пример #1
0
"""
This demo is used to find missing pills in a blister type of package
it would be used in quality control in manufacturing type of application
were you are verifying that the correct number of pills are present
"""

from simplecv.api import Image, Color, Blob

pillcolor = (153, 198, 252)  # This is set manually, you could either open the image you want and pick the color,
                             # or use blob detection to find the blob and do .mean_color() to get the RGB value
i = Image("pills.png", sample=True)
expected_pillcount = 12
saturation_threshold = 40  # This is how much saturation to allow in the image
pill_size = 100  # The size of the expected pills in pixels
packblobs = i.find(Blob, minsize=10)  # find the bright silver on back background, easy


# run through the list of pills (blobs) found and check their color and markup the image when they are found
for idx in range(len(packblobs)):
    pack = packblobs[idx].crop()

    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)
to think of this is if you played the card matching game, the cards would
pretty much have to be identical.  The template method doesn't allow much
for the scale to change, nor for rotation.  This is the most basic pattern
matching SimpleCV offers.  If you are looking for something more complex
you will probably want to look into img.find()
"""
print __doc__

import time

from simplecv.api import Image, Color, TemplateMatch

source = Image("templatetest.png", sample=True)  # the image to search
template = Image("template.png",
                 sample=True)  # the template to search the image for
t = 5

methods = [
    "SQR_DIFF", "SQR_DIFF_NORM", "CCOEFF", "CCOEFF_NORM", "CCORR", "CCORR_NORM"
]  # the various types of template matching available

for m in methods:
    img = Image("templatetest.png", sample=True)
    img.dl().text("current method: {}".format(m), (10, 20), color=Color.RED)
    fs = source.find(TemplateMatch, template, threshold=t, method=m)
    for match in fs:
        img.dl().rectangle((match.x, match.y), (match.width, match.height),
                           color=Color.RED)
    img.apply_layers().show()
    time.sleep(3)
Пример #3
0
This demo is used to find missing pills in a blister type of package
it would be used in quality control in manufacturing type of application
were you are verifying that the correct number of pills are present
"""

from simplecv.api import Image, Color, Blob

pillcolor = (
    153, 198, 252
)  # This is set manually, you could either open the image you want and pick the color,
# or use blob detection to find the blob and do .mean_color() to get the RGB value
i = Image("pills.png", sample=True)
expected_pillcount = 12
saturation_threshold = 40  # This is how much saturation to allow in the image
pill_size = 100  # The size of the expected pills in pixels
packblobs = i.find(
    Blob, minsize=10)  # find the bright silver on back background, easy

# run through the list of pills (blobs) found and check their color and markup the image when they are found
for idx in range(len(packblobs)):
    pack = packblobs[idx].crop()

    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
"""
This example uses the built in template matching.  The easiest way
to think of this is if you played the card matching game, the cards would
pretty much have to be identical.  The template method doesn't allow much
for the scale to change, nor for rotation.  This is the most basic pattern
matching SimpleCV offers.  If you are looking for something more complex
you will probably want to look into img.find()
"""
print __doc__

import time

from simplecv.api import Image, Color, TemplateMatch


source = Image("templatetest.png", sample=True) # the image to search
template = Image("template.png", sample=True) # the template to search the image for
t = 5

methods = ["SQR_DIFF", "SQR_DIFF_NORM", "CCOEFF",
           "CCOEFF_NORM", "CCORR", "CCORR_NORM"]  # the various types of template matching available

for m in methods:
    img = Image("templatetest.png", sample=True)
    img.dl().text("current method: {}".format(m), (10, 20), color=Color.RED)
    fs = source.find(TemplateMatch, template, threshold=t, method=m)
    for match in fs:
        img.dl().rectangle((match.x, match.y), (match.width, match.height), color=Color.RED)
    img.apply_layers().show()
    time.sleep(3)