Exemplo n.º 1
0
def segment(image, addr, extras):
    log = cap.logger(extras, image)
    components = findComponents(image, log)
    log.log(cap.drawComponents(image, components))
    angles = map(lambda comp: findAngle(comp, log), components)
    angles = filter(lambda angle: angle != 0.0 and abs(angle) <= 27.0, angles)
    if len(angles) != 0:
        angle = fsum(angles) / len(angles)
        image = cap.doRotate(image,
                             -angle,
                             fillval=255,
                             interpolation=cv.CV_INTER_NN)
        log.log(image)
        components = findComponents(image)
    assert (len(components) <= nSegs)
    log.log(cap.drawComponents(image, components))
    #components = cap.spltCCs(components, cap.partsFromnSegs5(components), projRadius=5, thresh=2)
    #components = filtCCs(components, (15, 15), 200, 0.2)
    components = map(lambda comp: addBackground(comp, image, bgcolor=96),
                     components)
    segments = map(lambda comp: comp[3], components)
    segments = map(removeBadBackground, segments)
    log.log(cap.joinImagesH(segments))
    segments = map(lambda seg: cap.smoothNoise1(seg, bgcolor=0), segments)
    log.log(cap.joinImagesH(segments))
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_SEGMENT)
    return segments
Exemplo n.º 2
0
def preprocess(image, addr, extras):
    log = cap.logger(extras, image)
    image = removeLightColors(image)
    log.log(image)
    image = remapColors(image)
    log.log(image)
    image = smoothNoise2(image)
    log.log(image)
    image = cap.smoothNoise1(image)
    log.log(image)
    mask = getNoiseMask(image, 15, 4)
    cv.Or(mask, findColor(image, myunkn), mask)
    log.log(mask)
    image = doInpaint(image, mask)
    log.log(image)
    image = sharpenColors(image)
    log.log(image)
    image = cap.repaintCCs(image, doRepaint=lambda comp, col: comp[0] <= 5 or comp[2][2] <= 2 or comp[2][3] <= 2)
    log.log(image)
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_PREPROCESS)
    return image
Exemplo n.º 3
0
Arquivo: segment.py Projeto: woto/EPC
def segment(image, addr, extras):
    log = cap.logger(extras, image)
    components = findComponents(image, log)
    log.log(cap.drawComponents(image, components))
    angles = map(lambda comp: findAngle(comp, log), components)
    angles = filter(lambda angle: angle != 0.0 and abs(angle) <= 27.0, angles)
    if len(angles) != 0:
        angle = fsum(angles) / len(angles)
        image = cap.doRotate(image, -angle, fillval=255, interpolation=cv.CV_INTER_NN)
        log.log(image)
        components = findComponents(image)
    assert(len(components) <= nSegs)
    log.log(cap.drawComponents(image, components))
    #components = cap.spltCCs(components, cap.partsFromnSegs5(components), projRadius=5, thresh=2)
    #components = filtCCs(components, (15, 15), 200, 0.2)
    components = map(lambda comp: addBackground(comp, image, bgcolor=96), components)
    segments = map(lambda comp: comp[3], components)
    segments = map(removeBadBackground, segments)
    log.log(cap.joinImagesH(segments))
    segments = map(lambda seg: cap.smoothNoise1(seg, bgcolor=0), segments)
    log.log(cap.joinImagesH(segments))
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_SEGMENT)
    return segments
Exemplo n.º 4
0
def preprocess(image, addr, extras):
    log = cap.logger(extras, image)
    image = removeLightColors(image)
    log.log(image)
    image = remapColors(image)
    log.log(image)
    image = smoothNoise2(image)
    log.log(image)
    image = cap.smoothNoise1(image)
    log.log(image)
    mask = getNoiseMask(image, 15, 4)
    cv.Or(mask, findColor(image, myunkn), mask)
    log.log(mask)
    image = doInpaint(image, mask)
    log.log(image)
    image = sharpenColors(image)
    log.log(image)
    image = cap.repaintCCs(image,
                           doRepaint=lambda comp, col: comp[0] <= 5 or comp[2][
                               2] <= 2 or comp[2][3] <= 2)
    log.log(image)
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_PREPROCESS)
    return image