def splitDika(self,image): segmentLine=ToLines() totalLines=segmentLine.segment(image) pixelCounter = PixelCounter() for lineNum in range(totalLines): lineImg=segmentLine.getLineSegment(lineNum) lineRowRange=segmentLine.getCoordinatesOfLineSegment(lineNum) countArr=pixelCounter.getCountArr_V(lineImg, 0) #print countArr min=pixelCounter.getMin(countArr) #dika width is min vertically and it is most occurred horizontally for x in pixelCounter.getOccurredPositionList(countArr, min): for height in range(lineRowRange[0],(lineRowRange[1]+lineRowRange[0])/2): cv.Set2D(image,height,x,255) return image
def splitDika(self, image): segmentLine = ToLines() totalLines = segmentLine.segment(image) pixelCounter = PixelCounter() for lineNum in range(totalLines): lineImg = segmentLine.getLineSegment(lineNum) lineRowRange = segmentLine.getCoordinatesOfLineSegment(lineNum) countArr = pixelCounter.getCountArr_V(lineImg, 0) #print countArr min = pixelCounter.getMin(countArr) #dika width is min vertically and it is most occurred horizontally for x in pixelCounter.getOccurredPositionList(countArr, min): for height in range(lineRowRange[0], (lineRowRange[1] + lineRowRange[0]) / 2): cv.Set2D(image, height, x, 255) return image
def run(self): # segmentLine=ToLines() img=cv.LoadImage("/home/sushil/input.jpg",cv.CV_LOAD_IMAGE_GRAYSCALE) #Converting to Binary Image convertToBinary=ConvertToBinaryImage() binaryImg=convertToBinary.convert(img,120) cv.ShowImage("Binary image", binaryImg) #Extracting line segments lineSegment=ToLines() lineSegment.segment(binaryImg) #cv.ShowImage("LineSegment",lineSegment.getLineSegment(3)) lineImg=lineSegment.getLineSegment(1) lineImg2=lineSegment.getLineSegment(2) lineImg3=lineSegment.getLineSegment(3) totalLines=lineSegment.segment(lineImg) #for lineNum in range(totalLines): # lineRowRange=lineSegment.getCoordinatesOfLineSegment(lineNum) charSegment=ToCharacters() Img_split=charSegment.splitDika(binaryImg) cv.ShowImage("LineSegment2",Img_split) # lineSegment.segment(binaryImg) # lineImg=lineSegment.getLineSegment(3) modifiers=Modifiers() #modifiers.locateDika(lineImg) modifiers.extractTop(lineImg) whiteSpace=cv.CreateImage((20,lineImg.height), lineImg.depth, lineImg.nChannels) cv.Set(whiteSpace,255) cv.ShowImage("White", whiteSpace) mergeImage=MergeImages() mergeImage2=MergeImages() mergedImg=mergeImage2.mergeVertically([lineImg,lineImg2]) addSpace=AddSpace() mergedImg=addSpace.addWhiteSpace(lineImg, [10,20,40,50], 10) cv.ShowImage("MERGED", mergedImg)