1import os 2 3import infra.basetest 4 5 6class TestTesseractOcr(infra.basetest.BRTest): 7 config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ 8 """ 9 BR2_PACKAGE_FREETYPE=y 10 BR2_PACKAGE_GHOSTSCRIPT_FONTS=y 11 BR2_PACKAGE_GRAPHICSMAGICK=y 12 BR2_PACKAGE_TESSERACT_OCR=y 13 BR2_PACKAGE_TESSERACT_OCR_LANG_ENG=y 14 BR2_TARGET_ROOTFS_CPIO=y 15 # BR2_TARGET_ROOTFS_TAR is not set 16 """ 17 18 def test_run(self): 19 cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") 20 self.emulator.boot(arch="armv5", 21 kernel="builtin", 22 options=["-initrd", cpio_file]) 23 self.emulator.login() 24 25 msg = "Hello from Buildroot runtime test." 26 img_file = "image.pgm" 27 txt_basename = "text" 28 txt_file = f"{txt_basename}.txt" 29 30 # Check the program execute. 31 self.assertRunOk("tesseract --version") 32 33 # Generate an image file including a text message. 34 cmd = f"gm convert -pointsize 16 label:'{msg}' {img_file}" 35 self.assertRunOk(cmd) 36 37 # Perform the character recognition. 38 cmd = f"tesseract {img_file} {txt_basename}" 39 self.assertRunOk(cmd, timeout=30) 40 41 # Check the decoded text matches the original message. 42 cmd = f"grep -F '{msg}' {txt_file}" 43 self.assertRunOk(cmd) 44