Exemplo n.º 1
0
def recognise(image, addr, extras):
    result = ""
    x = image.width - 1
    channels = getChannels(image)
    bestBounds = []
    #cv.NamedWindow("pic", 1)
    #cv.NamedWindow("cols", 0)
    while len(result) < nSegs and x >= minW:
        x = cap.getBound(image, cap.CAP_BOUND_RIGHT, start=x)
        ratings = []
        for w in xrange(minW, min(maxW + 1, x)):
            bounds = findBounds(image, x, w)
            subImage = cap.getSubImage(image, bounds)
            flags = findColors(subImage)
            for index, flag in enumerate(flags):
                if not flag: continue
                seg = getSegment(channels[index], image, bounds)
                seg = cap.flattenImage(adjustSize(seg, segSize))
                guesses = ann.run(seg)
                charIndex = cap.argmax(guesses)
                ratings.append((guesses[charIndex], charIndex, index, bounds, seg))
        best = max(ratings, key=itemgetter(0))
        result += charset[best[1]]
        bestChannel = channels[best[2]]
        cv.SetImageROI(bestChannel, best[3])
        cv.Set(bestChannel, 96, bestChannel)
        cv.ResetImageROI(bestChannel)
        bestBounds.append(best[3])
        bestW = best[3][2]
        x -= bestW
        #print ann.run(best[4])
    cap.processExtras([cap.drawComponents(image, bestBounds)], addr, extras, cap.CAP_STAGE_RECOGNISE)
    return result[::-1]
Exemplo n.º 2
0
def recognise(image, addr, extras):
    result = ""
    x = image.width - 1
    channels = getChannels(image)
    bestBounds = []
    #cv.NamedWindow("pic", 1)
    #cv.NamedWindow("cols", 0)
    while len(result) < nSegs and x >= minW:
        x = cap.getBound(image, cap.CAP_BOUND_RIGHT, start=x)
        ratings = []
        for w in xrange(minW, min(maxW + 1, x)):
            bounds = findBounds(image, x, w)
            subImage = cap.getSubImage(image, bounds)
            flags = findColors(subImage)
            for index, flag in enumerate(flags):
                if not flag: continue
                seg = getSegment(channels[index], image, bounds)
                seg = cap.flattenImage(adjustSize(seg, segSize))
                guesses = ann.run(seg)
                charIndex = cap.argmax(guesses)
                ratings.append(
                    (guesses[charIndex], charIndex, index, bounds, seg))
        best = max(ratings, key=itemgetter(0))
        result += charset[best[1]]
        bestChannel = channels[best[2]]
        cv.SetImageROI(bestChannel, best[3])
        cv.Set(bestChannel, 96, bestChannel)
        cv.ResetImageROI(bestChannel)
        bestBounds.append(best[3])
        bestW = best[3][2]
        x -= bestW
        #print ann.run(best[4])
    cap.processExtras([cap.drawComponents(image, bestBounds)], addr, extras,
                      cap.CAP_STAGE_RECOGNISE)
    return result[::-1]
Exemplo n.º 3
0
def findBounds(image, right, w):
    left = right - w + 1
    cols = cv.GetCols(image, left, right + 1)
    top    = cap.getBound(cols, cap.CAP_BOUND_TOP)
    bottom = cap.getBound(cols, cap.CAP_BOUND_BOTTOM)
    return (left, top, w, bottom - top)
Exemplo n.º 4
0
def findRect(image, left, right):
    cols = cv.GetCols(image, left, right)
    top    = cap.getBound(cols, cap.CAP_BOUND_TOP, colthresh=128)
    bottom = cap.getBound(cols, cap.CAP_BOUND_BOTTOM, colthresh=128)
    return (left, top, right - left, bottom - top)
Exemplo n.º 5
0
def findRect(image, left, right):
    cols = cv.GetCols(image, left, right)
    top = cap.getBound(cols, cap.CAP_BOUND_TOP, colthresh=128)
    bottom = cap.getBound(cols, cap.CAP_BOUND_BOTTOM, colthresh=128)
    return (left, top, right - left, bottom - top)
Exemplo n.º 6
0
def findBounds(image, right, w):
    left = right - w + 1
    cols = cv.GetCols(image, left, right + 1)
    top = cap.getBound(cols, cap.CAP_BOUND_TOP)
    bottom = cap.getBound(cols, cap.CAP_BOUND_BOTTOM)
    return (left, top, w, bottom - top)