bug-ocrad
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-ocrad] OCRAD with Visual Studio 2010 success


From: Tilman Hausherr
Subject: [Bug-ocrad] OCRAD with Visual Studio 2010 success
Date: Mon, 09 Aug 2010 17:27:29 +0200

Hello Antonio,

After a coworker presented OCRAD to me, I got interested. Then I had the
"idea" to try to build OCRAD at home on windows without using cygwin,
thus using Visual C++ to test whether its slower or faster than with
cygwin and gcc. I had to make the following changes:


1)

bitmap.cc, Bitmap::left()

data[row].erase( data[row].begin(), data[row].begin() + l - left() );

change to:

data[row].erase( data[row].begin(), data[row].begin() + (l - left()) );

reason:
The temporary expression "data[row].begin() + l" might be out of bounds
and OCRAD crashes, as seen here:
http://lists.gnu.org/archive/html/bug-ocrad/2008-03/msg00000.html


bitmap.cc, Bitmap::top()

data.erase( data.begin(), data.begin() + t - top() );

change to

data.erase( data.begin(), data.begin() + (t - top()) );

reason:
The temporary expression "data.begin() + t" might be out of bounds and
OCRAD crashes.


character.cc, Character::shift_blobp()


blobpv.insert( blobpv.begin() + i + 1, p );

change to

blobpv.insert( blobpv.begin() + (i + 1), p );

reason:

The temporary expression "blobpv.begin() + i" might be out of bounds and
OCRAD crashes.


IMHO, all three changes won't harm your code; they might even speed it
up very slightly, because now you'd have, instead of two pointer
calculations, one (faster) int calculation and one pointer calculation.

There are two more similar changes, I don't know if they're really
needed because it didn't crash there for me, but I'd suggest to do it
anyway:

in textpage.cc, join_blobs()

std::replace( v2.begin(), v2.begin() + i + 1, p2, p1 );
change to
std::replace( v2.begin(), v2.begin() + (i + 1), p2, p1 );

in textpage.cc, analyse_layout()

      zone_vector.erase( zone_vector.begin() + begin + 1,
                         zone_vector.begin() + end );
change to
      zone_vector.erase( zone_vector.begin() + (begin + 1),
                         zone_vector.begin() + end );



2)

Insert this in main() just before the call to process_file():

#ifdef _MSC_VER
        if (infile == stdin)
                _setmode ( _fileno( stdin ), _O_BINARY );
#endif

you'll also need to add at the top:

#include <io.h>
#include <fcntl.h>


reason: 
without the change, OCRAD reads an image file from the standard input in
ascii mode although it should read it in binary mode.

3)
replace this in main

if( ( control.outfile = std::fopen( outfile_name, "wx" ) ) == 0 )

with this:

#ifdef _MSC_VER
if( _access (outfile_name, 0) == 0
  || ( control.outfile = std::fopen( outfile_name, "w" ) ) == 0 )
#else
if( ( control.outfile = std::fopen( outfile_name, "wx" ) ) == 0 )
#endif

reason:
"wx" is a gcc only option, isn't supported by MSVC, and fopen fails
always.

4)
I ran OCRAD with a bunch of files, and it at least 50% faster compared
to the cygwin+gcc version.


So I'd appreciate if you consider including one or several of the
changes in the "official" sources.


Thanks,

Tilman Hausherr



reply via email to

[Prev in Thread] Current Thread [Next in Thread]