tesseract 3.01 actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES - c++

I'm building tesseract 3.01 and magick++ into a program because the command line versions were too slow. getting everything compiled correctly took forever but finally I get no errors in my compiler, but as soon as I go to run my console app I get
PS C:\Users\sirus\Documents\Visual Studio 2013\Projects\ConsoleApplication4\Release> .\ConsoleApplication4.exe
first command
actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES:Error:Assert failed:in file ..\ccutil\tessdatamanager.cpp, line 48
PS C:\Users\sirus\Documents\Visual Studio 2013\Projects\ConsoleApplication4\Release> l
searching for this online shows that this is what happens when you have to incorrect language data, but I have tesseract 3.01 and the tesseract 3.01 language data downloaded directly from their google code site.
I'm using visual studio 2013 on windows 8.1 building 32 bit /MD
here is a sample of my source
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <locale>
#include <sstream>
#include <string>
#include <Magick++.h>
#include "baseapi.h"
#include "allheaders.h"
using namespace Magick;
using namespace std;
using namespace tesseract;
#define MaxRGB ((Magick::Quantum)65545)
tesseract::TessBaseAPI tess;
string cmd = "";
string cmd2 = "";
void img_split(){
string tesseract = "\"C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe\" text/";
int rect_y = 141;
string del = "del /s /q text\\*";
system(del.c_str());
for (int x = 1; x < 40; x++){
rect_y += 19;
Image image;
image.read("source.jpg");
Magick::Image* mImage;
Image sub_image(image);
mImage = &sub_image;
//mImage->write("test.jpg");
sub_image.chop(Geometry(1481, rect_y));
sub_image.crop(Geometry(220, 17));
sub_image.quantizeColorSpace(GRAYColorspace);
sub_image.quantizeColors(2);
sub_image.quantizeDither(false);
sub_image.quantize();
sub_image.scale(Geometry(2200,170));
sub_image.antiAlias();
sub_image.compressType(Magick::NoCompression);
//const unsigned char* imagedata = (unsigned char*)mImage;
//tess.SetImage(imagedata, 2200, 170, 1, 17300);
//tess.Recognize(0);
//const char* out = tess.GetUTF8Text();
//cout << "\n\nno idea if this will work: " << out << endl;
sub_image.write("text/" + static_cast<ostringstream*>(&(ostringstream() << x))->str() + ".gif");
//cmd2 = tesseract + static_cast<ostringstream*>(&(ostringstream() << x))->str() + ".png text/" + static_cast<ostringstream*>(&(ostringstream() << x))->str();
//tesseract_ocr(x);
}
}
int main(int argc, char **argv)
{
cout << "first command\n";
//tess.Init(argv[0], "eng", tesseract::OEM_DEFAULT);
tess.Init(*argv, "eng");
tess.SetPageSegMode(tesseract::PSM_AUTO);
cout << "\ntest" << endl;
InitializeMagick(*argv);
//img_split();
return 0;
}
bonus points if you can tell me how to correctly pass the image in sub_image to tesseract's setimage function (because i'm pretty sure what I have wont be right either)

actual_tessdata_num_entries <= TESSDATA_NUM_ENTRIES:Error:Assert
failed:in file ..\ccutil\tessdatamanager.cpp, line 55
If you get error during running tesseract, please check if you use correct version of traineddata (e.g. 3.00 with 3.01). You can not use 3.01 traineddata with tesseract 3.00.
To sum it up you just need to get the traineddata for your version.. or don't even mess with the traineddata and use the ones that it comes with when you download it.
Check out this link below for the solution.
https://code.google.com/p/tesseract-ocr/wiki/FAQ#actual_tessdata_num_entries_<=_TESSDATA_NUM_ENTRIES:Error:Ass

Related

when i use itk to read '.nii.gz' file ,reader->update give me a microsoft c++ error

when my program run reader->update(); i will be given a microsoft c++ error
Microsoft C++ 异常: itk::ImageFileReaderException,位于内存位置 0x00000000002CF0F8 处。
here is my entire code:
#include "itkImage.h"
#include <iostream>
#include<itkAndImageFilter.h>
#include <itkImageFileReader.h>
#include "itkImageFileWriter.h"
#include<string>
int main()
{
using PixelType = float;
constexpr unsigned int Dimension = 3;
const char* im_path = "C:/Users/Administrator/Desktop/test.nii.gz";
using ImageType = itk::Image<PixelType, Dimension>;
using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(im_path);
std::string s = reader->GetFileName();
std::cout << s << std::endl;
ImageType::Pointer image = reader->GetOutput();
reader->Update();
return 0;
}
There is probably something wrong with how you compiled ITK, or how you link your program to ITK. Your program works on my computer without issue. I only changed the path to the file. Make sure the file is not damaged, by opening it in another program such as ITK-SNAP or 3D Slicer.

I invoke LSCopyApplicationURLsForURL() using C++, but get a segment fault

