Exemplo n.º 1
0
    def test_ffr_player_info_detect(self):
        def rand_text():
            return ''.join([ chr(random.randint(32, 126)) for char in range(12) ])

        def text_gen():
            return f'Results for [Lv. {random.randint(0, 999)}] {rand_text()}:'

        # Results data
        total = 50
        num_ok = 0
        fail_data = []

        for _ in range(total):
            # Generate image
            text, color, font_size, img = self.gen_image(text_gen)
            ocr_data = OCR.detect_data(img)

            # Run ocr and generated data through text parser
            gen_txt_data = FfrTxtProcessing.get_player_info_txt(text)
            ocr_txt_data = FfrTxtProcessing.get_player_info_txt(' '.join(ocr_data['text']))
        
            all_ok = True

            # Compare and record result
            for gen_items, ocr_items in zip(gen_txt_data.items(), ocr_txt_data.items()):
                gen_key, gen_text = gen_items
                ocr_key, ocr_text = ocr_items

                # Sanity check
                self.assertEqual(gen_key, ocr_key)

                if gen_text != ocr_text:
                    fail_data.append({
                        'gen_text' : gen_txt_data,
                        'ocr_text' : ocr_txt_data,
                        'size'     : font_size,
                        'color'    : color,
                    })

                    all_ok = False
                    break

            if all_ok:
                num_ok += 1

        with open(f'{self.results_path}/player_info.txt', 'w') as f:
            f.write(json.dumps(fail_data, indent=4))

        detection_rate = num_ok/total
        self.detection_rates['player_info'] = detection_rate
        self.assertGreaterEqual(detection_rate, 0.9)
Exemplo n.º 2
0
    def test_ffr_raw_goods_detect(self):
        def text_gen():
            return f'Raw Goods: {round(random.random()*100, 2)}'

        # Results data
        total = 50
        num_ok = 0
        fail_data = []

        for _ in range(total):
            # Generate image
            text, color, font_size, img = self.gen_image(text_gen)
            ocr_data = OCR.detect_data(img)

            # Run ocr and generated data through text parser
            gen_txt_data = FfrTxtProcessing.get_raw_goods_txt(text)
            ocr_txt_data = FfrTxtProcessing.get_raw_goods_txt(' '.join(ocr_data['text']))
        
            all_ok = True

            # Compare and record result
            for gen_items, ocr_items in zip(gen_txt_data.items(), ocr_txt_data.items()):
                gen_key, gen_text = gen_items
                ocr_key, ocr_text = ocr_items

                # Sanity check
                self.assertEqual(gen_key, ocr_key)

                if gen_text != ocr_text:
                    fail_data.append({
                        'gen_text' : gen_txt_data,
                        'ocr_text' : ocr_txt_data,
                        'size'     : font_size,
                        'color'    : color,
                    })
                    
                    all_ok = False
                    break

            if all_ok:
                num_ok += 1

        with open(f'{self.results_path}/raw_goods.txt', 'w') as f:
            f.write(json.dumps(fail_data, indent=4))

        detection_rate = num_ok/total
        self.detection_rates['raw_goods'] = detection_rate
        self.assertGreaterEqual(detection_rate, 0.9)