1. <?php
    2. /**
    3. * Info 图文识别
    4. */
    5. namespace lib;
    6. use o;
    7. use fun;
    8. use file;
    9. use lib;
    10. use lib3\TesseractOCR\TesseractOCR;
    11. use lib3\TesseractOCR\Command;
    12. class ocr{
    13. /**
    14. * @param mixed $k 参数,有需要才传
    15. * @return object
    16. */
    17. public static function I($k = ''){
    18. return I(__CLASS__, $k);
    19. }
    20. /**
    21. * 测试方法
    22. * 调用方法lib\ocr::I()->test(DATA_ROOT . 'zt/ocr/img/Image_00002.jpg');
    23. * @param string $imgFile 需要识别的图片地址
    24. * @return string
    25. */
    26. public function test($imgFile){
    27. if(!is_file($imgFile)) return $imgFile .'文件不存在';
    28. $outputFile = DATA_ROOT . 'zt/ocr/temp/test';
    29. $cmd = new Command($imgFile, $outputFile);
    30. $tess = new TesseractOCR($imgFile, $cmd);
    31. $ret = $tess->lang('chi_sim', 'eng')->run();
    32. return $ret;
    33. }
    34. }