aboutsummaryrefslogtreecommitdiff
path: root/helium/main_helium.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'helium/main_helium.cpp')
-rw-r--r--helium/main_helium.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/helium/main_helium.cpp b/helium/main_helium.cpp
new file mode 100644
index 0000000..c013855
--- /dev/null
+++ b/helium/main_helium.cpp
@@ -0,0 +1,66 @@
+// Copyright 2006 Google Inc.
+// All Rights Reserved.
+// Author: <renn@google.com> (Marius Renn)
+//
+// This is the main file for the core front-end to Helium. It is rather
+// simple, and does not provide any debugging information.
+// The detected text is output to a file called "text.dat".
+//
+// Please note, that for image loading, Leptonica is required!
+//
+// Local includes
+#include "color.h"
+#include "debugging.h"
+#include "image.h"
+#include "heliumbinarizer.h"
+#include "heliumtextdetector.h"
+#include "leptonica.h"
+#include "textareas.h"
+#include "textrecognition.h"
+
+// C includes
+#include <stdlib.h>
+
+using namespace helium;
+
+void ExitWithError(const char* message) {
+ ERROR(message);
+ exit(-1);
+}
+
+int main(int argc, char** argv) {
+ // Usage check
+ if (argc != 2) ExitWithError("Usage: text_detect <input_file>");
+
+ // Init Tesseract
+ TextRecognition::Init("../");
+
+ // Read input image
+ LOG_MSG("Reading file...");
+ PIX* input = pixRead(argv[1]);
+ if (!input) ExitWithError("Could not open image file!");
+ Image image = Leptonica::PixToImage(input);
+ if (!image.Valid()) ExitWithError("Error while loading image file!");
+
+ // Run text detector
+ LOG_MSG("Running Text Detector...");
+ HeliumTextDetector detector;
+ detector.SetDefaultParameters();
+ detector.DetectText(image);
+
+ // Setup binarizer
+ LOG_MSG("Setting up Binarizer...");
+ HeliumBinarizer binarizer(image);
+ binarizer.AddClusters(detector.GetClusters());
+
+ // Run OCR
+ LOG_MSG("OCRing...");
+ TextAreas text;
+ TextRecognition::RecognizeUsingBinarizer(&binarizer, text);
+
+ // Output Text
+ text.WriteDatFile("text.dat");
+ LOG_MSG("Done.");
+
+ return 0;
+};