title: How to solve Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) using OCR?
body: <p>I am stuck with following error:</p>
  
  <blockquote>
    <p>--> Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) </p>
  </blockquote>
  
  <p>In this particular line of code: </p>
  
  <blockquote>
    <p>--> <code>outText = string(ocr-&gt;GetUTF8Text());</code></p>
  </blockquote>
  
  <p>Here is the complete code:</p>
  
  <pre><code>// OCR Process Begins
  string outText;
  string imPath = argv[2];
  // Create Tesseract object
  tesseract::TessBaseAPI *ocr = new tesseract::TessBaseAPI();
  // Initialize tesseract to use English (eng) and the LSTM OCR engine.
  ocr-&gt;Init(NULL, "eng", tesseract::OEM_LSTM_ONLY);
  // Set Page segmentation mode to PSM_AUTO (3)
  ocr-&gt;SetPageSegMode(tesseract::PSM_AUTO);
  // Open input image using OpenCV
  Mat im = cv::imread(imPath, IMREAD_COLOR);
  // Set image data
  ocr-&gt;SetImage(im.data, im.cols, im.rows, 3, static_cast&lt;int&gt;(im.step));
  // Run Tesseract OCR on image
  outText = string(ocr-&gt;GetUTF8Text());
  // print recognized text
  cout &lt;&lt; outText &lt;&lt; endl; // Destroy used object and release memory ocr-&gt;End();
  waitKey();
  //return 0 instead of return EXIT_SUCCESS
  return EXIT_SUCCESS;
  </code></pre>
  
  <p>This is a list of errors I'm getting.</p>
  
  <blockquote>
    <p>Error in pixCreateHeader: width must be > 0 Error in pixCreateNoInit: pixd not made Error in pixCreate: pixd not made Error in pixGetData: pix not defined Error in pixGetWpl: pix not defined Error in pixGetDimensions: pix not defined Error in pixGetColormap: pix not defined Error in pixCopy: pixs not defined Error in pixGetDepth: pix not defined Error in pixGetWpl: pix not defined Error in pixGetYRes: pix not defined Error in pixClone: pixs not defined Please call SetImage before attempting recognition. (lldb)</p>
  </blockquote>
  
  <p>Thanks in advance</p>