我发现内存从我使用tesseract api运行的非常简单的应用程序泄漏。我知道tesseract api说我必须从GetUTF8Text()删除[] char数组,但它崩溃了我的情况。这是代码块:
int main(int argc, char** argv){
Mat plate_segments = imread(argv[1], 0);
tesseract::TessBaseAPI *myOCR = new tesseract::TessBaseAPI();
myOCR->SetPageSegMode(tesseract::PSM_AUTO);
if (myOCR->Init("./", "newnz+oldnz")) {
std::cerr << "Could not initialize tesseract." << std::endl;
exit(1);
}
myOCR->SetVariable("tessedit_char_blacklist","abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()_+-={}[]|\':;/?.<,>");
myOCR->SetVariable("tessedit_char_whitelist","ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
myOCR->SetImage((uchar*) plate_segments.data,plate_segments.size().width, plate_segments.size().height, plate_segments.channels(), plate_segments.step1());
myOCR->Recognize(0);
char* license_result = myOCR->GetUTF8Text();
printf("OCR output:\n%s", license_result );
delete [] license_result; // CAUSE CRASH
myOCR->Clear();
myOCR->End();
return 0;}
我需要“删除myOCR”吗?我确实尝试了但它也崩溃了。
答案 0 :(得分:0)
尝试
delete myOCR;
myOCR=nullptr;
所以,你不需要打电话
myOCR->Clear();
myOCR->End();
因为删除为你做了! (它的调用~TessBaseAPI())