I want to write a C++ program to get associated applications which are suitable to open specified file. I find the LSCopyApplicationURLsForURL API, and create a command line C++ application by XCode.
But after running this program, I always get segment fault. XCode shows EXEC_BAD_ACCESS(code=1, address....) error.
I also tryied running it from sudo, but the same result. What is the problem?
The code:
#include <iostream>
#include <objc/objc.h>
#include <objc/objc-runtime.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
using namespace std;
int main(int argc, const char * argv[]) {
auto url = CFURLRef("file:///Users/efan/src/a.cpp");
auto ret = LSCopyApplicationURLsForURL(url, kLSRolesAll);
cout << ret << endl;
return 0;
}
Try creating your CFURLRef using one of the proper CFURLCreate* methods. See "Creating a CFURL" here.
For example:
auto tempStringURL = CFStringCreateWithCString(nullptr, "/Users/efan/src/a.cpp", kCFStringEncodingUTF8);
auto url = CFURLCreateWithFileSystemPath(nullptr, tempStringURL, kCFURLPOSIXPathStyle, FALSE);
auto ret = LSCopyApplicationURLsForURL(url, kLSRolesAll);
You need to Release the "Created" variables to clean up memory.

OpenCV ImageStitching App working on Visual, not working with QTCreator. Code is the same in both

I have application made with QTCreator. It uses OpenCV 2.4.11. I have the same application on Visual. Code is the same in both.
OpenCV for Microsoft Visual 2013 was made using this link:
https://www.youtube.com/watch?v=e_TQ9c3n_d8
It is for 2.4.10, but it's the same for 2.4.11.
And I configured QtCreator with this tutorial:
How to link opencv in QtCreator and use Qt library
Now the code:
#include <opencv2\highgui\highgui.hpp>
#include <iostream>
#include <fstream>
#include <opencv2\highgui\highgui.hpp>
#include "opencv2\stitching\stitcher.hpp"
using namespace cv;
using namespace std;
void ReadPhotos();
double begin_t, end_t;
int photo_number = 0;
Mat photos[100];
Mat image;
vector< Mat > ImagesVector;
vector<Mat> roisVector;
int main()
{
cout << "Starting program!" << endl;
ReadPhotos();
Size size(1050, 600);
for (int i = 0; i < photo_number; i++){
//resize(photos[i], photos[i], size);
ImagesVector.push_back(photos[i]);
}
Stitcher stitcher = Stitcher::createDefault(true);
stitcher.setWarper(new SphericalWarper());
stitcher.setFeaturesFinder(new detail::SurfFeaturesFinder(300, 3, 4, 3, 4));
stitcher.setRegistrationResol(0.9);
stitcher.setSeamEstimationResol(0.9);
stitcher.setCompositingResol(1);
stitcher.setPanoConfidenceThresh(1);
stitcher.setWaveCorrection(true);
stitcher.setWaveCorrectKind(detail::WAVE_CORRECT_HORIZ);
stitcher.setFeaturesMatcher(new detail::BestOf2NearestMatcher(false, 0.3));
stitcher.setBundleAdjuster(new detail::BundleAdjusterRay());
Stitcher::Status status = Stitcher::ERR_NEED_MORE_IMGS;
try{
status = stitcher.stitch(ImagesVector, image);
}
catch (cv::Exception e){}
imwrite("panorama.jpg", image);
waitKey(0);
return 0;
}
void ReadPhotos(){
string sourceIN;
string sourcePhoto;
sourceIN = "paths1.txt";
ifstream FileIN(sourceIN);
if (FileIN.is_open())
{
while (getline(FileIN, sourcePhoto)){
photos[photo_number] = imread(sourcePhoto, 1);
photo_number++;
}
}
else{
cout << "Can't find file" << endl;
}
cout << "Number of photos: " << photo_number << endl;
}
Read photos function takes path to images from txt file and load photos.
In visual studio it's working good, I can stitch 3500x2000 resulution images and it gives nice output panorama. In QtCreator I try to stitch the same images and it gives following errors:
OpenCV Error: Insufficient memory (Failed to allocate 290519044 bytes) in OutOfMemoryError, file C:\OpenCV2411\opencv\sources\modules\core\src\alloc.cpp, line 52
terminate called after throwing an instance of 'cv::Exception'
what(): C:\OpenCV2411\opencv\sources\modules\core\src\alloc.cpp:52: error: (-4) Failed to allocate 290519044 bytes in function OutOfMemoryError
Bad alloc - sorry, I can't make this error again so can't copy exactly.
Anyone has any idea why the same code is not working on QTCreator and is working in Visual Studio 2013? Library is the same. One thing I can think of is that I build libraries for QTCreator myself with Cmake. Maybe it has something with this.

How to run commandline/terminal utils with Boost.Process 0.5?

