def get_division_lines(image):
    segments = extract_segments(image)
    res = []

    for segment in segments:
        region = segment.bounding_box

        if segment.bounding_box.width > 70:
            res.append(Primitive('div', region))
        elif segment.bounding_box.width > 45 and segment.bounding_box.height < image_size / 8:
            res.append(Primitive('div', region))

    return res
Exemple #2
0
 def create_number_segments(self, x, y, digits):
     segments = []
     dx = 45
     for digit in digits:
         segments.append(Primitive.new_primitive(digit, x, y))
         x += dx
     return segments
Exemple #3
0
    def test_number1_over_number2(self):
        num1_segments = self.create_number_segments(200, 200, '4')
        div_segment = Primitive.new_primitive('div', 198, 260)
        num2_segments = self.create_number_segments(198, 320, '5')

        segments = num1_segments + [div_segment] + num2_segments
        latex = construct_latex(segments=segments, width=500, height=500)
        self.assertEqual(latex, '\\frac{4}{5}')
Exemple #4
0
    def test_number1_times_number2(self):
        num1_segments = self.create_number_segments(200, 400, '43')
        minus_segment = Primitive.new_primitive('times', 300, 400)
        num2_segments = self.create_number_segments(350, 400, '538')

        segments = num1_segments + [minus_segment] + num2_segments
        latex = construct_latex(segments=segments, width=500, height=500)
        self.assertEqual(latex, '43 * 538')
def recognize(segments, model):
    res = []

    for segment in segments:
        region = segment.bounding_box

        if segment.bounding_box.width > 70:
            res.append(Primitive('div', region))
        elif segment.bounding_box.width > 45 and segment.bounding_box.height < image_size / 8:
            res.append(Primitive('div', region))
        else:
            x = segment.pixels
            x_input = prepare_input(x)
            a = model.predict(x_input)
            category_class = index_to_class[np.argmax(a)]
            res.append(Primitive(category_class, segment.bounding_box))

    return res
Exemple #6
0
 def test_digit_to_the_digit_power(self):
     segments = [Primitive.new_primitive('7', 225, 340),
                 Primitive.new_primitive('3', 250, 280)]
     latex = construct_latex(segments=segments, width=500, height=500)
     self.assertEqual(latex, '7^{3}')
Exemple #7
0
 def test_with_number(self):
     segments = [Primitive.new_primitive('7', 225, 340),
                 Primitive.new_primitive('3', 260, 342),
                 Primitive.new_primitive('8', 300, 338)]
     latex = construct_latex(segments=segments, width=500, height=500)
     self.assertEqual(latex, '738')
Exemple #8
0
    def test_with_single_digit(self):

        segments = [Primitive.new_primitive('7', 225, 340)]
        latex = construct_latex(segments=segments, width=500, height=500)
        self.assertEqual(latex, '7')