Skip to content

Commit

Permalink
Adds OCRTesseract class and sample demo
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisgomez committed Jul 31, 2014
1 parent 70a2bca commit 5c89c78
Show file tree
Hide file tree
Showing 7 changed files with 685 additions and 0 deletions.
23 changes: 23 additions & 0 deletions modules/text/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})

find_package(Tesseract)
if(Tesseract_FOUND)
message(STATUS "Tesseract: YES")
set(HAVE_TESSERACT 1)
else()
message(STATUS "Tesseract: NO")
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/text_config.hpp.in
${CMAKE_BINARY_DIR}/text_config.hpp @ONLY)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

if(${Tesseract_FOUND})
include_directories(${Tesseract_INCLUDE_DIR})
endif()

set(the_description "Text Detection and Recognition")
ocv_define_module(text opencv_ml opencv_highgui opencv_imgproc opencv_core)

if(${Tesseract_FOUND})
target_link_libraries(opencv_text ${Tesseract_LIBS})
endif()
24 changes: 24 additions & 0 deletions modules/text/FindTesseract.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Tesseract OCR
unset(Tesseract_FOUND)

find_path(Tesseract_INCLUDE_DIR tesseract/baseapi.h
HINTS
/usr/include
/usr/local/include)

find_library(Tesseract_LIBRARY NAMES tesseract
HINTS
/usr/lib
/usr/local/lib)

find_library(Lept_LIBRARY NAMES lept
HINTS
/usr/lib
/usr/local/lib)

set(Tesseract_LIBS ${Tesseract_LIBRARY} ${Lept_LIBRARY})
if(Tesseract_LIBS AND Tesseract_INCLUDE_DIR)
set(Tesseract_FOUND 1)
endif()


1 change: 1 addition & 0 deletions modules/text/include/opencv2/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ the use of this software, even if advised of the possibility of such damage.
#define __OPENCV_TEXT_HPP__

#include "opencv2/text/erfilter.hpp"
#include "opencv2/text/ocr.hpp"

#endif
110 changes: 110 additions & 0 deletions modules/text/include/opencv2/text/ocr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#ifndef __OPENCV_TEXT_OCR_HPP__
#define __OPENCV_TEXT_OCR_HPP__

#include "text_config.hpp"

#ifdef HAVE_TESSERACT
#include <tesseract/baseapi.h>
#include <tesseract/resultiterator.h>
#endif

#include "opencv2/core.hpp"
#include <vector>
#include <string>


namespace cv
{
namespace text
{

using namespace std;

enum
{
OCR_LEVEL_WORD,
OCR_LEVEL_TEXTLINE
};

#ifdef HAVE_TESSERACT
class CV_EXPORTS OCRTesseract
{
private:
tesseract::TessBaseAPI tess;

public:
//Default constructor
OCRTesseract(const char* datapath=NULL, const char* language=NULL, const char* char_whitelist=NULL,
tesseract::OcrEngineMode oem=tesseract::OEM_DEFAULT, tesseract::PageSegMode psmode=tesseract::PSM_AUTO);

~OCRTesseract();

void run(Mat& image, string& output_text, vector<Rect>* component_rects=NULL,
vector<string>* component_texts=NULL, vector<float>* component_confidences=NULL,
int component_level=0);
};
#else
//stub
class CV_EXPORTS OCRTesseract
{
public:
//Default constructor
OCRTesseract(const char* datapath=NULL, const char* language=NULL, const char* char_whitelist=NULL,
int oem=0, int psmode=0);

~OCRTesseract();

void run(Mat& image, string& output_text, vector<Rect>* component_rects=NULL,
vector<string>* component_texts=NULL, vector<float>* component_confidences=NULL,
int component_level=0);
};
#endif



}
}
#endif // _OPENCV_TEXT_OCR_HPP_
Loading

0 comments on commit 5c89c78

Please sign in to comment.