Example #1
0
def AnprLocalised(im, bbox, preProcessedModel):

    if len(preProcessedModel) == 0:
        print "Warning: recognition model is empty"

    #Deskew
    expandedBbox, bestInd, bestAngle = deskew.Deskew(im, bbox)
    #print "expandedBbox", expandedBbox
    deskewedIm = deskew.RotateAndCrop(im, expandedBbox, bestAngle)

    #Split into characters
    scoreIm = deskewMarkedPlates.RgbToPlateBackgroundScore(deskewedIm)
    #misc.imshow(scoreIm)

    charBboxes, charCofGs = detectblobs.DetectCharacters(scoreIm)

    if charBboxes == None or charCofGs == None:
        return None

    #Recognise individual characters
    details = []
    bestGuess = ""
    bestGuessConfidence = []
    for bbx, cofg in zip(charBboxes, charCofGs):
        charScores, candidateImgs = recognisechars.ProcessPatch(
            deskewedIm, bbx, cofg, preProcessedModel)
        #for ch in charScores[:5]:
        #	print ch[0], ch[1]
        details.append(charScores)
        bestChar = charScores[0][1]
        bestGuess += bestChar

        #Look at the ranked results and see the proportion that
        #are in agreement in the top 10
        countAgree = 0
        countTested = 0
        for sc, ch, im, srcId in charScores[1:11]:
            if bestChar == ch:
                countAgree += 1
            countTested += 1

        bestGuessConfidence.append(float(countAgree) / countTested)
    return bestGuess, bestGuessConfidence, details
Example #2
0
        for photoNum, photo in enumerate(plates):
            fina = photo[0]['file']
            reg = photo[1]['reg']
            foundObjId = photo[1]['object']
            if foundObjId == objId:
                break

        bboxes = plateCharBboxes[objId]
        plateStr = plateString[objId]
        charCofG = plateCharCofGs[objId]
        bbox, angle = plateCharBboxAndAngle[objId]
        plateStrStrip = managetrainingchars.StripInternalSpaces(plateStr)

        #ViewPlate(fina, bbox, angle, bboxes, charCofG)
        im = misc.imread(fina)
        rotIm = deskew.RotateAndCrop(im, bbox, angle)

        print "Plate", plateCount, "of", len(testObjIds)

        for i, (bbx, cCofG) in enumerate(zip(bboxes, charCofG)):
            expectedChar = None
            if plateStrStrip is not None and len(plateStrStrip) == len(bboxes):
                expectedChar = plateStrStrip[i]

            print reg, expectedChar, cCofG, bbx
            charScores, candidateImgs = ProcessPatch(rotIm, bbx, cCofG,
                                                     preProcessedModel)

            expectedCharFiltered = expectedChar
            bestCharFiltered = charScores[0][1]
            if expectedCharFiltered == "I": expectedCharFiltered = "1"
Example #3
0
		im = misc.imread(actualFina)

		finaImSplitPath = os.path.split(fina)
		finaImSplitExt = os.path.splitext(finaImSplitPath[1])
		outRootFina = "train" + "/" + finaImSplitExt[0]

		for plate in photo[1:]:
			bbox = plate['bbox']
			reg = plate['reg']
			
			xran = (bbox[0], bbox[0]+bbox[2])
			yran = (bbox[1], bbox[1]+bbox[3])

			print count, actualFina, xran, yran
			bbox, bestInd, bestAngle = deskew.Deskew(im, (xran, yran))
			rotIm = deskew.RotateAndCrop(im, (xran, yran), bestAngle)

			#misc.imsave("rotIm{0}.png".format(count), rotIm)			

			imScore = RgbToPlateBackgroundScore(rotIm)

			#normContrast = exposure.equalize_hist(imScore)
			normContrast = exposure.rescale_intensity(imScore)
			#normContrast = exposure.equalize_adapthist(imScore)

			thresh = 0.6 * (normContrast.min() + normContrast.max())
			#normContrast = (normContrast > 0.5)
			#print normContrast.min(), normContrast.max()

			misc.imsave("{0}.png".format(outRootFina), normContrast)
			pickle.dump((bbox, bestAngle), open("{0}.deskew".format(outRootFina), "wb"), protocol=-1)