Skip to content

Commit

Permalink
Initial check in.
Browse files Browse the repository at this point in the history
  • Loading branch information
aperrault committed Jul 7, 2012
1 parent 5399c16 commit 75f7649
Show file tree
Hide file tree
Showing 6 changed files with 2,025 additions and 4 deletions.
674 changes: 674 additions & 0 deletions COPYING.txt

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions FeaturesMain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

/*
Copyright 2012 Andrew Perrault and Saurav Kumar.
This file is part of DetectText.
DetectText is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DetectText is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DetectText. If not, see <http:https://www.gnu.org/licenses/>.
*/
#include <cassert>
#include <fstream>
#include "TextDetection.h"
#include <opencv/highgui.h>
#include <exception>

void convertToFloatImage ( IplImage * byteImage, IplImage * floatImage )
{
cvConvertScale ( byteImage, floatImage, 1 / 255., 0 );
}

class FeatureError : public std::exception
{
std::string message;
public:
FeatureError ( const std::string & msg, const std::string & file )
{
std::stringstream ss;

ss << msg << " " << file;
message = msg.c_str ();
}
~FeatureError () throw ( )
{
}
};

IplImage * loadByteImage ( const char * name )
{
IplImage * image = cvLoadImage ( name );

if ( !image )
{
return 0;
}
cvCvtColor ( image, image, CV_BGR2RGB );
return image;
}

IplImage * loadFloatImage ( const char * name )
{
IplImage * image = cvLoadImage ( name );

if ( !image )
{
return 0;
}
cvCvtColor ( image, image, CV_BGR2RGB );
IplImage * floatingImage = cvCreateImage ( cvGetSize ( image ),
IPL_DEPTH_32F, 3 );
cvConvertScale ( image, floatingImage, 1 / 255., 0 );
cvReleaseImage ( &image );
return floatingImage;
}

int mainTextDetection ( int argc, char * * argv )
{
IplImage * byteQueryImage = loadByteImage ( argv[1] );
if ( !byteQueryImage )
{
printf ( "couldn't load query image\n" );
return -1;
}

// Detect text in the image
IplImage * output = textDetection ( byteQueryImage, atoi(argv[3]) );
cvReleaseImage ( &byteQueryImage );
cvSaveImage ( argv[2], output );
cvReleaseImage ( &output );
return 0;
}

int main ( int argc, char * * argv )
{
if ( ( argc != 4 ) )
{
printf ( "usage: %s imagefile resultImage darkText\n",
argv[0] );

return -1;
}
return mainTextDetection ( argc, argv );
}
23 changes: 23 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
DetectText
==========

Detect text with stroke width transform.

Dependencies: OpenCV, boost.

To compile:
g++ -o TextDetection FeaturesMain.cpp TextDetection.cpp -Ipath_to_current_directory
where path_to_current_directory is replaced with the path to the current directory.

To run:
./TextDetection input_file output_file dark_on_light
where dark_on_light is 1 or 0, indicating whether the text is darker or lighter than the background.

GitHub repository:
https://github.com/aperrau/DetectText

A similar implementation can be found here:
https://github.com/mfarre/textdetection

More details on the algorithm can be found in:
http:https://www.cs.cornell.edu/courses/cs4670/2010fa/projects/final/results/group_of_arp86_sk2357/Writeup.pdf
4 changes: 0 additions & 4 deletions README.md

This file was deleted.

Loading

0 comments on commit 75f7649

Please sign in to comment.