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 segmentHorizontally(self,img): self.image=img pixelCounter=PixelCounter() pixelCountArr=pixelCounter.getCountArr_H(img,0) startCountingRows=0 startRowNum=0 rowNumCounter=0 for row in range(len(pixelCountArr)): if(pixelCountArr[row]!=0): if(not startCountingRows): startCountingRows=1 startRowNum=row rowNumCounter=rowNumCounter+1 else: if(startCountingRows): usefulRowRangesTuple=(startRowNum,startRowNum+rowNumCounter) self.usefulRowRangesList.append(usefulRowRangesTuple) startCountingRows=0 rowNumCounter=0 #cv.SetZero(cv.GetRow(img, row)) return len(self.usefulRowRangesList)
def segmentHorizontally(self, img): self.image = img pixelCounter = PixelCounter() pixelCountArr = pixelCounter.getCountArr_H(img, 0) startCountingRows = 0 startRowNum = 0 rowNumCounter = 0 for row in range(len(pixelCountArr)): if (pixelCountArr[row] != 0): if (not startCountingRows): startCountingRows = 1 startRowNum = row rowNumCounter = rowNumCounter + 1 else: if (startCountingRows): usefulRowRangesTuple = (startRowNum, startRowNum + rowNumCounter) self.usefulRowRangesList.append(usefulRowRangesTuple) startCountingRows = 0 rowNumCounter = 0 #cv.SetZero(cv.GetRow(img, row)) return len(self.usefulRowRangesList)
class Modifiers: segmenter = Segmenter() pixelCounter = PixelCounter() def __init__(self): 'Constructor' #returns horizontal starting row and ending row of dika def locateDika(self, lineImg): countArr_V = self.pixelCounter.getCountArr_V(lineImg, 0) countArr_H = self.pixelCounter.getCountArr_H(lineImg, 0) dikaWidth = self.pixelCounter.getMin(countArr_V) max = self.pixelCounter.getMax(countArr_H) #print max maxAt = self.pixelCounter.getOccurredPositionList(countArr_H, max) #print maxAt return maxAt #get horizontally occurred pixel count #+1 or -1 or set some threshold # OR # get horizontally most occurred pixel count => say 'x' # find width of dika # ?? is this really needed?? position from x-widthDika to x+widthDika can be considered to be dika?? # or may be count the pixels in that row and decide according to certain threshold '' def extractTop(self, lineImg): '' dikaList = self.locateDika(lineImg) rect = CvRect rect.x = 0 rect.y = 0 rect.width = lineImg.width rect.height = dikaList[ 0] - 2 # -2 is to eliminate disturbances from bha tha dha etc segmentImg = cv.CreateImage((rect.width, rect.height), cv.IPL_DEPTH_8U, 1) cv.SetImageROI(lineImg, (rect.x, rect.y, rect.width, rect.height)) cv.Resize(lineImg, segmentImg) cv.ResetImageROI(lineImg) cv.ShowImage("TOP", segmentImg) # locate horizontal dika position # set roi upper than dika # extract the roi def extractMainElement(self, lineImg): '' #strip top #strip bottom #set roi to remaining #extract roi #OR #using height of purnabiram extract all letters of that height def extractBottom(self, lineImg): ''