private static bool IsCanCombineToPrevious(TextBlock block, char part) { int index = -1; if (isHorizontalText) { index = HorizontalTextProjection.KanjiRightPartsDetection(part, block.Text[0]); } else { if (block.Text[0] == '?') { return(true); } else { index = Array.BinarySearch <char>(VerticalTextProjection.BottomMistakenTextBlocks, block.Text[0]); } } if (index < 0) { return(false); } else { return(true); } }
private static List <TextBlock> ProcessHorizontalLines(GrayImage image, uint[] vertical) { List <TextBlock> textBlocks = new List <TextBlock>(); List <SplitMultiLines.Line> textLines = SplitMultiLines.SplitProjectDensity(vertical); for (int i = 0; i < textLines.Count; i++) { var density = Projection.ProjectSubImageOnHorizontalLine(image, textLines[i]); textBlocks.AddRange(HorizontalTextProjection.FindAllTextBlock(image, density, textLines[i], i)); } return(textBlocks); }
private static bool IsCanCombineToNext(TextBlock block, char part) { int index = -1; if (isHorizontalText) { index = HorizontalTextProjection.KanjiLeftPartsDetection(part, block.Text[0]); } else { index = Array.BinarySearch <char>(VerticalTextProjection.TopMistakenTextBlocks, block.Text[0]); } if (index < 0) { return(false); } else { return(true); } }
private static float CaluculateValidGap(int blockIndex, char text) { if (isHorizontalText) { float avgGap = HorizontalTextProjection.AvgGapBlocks[blocks[blockIndex].LineIndex]; float percent = HorizontalTextProjection.GetMaxHeightPostionPercentToNeightbor(blocks, blockIndex); if (text == '、' || text == 'l' || text == 'ノ') { if (percent > HorizontalTextProjection.MARK_HEIGH_POSITION_PERCENT) { return(2f * avgGap); } } else if (text == 'し') { return((float)Math.Ceiling(avgGap * 2f)); } else if (percent > HorizontalTextProjection.MARK_HEIGH_POSITION_PERCENT) { return(1.5f * avgGap); } return(avgGap); } else { float percent = VerticalTextProjection.GetMaxWidthPostionPercentToNeightbor(blocks, blockIndex); if (percent > VerticalTextProjection.MARK_WIDTH_POSITION_PERCENT) { return(VerticalTextProjection.AvgGapBlocks[blocks[blockIndex].LineIndex] * 1.5f); } else { return(VerticalTextProjection.AvgGapBlocks[blocks[blockIndex].LineIndex]); } } }
private static int GetSplitIndexOfBlock(TextBlock block, uint[] density) { uint maxDensity = 0; MinOfSection[] sectionMin = new MinOfSection[9]; float topDivide = avgCharHeight / 4; int section1 = (int)(block.Top + topDivide); int section2 = (int)(section1 + topDivide); int section3 = (int)(section2 + topDivide); int section4 = (int)(section3 + topDivide); float bottomDivide = (block.Top + block.Height - section4) / 5; int section5 = (int)(section4 + bottomDivide); int section6 = (int)(section5 + bottomDivide); int section7 = (int)(section6 + bottomDivide); int section8 = (int)(section7 + bottomDivide); sectionMin[0] = HorizontalTextProjection.FindMinOfSection(density, block.Top, section1, ref maxDensity); sectionMin[1] = HorizontalTextProjection.FindMinOfSection(density, section1, section2, ref maxDensity); sectionMin[2] = HorizontalTextProjection.FindMinOfSection(density, section2, section3, ref maxDensity); sectionMin[3] = HorizontalTextProjection.FindMinOfSection(density, section3, section4, ref maxDensity); uint minMiddleSectionDensity = sectionMin[3].Density; int minMiddleindex = sectionMin[3].Index; sectionMin[4] = HorizontalTextProjection.FindMinOfSection(density, section4, section5, ref maxDensity); if (sectionMin[4].Density < minMiddleSectionDensity) { minMiddleSectionDensity = sectionMin[4].Density; minMiddleindex = sectionMin[4].Index; } sectionMin[5] = HorizontalTextProjection.FindMinOfSection(density, section5, section6, ref maxDensity); if (sectionMin[5].Density < minMiddleSectionDensity) { minMiddleSectionDensity = sectionMin[5].Density; minMiddleindex = sectionMin[5].Index; } sectionMin[6] = HorizontalTextProjection.FindMinOfSection(density, section6, section7, ref maxDensity); sectionMin[7] = HorizontalTextProjection.FindMinOfSection(density, section7, section8, ref maxDensity); sectionMin[8] = HorizontalTextProjection.FindMinOfSection(density, section8, block.Bottom, ref maxDensity); int splitIndex = 0; if (minMiddleSectionDensity < (maxDensity / 4)) { splitIndex = minMiddleindex; } else { float minDen = HorizontalTextProjection.MAX_INT; for (int mod = 0; mod < HorizontalTextProjection.MODIFICATION_VECTORS.Length; mod++) { float temp = HorizontalTextProjection.MODIFICATION_VECTORS[mod] * sectionMin[mod].Density; if (minDen > temp) { minDen = temp; splitIndex = sectionMin[mod].Index; } } } return(splitIndex); }