コード例 #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
コード例 #2
0
ファイル: preprocess.py プロジェクト: woto/EPC
def preprocess(image, addr, extras):
    log = cap.logger(extras, image)
    image = cap.doResize(image, factor, cv.CV_INTER_CUBIC)
    log.log(image)
    image = undistort(image)
    log.log(image)
    cv.Threshold(image, image, 200, 255, cv.CV_THRESH_BINARY)
    log.log(image)
    image = cap.repaintCCs(image, doRepaint=lambda comp, col: comp[0] <= 10 and col <= 128)
    log.log(image)
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_PREPROCESS)
    return image
コード例 #3
0
ファイル: segment.py プロジェクト: woto/EPC
def segment(image, addr, extras):
    clone = cv.CloneImage(image)
    log = cap.logger(extras, image)
    components = cap.findCCs(image, erasecol=0, doContinue=None, doSkip=lambda comp: comp[0] <= 25)
    log.log(cap.drawComponents(clone, components))
    if len(components) != nSegs:
        components = cap.joinCCs(components, cap.rectsIntersectH)
        log.log(cap.drawComponents(clone, components))
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_SEGMENT)
    assert(len(components) == nSegs)
    segments = map(lambda comp: comp[3], components)
    return segments
コード例 #4
0
def preprocess(image, addr, extras):
    log = cap.logger(extras, image)
    image = cap.doResize(image, factor, cv.CV_INTER_CUBIC)
    log.log(image)
    image = undistort(image)
    log.log(image)
    cv.Threshold(image, image, 200, 255, cv.CV_THRESH_BINARY)
    log.log(image)
    image = cap.repaintCCs(
        image, doRepaint=lambda comp, col: comp[0] <= 10 and col <= 128)
    log.log(image)
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_PREPROCESS)
    return image
コード例 #5
0
def preprocess(image, addr, extras):
    log = cap.logger(extras, image)
    alpha, dark = rotAngle(image)
    log.log(dark, False)
    clear = clearNoise(image)
    log.log(clear, False)
    straight = cap.doRotate(clear, -alpha, fillval=0, resize=False, interpolation=cv.CV_INTER_NN)
    #cv.Threshold(straight, straight, 128, 255, cv.CV_THRESH_BINARY)
    log.log(straight)
    cv.Dilate(straight, straight)
    cv.Erode(straight, straight)
    log.log(straight)
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_PREPROCESS)
    return straight
コード例 #6
0
def segment(image, addr, extras):
    clone = cv.CloneImage(image)
    log = cap.logger(extras, image)
    components = cap.findCCs(image,
                             erasecol=0,
                             doContinue=None,
                             doSkip=lambda comp: comp[0] <= 25)
    log.log(cap.drawComponents(clone, components))
    if len(components) != nSegs:
        components = cap.joinCCs(components, cap.rectsIntersectH)
        log.log(cap.drawComponents(clone, components))
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_SEGMENT)
    assert (len(components) == nSegs)
    segments = map(lambda comp: comp[3], components)
    return segments
コード例 #7
0
def segment(image, addr, extras):
    log = cap.logger(extras, image)
    clone = cv.CloneImage(image)
    components = cap.findCCs(image, 0, lambda col: col <= 128, lambda comp: comp[0] < 10)
    log.log(cap.drawComponents(clone, components), False)
    components = cap.joinCCs(components, cap.rectsIntersectH)
    log.log(cap.drawComponents(clone, components), False)
    assert(len(components) <= nSegs)
    parts = cap.partsFromnSegs5(components)
    components = cap.spltCCs(components, parts, projRadius=4, thresh=1)
    log.log(cap.drawComponents(clone, components), False)
    segments = map(lambda comp: comp[3], components)
    log.log(cap.joinImagesH(segments), False)
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_SEGMENT)
    return segments
コード例 #8
0
ファイル: segment.py プロジェクト: Pastafarianist/captchure
def segment(image, addr, extras):
    clone = cv.CloneImage(image)
    log = cap.logger(extras, image)
    components = cap.findCCs(image, erasecol=255, doContinue=lambda col: col == 255, doSkip=lambda comp: comp[0] <= 20)
    #components = cap.spltCCs(components, cap.partsFromSegW(components, 20), projRadius=5, thresh=1)
    log.log(cap.drawComponents(clone, components))
    while len(components) > nSegs:
        smallest = cap.argmin(components, itemgetter(0))
        del(components[smallest])
    assert(len(components) == nSegs)
    log.log(cap.drawComponents(clone, components))
    segments = map(lambda comp: comp[3], components)
    log.log(cap.joinImagesH(segments))
    segments = map(deRotate, segments)
    log.log(cap.joinImagesH(segments))
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_SEGMENT)
    return segments
コード例 #9
0
def preprocess(image, addr, extras):
    log = cap.logger(extras, image)
    alpha, dark = rotAngle(image)
    log.log(dark, False)
    clear = clearNoise(image)
    log.log(clear, False)
    straight = cap.doRotate(clear,
                            -alpha,
                            fillval=0,
                            resize=False,
                            interpolation=cv.CV_INTER_NN)
    #cv.Threshold(straight, straight, 128, 255, cv.CV_THRESH_BINARY)
    log.log(straight)
    cv.Dilate(straight, straight)
    cv.Erode(straight, straight)
    log.log(straight)
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_PREPROCESS)
    return straight
コード例 #10
0
def segment(image, addr, extras):
    clone = cv.CloneImage(image)
    log = cap.logger(extras, image)
    components = cap.findCCs(image,
                             erasecol=255,
                             doContinue=lambda col: col == 255,
                             doSkip=lambda comp: comp[0] <= 20)
    #components = cap.spltCCs(components, cap.partsFromSegW(components, 20), projRadius=5, thresh=1)
    log.log(cap.drawComponents(clone, components))
    while len(components) > nSegs:
        smallest = cap.argmin(components, itemgetter(0))
        del (components[smallest])
    assert (len(components) == nSegs)
    log.log(cap.drawComponents(clone, components))
    segments = map(lambda comp: comp[3], components)
    log.log(cap.joinImagesH(segments))
    segments = map(deRotate, segments)
    log.log(cap.joinImagesH(segments))
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_SEGMENT)
    return segments
コード例 #11
0
ファイル: preprocess.py プロジェクト: woto/EPC
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
コード例 #12
0
ファイル: segment.py プロジェクト: 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
コード例 #13
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
コード例 #14
0
def preprocess(image, addr, extras):
    log = cap.logger(extras, image)
    image = cutLetters(image, 116, log)
    log.log(image)
    cap.processExtras(log.steps, addr, extras, cap.CAP_STAGE_PREPROCESS)
    return image