我正在使用 tesseract OCR 读取名片。 我有内存泄漏,我无法解决它,我不知道如何解决。
在我的代码中...
tesseract->Recognize(NULL);
char* utf8Text = tesseract->GetUTF8Text();
GetUTF8Text() 方法导致内存泄漏。 这是内存泄漏工具的日志:
tesseract::TessBaseAPI::GetUTF8Text()
operator new[](unsigned long) libstdc++.6.dylib
operator new(unsigned long) libstdc++.6.dylib
malloc libsystem_c.dylib
一些内存泄漏后,应用程序崩溃。 GetUTF8Text 在 baseapi.h 文件中。我认为 tessearact 是由 c++ 编写的。我不知道 C++。 谁能帮忙?或者有人有干净的 tesseract 吗?
最佳答案
根据我在 baseapi.h 中找到的文档.
/**
* The recognized text is returned as a char* which is coded
* as UTF8 and must be freed with the delete [] operator.
*/
char* GetUTF8Text();
因此,您需要在完成后删除[]
utf8text
。
tesseract->Recognize(NULL);
char* utf8Text = tesseract->GetUTF8Text();
... //use utf8Text or copy if necessary
delete [] utf8text;
关于iphone - 使用 Tesseract 进行 OCR 会导致 GetUTF8Text 方法出现内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10806491/