def matchingChars(possibleC, possibleChars): listOfMatchingChars = [] for possibleMatchingChar in possibleChars: if possibleMatchingChar == possibleC: continue distanceBetweenChars = Tools.distanceBetweenChars( possibleC, possibleMatchingChar) angleBetweenChars = Tools.angleBetweenChars( possibleC, possibleMatchingChar) changeInArea = float( abs(possibleMatchingChar.boundingRectArea - possibleC.boundingRectArea)) / float( possibleC.boundingRectArea) changeInWidth = float( abs(possibleMatchingChar.boundingRectWidth - possibleC.boundingRectWidth)) / float( possibleC.boundingRectWidth) changeInHeight = float( abs(possibleMatchingChar.boundingRectHeight - possibleC.boundingRectHeight)) / float( possibleC.boundingRectHeight) if distanceBetweenChars < (possibleC.diagonalSize * 5) and \ angleBetweenChars < 12.0 and \ changeInArea < 0.5 and \ changeInWidth < 0.8 and \ changeInHeight < 0.2: listOfMatchingChars.append(possibleMatchingChar) return listOfMatchingChars
listOfMatchingChars[0].boundingRectX) * 1.3) totalOfCharHeights = 0 for matchingChar in listOfMatchingChars: totalOfCharHeights = totalOfCharHeights + matchingChar.boundingRectHeight averageCharHeight = totalOfCharHeights / len(listOfMatchingChars) plateHeight = int(averageCharHeight * 1.5) opposite = listOfMatchingChars[len(listOfMatchingChars) - 1].centerY - listOfMatchingChars[0].centerY hypotenuse = Tools.distanceBetweenChars( listOfMatchingChars[0], listOfMatchingChars[len(listOfMatchingChars) - 1]) correctionAngleInRad = math.asin(opposite / hypotenuse) correctionAngleInDeg = correctionAngleInRad * (180.0 / math.pi) possiblePlate.rrLocationOfPlateInScene = (tuple(plateCenter), (plateWidth, plateHeight), correctionAngleInDeg) rotationMatrix = cv2.getRotationMatrix2D(tuple(plateCenter), correctionAngleInDeg, 1.0) height, width, numChannels = img.shape imgRotated = cv2.warpAffine(img, rotationMatrix, (width, height))