/** * Check list of strokes to see if any can be combined by checking to see if * together they pass a line test * * @param strokes * strokes to check * @return merged/combined strokes */ private List <StylusPointCollection> combineLineTest(List <StylusPointCollection> strokes) { if (strokes.Count <= 1) { return(strokes); } for (int i = 1; i < strokes.Count; i++) { StylusPointCollection newStroke = combine(strokes[i - 1], strokes[i]); Recognizer newFeatures; newFeatures = new Recognizer(newStroke); LineFit lineFit = new LineFit(); lineFit.FitTest(newFeatures, true); if (lineFit.passed()) { // System.out.println("line fit: " + lineFit.m_err + " lsqe = " // + lineFit.m_lsqe/lineFit.m_features.getStrokeLength() + // " ratio = " + lineFit.m_ratio); strokes.RemoveAt(i - 1); strokes.RemoveAt(i - 1); strokes.Insert(i - 1, newStroke); strokes = combineLineTest(strokes); } } return(strokes); }
internal void Test() { m_allLinesPassed = true; m_err = 0; m_lsqe = 0; m_subStrokes = GetSegments(); m_subStrokesLength = new List <double>(m_subStrokes.Count); // check for small, extraneous lines in interpretation if (SMALL_POLYLINE_COMBINE && m_subStrokes.Count < 10) { m_subStrokes = combineSmallLines(m_subStrokes); } //// System.out.println("num substrokes = " + m_subStrokes.size()); //// check for consecutive lines with similar slopes, combine if similar if (SIM_SLOPE_POLYLINE_COMBINE) { m_subStrokes = combineSimilarSlopes(m_subStrokes); } //// System.out.println("num substrokes = " + m_subStrokes.size()); //// check for consecutive lines that, when combined, pass a line test if (LINE_TEST_COMBINE && m_subStrokes.Count > 2) { m_subStrokes = combineLineTest(m_subStrokes); } // test 1: we need at least 2 substrokes if (m_subStrokes.Count < 2) { m_passed = false; m_fail = 0; } else { // test 2: run line test on all sub strokes and get a cumulative // error for (int i = 0; i < m_subStrokes.Count; i++) { // if we have 2 or fewer points we automatically have a line if (m_subStrokes[i].Count > 1) { LineFit lf = new LineFit(); lf.getFit(m_subStrokes[i]); m_subStrokesLength.Add(lf.lineLength); m_err += lf.getError(); m_lsqe += lf.getLSQE(); //m_subshapes.add(lf.getShape()); if (!lf.passed()) { m_allLinesPassed = false; m_passed = false; m_fail = 1; } else { m_numPassed++; } } else { m_numPassed++; } } m_err /= recognizer.getStrokeLength(); m_lsqe /= recognizer.getStrokeLength(); // dcr should be high if (recognizer.getDCR() < M_DCR_TO_BE_POLYLINE) { m_passed = false; m_fail = 2; } // test 3.2: if total lsqe is low then accept even if not all // substrokes passed polyline test if (m_lsqe < M_POLYLINE_LS_ERROR) {// || m_allLinesPassed) m_passed = true; m_fail = 3; } } // calcular avg angular direction double sum = 0.0; foreach (var s in m_subStrokes) { sum += Math.Abs(angularDirection(s)); } m_avgAngularDirection = (sum * 180.0) / (m_subStrokes.Count * Math.PI); }