599 {
600 const char* lang = nullptr;
601 const char* image = nullptr;
602 const char* outputbase = nullptr;
603 const char* datapath = nullptr;
604 bool list_langs = false;
605 bool print_parameters = false;
606 l_int32 dpi = 0;
607 int arg_i = 1;
609#ifdef DISABLED_LEGACY_ENGINE
611#else
613#endif
614
615
616
619
620#if !defined(DEBUG)
621
622 setMsgSeverity(L_SEVERITY_ERROR);
623#endif
624
625#if defined(HAVE_TIFFIO_H) && defined(_WIN32)
626
627 TIFFSetErrorHandler(Win32ErrorHandler);
628 TIFFSetWarningHandler(Win32WarningHandler);
629#endif
630
631 ParseArgs(argc, argv, &lang, &image, &outputbase, &datapath, &dpi,
632 &list_langs, &print_parameters, &vars_vec, &vars_values, &arg_i,
633 &pagesegmode, &enginemode);
634
635 if (lang == nullptr) {
636
637 lang = "eng";
638 }
639
640 if (image == nullptr && !list_langs && !print_parameters)
641 return EXIT_SUCCESS;
642
643
644
645
647
648
650
652
653 const int init_failed = api.
Init(datapath, lang, enginemode, &(argv[arg_i]),
654 argc - arg_i, &vars_vec, &vars_values, false);
655
656 SetVariablesFromCLArgs(&api, argc, argv);
657
658
660
661 if (list_langs) {
662 PrintLangsList(&api);
663 return EXIT_SUCCESS;
664 }
665
666 if (init_failed) {
667 fprintf(stderr, "Could not initialize tesseract.\n");
668 return EXIT_FAILURE;
669 }
670
671 if (print_parameters) {
672 FILE* fout = stdout;
673 fprintf(stdout, "Tesseract parameters:\n");
676 return EXIT_SUCCESS;
677 }
678
679 FixPageSegMode(&api, pagesegmode);
680
681 if (dpi) {
682 char dpi_string[255];
683 snprintf(dpi_string, 254, "%d", dpi);
685 }
686
688 int ret_val = EXIT_SUCCESS;
689
690 Pix* pixs = pixRead(image);
691 if (!pixs) {
692 fprintf(stderr, "Leptonica can't process input file: %s\n", image);
693 return 2;
694 }
695
697
701 float deskew_angle;
702
704 if (it) {
705
706
707 it->
Orientation(&orientation, &direction, &order, &deskew_angle);
709 "Orientation: %d\nWritingDirection: %d\nTextlineOrder: %d\n"
710 "Deskew angle: %.4f\n",
711 orientation, direction, order, deskew_angle);
712 } else {
713 ret_val = EXIT_FAILURE;
714 }
715
716 delete it;
717
718 pixDestroy(&pixs);
719 return ret_val;
720 }
721
722
723
724
725 bool b = false;
726 bool in_training_mode =
731
732#ifdef DISABLED_LEGACY_ENGINE
734 auto osd_warning = std::string("");
736 const char* disabled_osd_msg =
737 "\nERROR: The page segmentation mode 0 (OSD Only) is currently disabled.\n\n";
738 fprintf(stderr, "%s", disabled_osd_msg);
739 return EXIT_FAILURE;
742 osd_warning +=
743 "\nWarning: The page segmentation mode 1 (Auto+OSD) is currently disabled. "
744 "Using PSM 3 (Auto) instead.\n\n";
747 osd_warning +=
748 "\nWarning: The page segmentation mode 12 (Sparse text + OSD) is currently disabled. "
749 "Using PSM 11 (Sparse text) instead.\n\n";
750 }
751#endif
752
753
755
756 if (in_training_mode) {
758 } else if (outputbase != nullptr) {
759 PreloadRenderers(&api, &renderers, pagesegmode, outputbase);
760 }
761
762 bool banner = false;
763 if (outputbase != nullptr && strcmp(outputbase, "-") &&
764 strcmp(outputbase, "stdout")) {
765 banner = true;
766 }
767
768 if (!renderers.
empty()) {
769 if (banner) PrintBanner();
770#ifdef DISABLED_LEGACY_ENGINE
771 if (!osd_warning.empty()) {
772 fprintf(stderr, "%s",osd_warning.c_str());
773 }
774#endif
775 bool succeed = api.
ProcessPages(image,
nullptr, 0, renderers[0]);
776 if (!succeed) {
777 fprintf(stderr, "Error during processing.\n");
778 return EXIT_FAILURE;
779 }
780 }
781
782 return EXIT_SUCCESS;
783}
DLLSYM void tprintf(const char *format,...)
@ PSM_AUTO_OSD
script detection. (OSD)
@ PSM_OSD_ONLY
Orientation and script detection only.
@ PSM_SPARSE_TEXT
Find as much text as possible in no particular order.
@ PSM_AUTO_ONLY
Automatic page segmentation, but no OSD, or OCR.
@ PSM_AUTO
Fully automatic page segmentation, but no OSD.
@ PSM_SPARSE_TEXT_OSD
Sparse text with orientation and script det.
void SetPageSegMode(PageSegMode mode)
bool SetVariable(const char *name, const char *value)
bool ProcessPages(const char *filename, const char *retry_config, int timeout_millisec, TessResultRenderer *renderer)
PageSegMode GetPageSegMode() const
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_non_debug_params)
void PrintVariables(FILE *fp) const
void SetImage(const unsigned char *imagedata, int width, int height, int bytes_per_pixel, int bytes_per_line)
PageIterator * AnalyseLayout()
bool GetBoolVariable(const char *name, bool *value) const
void SetOutputName(const char *name)
static TESS_API void Update()
void Orientation(tesseract::Orientation *orientation, tesseract::WritingDirection *writing_direction, tesseract::TextlineOrder *textline_order, float *deskew_angle) const
static TESS_API DawgCache * GlobalDawgCache()