예제 #1
0
def crop(path, shape, x, y, w, h):
    """Crop image with rectangle

    :param path: an image path
    :param shape: some shape type
    :param x: rect x origin
    :param y: rect y origin
    :param w: rect w size
    :param h: rect h size
    """
    shape = (x, y, w, h)
    img = Img(path)
    cropped = img.crop(shape)
    out = new_name(path, 'crop')
    cropped.save(out)
    sys.stdout.write('%s\n' % out)
예제 #2
0
def average(*images):
    """Perform an averaging over the set of images
    count = len(images)
    for image in images:
        cv.addWeighted(average, 1, image, 1/count, 0, average)
    """
    if not len(images):
        return None

    fpath = images[0]
    first = Img(fpath)
    sz = first.size
    sizetup = sz.to_tuple()
    moving_average = cv.CreateImage(sizetup, 32, 1)
    result = cv.CreateImage(sizetup, 8, 1)
    count = 1
    result = first.cv_rep()
    for path in images:
        img = Img(path)
        rep = img.resize(sz)
        cv.RunningAvg(rep, moving_average, 1. / float(count), None)
        count += 1
    cv.ConvertScaleAbs(moving_average, result)
    out = new_name(fpath, 'average')
    cv.SaveImage(out, result)
    sys.stdout.write('%s\n' % out)
    return result
예제 #3
0
파일: detect.py 프로젝트: jiapei100/lmb
def img_url(url, detect=True):
    if not url:
        return []
    img = Img(url)
    img.faces = faces_img(img)
    return img