I foud out there is a new Boost.Process 0.5 but I cant see how to execute across Windows Linux and Mac ping or echo.
I got it working at leaast on Windows with simple:
#include <string>
#include <iostream>
#include <boost/asio.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/process.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/system/error_code.hpp>
namespace bp = boost::process;
namespace bpi = boost::process::initializers;
namespace bio = boost::iostreams;
int main()
{
bp::pipe p = bp::create_pipe();
{
bio::file_descriptor_sink sink(p.sink, bio::close_handle);
boost::filesystem::path p("C:/Windows/System32/cmd.exe");
boost::system::error_code ec;
bp::execute(
bpi::run_exe(p),
bpi::set_cmd_line(L"cmd /c echo --echo-stderr hello"),
bpi::bind_stdout(sink),
bpi::set_on_error(ec)
);
}
bio::file_descriptor_source source(p.source, bio::close_handle);
bio::stream<bio::file_descriptor_source> is(source);
std::string s;
is >> s;
std::cout << s << std::endl;
std::cin.get();
return 0;
}
On windows this works correctly but how to make it crossplatform to work also on Mac and Linux? (I am stupid and do not know how to write one path that would work for any Unix terminal (or at least for Linux Bash and mac default one)) So How to run commandline/terminal utils with Boost.Process 0.5 on Windows and Unix like OSs (better not writing path to terminal each time but just writting app like echo or ping and its arguments)?
...Found related code inside prevoius version:
std::string exe;
std::vector<std::string> args;
#if defined(BOOST_POSIX_API)
exe = "/bin/sh";
args.push_back("sh");
args.push_back("-c");
args.push_back(command);
#elif defined(BOOST_WINDOWS_API)
char sysdir[MAX_PATH];
UINT size = ::GetSystemDirectoryA(sysdir, sizeof(sysdir));
if (!size)
boost::throw_exception(boost::system::system_error(boost::system::error_code(::GetLastError(), boost::system::get_system_category()), "boost::process::launch_shell: GetWindowsDirectory failed"));
BOOST_ASSERT(size < MAX_PATH);
exe = std::string(sysdir) + (sysdir[size - 1] != '\\' ? "\\cmd.exe" : "cmd.exe");
args.push_back("cmd");
args.push_back("/c");
args.push_back(command);
#endif
Under boost.process 0.5 the shell_path() API was introduced so might the following will hook you up
#if defined(BOOST_POSIX_API)
#define SHELL_COMMAND_PREFIX "-c"
#elif defined(BOOST_WINDOWS_API)
#define SHELL_COMMAND_PREFIX "/c"
#endif
filesystem::path shellPath = process::shell_path();
std::string cl = shell_path().string() + " " SHELL_COMMAND_PREFIX " ";
cl += "ping 127.0.0.1";
execute(
set_cmd_line(cl),
throw_on_error()
);
If you really want to hide the #ifdef, I'd go on and edit the boost sources to return also the relevant command prefix (adding new API) , open source after all isn't it ? :).
You could find the relevant sources to edit at boost/process/windows/shell_path.hpp and boost/process/posix/shell_path.hpp

Octave c++ and VS2010

I'm trying to Use Octave with Visual C++.
I have downloaded octave-3.6.1-vs2010-setup-1.exe. Created a new project, added octave include folder to include path, octinterp.lib and octave.lib to lib path, and I added Octave bin folder as running directory.
The program compiles and runs fine except feval function that causes the exception:
Microsoft C++ exception: octave_execution_exception at memory location 0x0012faef
and on Octave side:
Invalid resizing operation or ambiguous assignment to an out-of-bounds array element.
What am I doing wrong?
Code for a standalone program:
#include <octave/octave.h>
#include <octave/oct.h>
#include <octave/parse.h>
int main(int argc, char **argv)
{
if (octave_main (argc, argv, true))
{
ColumnVector NumRands(2);
NumRands(0) = 10;
NumRands(1) = 1;
octave_value_list f_arg, f_ret;
f_arg(0) = octave_value(NumRands);
f_ret = feval("rand",f_arg,1);
Matrix unis(f_ret(0).matrix_value());
}
else
{
error ("Octave interpreter initialization failed");
}
return 0;
}
Thanks in advance.
I tried it myself, and the problem seems to originate from the feval line.
Now I don't have an explanation as to why, but the problem was solved by simply switching to the "Release" configuration instead of the "Debug" configuration.
I am using the Octave3.6.1_vs2010 build, with VS2010 on WinXP.
Here is the code I tested:
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
int main(int argc, char **argv)
{
// Init Octave interpreter
if (!octave_main(argc, argv, true)) {
error("Octave interpreter initialization failed");
}
// x = rand(10,1)
ColumnVector sz(2);
sz(0) = 10; sz(1) = 1;
octave_value_list in = octave_value(sz);
octave_value_list out = feval("rand", in, 1);
// print random numbers
if (!error_state && out.length () > 0) {
Matrix x( out(0).matrix_value() );
std::cout << "x = \n" << x << std::endl;
}
return 0;
}
with an output:
x =
0.165897
0.0239711
0.957456
0.830028
0.859441
0.513797
0.870601
0.0643697
0.0605021
0.153486
I'd guess that its actually stopped pointing at the next line and the error actually lies at this line:
f_arg(0) = octave_value(NumRands);
You seem to be attempting to get a value (which value?) from a vector and then assigning it to element 0 of a vector that has not been defined as a vector.
I don't really know though ... I've never tried writing octave code like that. I'm just trying to work it out by translating the code to standard matlab/octave code and that line seems really odd to me ...