title: Converting Mat to PIX to setImage
body: <p>I'm trying to recognize text from a cropped image but I need to pass it from <code>Mat</code> to <code>PIX</code> because X-Platform coding.</p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/8115368/converting-cvmat-for-tesseract">this</a>, <a href="http://hepeng421.blog.163.com/blog/static/11948517201302911311745/" rel="nofollow noreferrer">this</a> and <a href="https://groups.google.com/forum/#!topic/tesseract-ocr/aUH1cuGCYW8" rel="nofollow noreferrer">this</a> </p>
  
  <p>And doing the same function passing <code>Mat</code> and <code>PIX</code> with the same image, results are very very different (with <code>PIX</code> it works perfectly, with <code>Mat</code> it gets messed).</p>
  
  <p>What am I probably doing bad?</p>
  
  <p>Thanks.</p>
  
  <p>PD: (This is one of the code snippets that I'm using)</p>
  
  <pre><code>String imgToString(const char* variables, Mat gray) {
      char *outText;
  
      tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
      if (api-&gt;Init(NULL, "eng")) {
          String returnString = "Could not initialize tesseract.\n";
          fprintf(stderr, "Could not initialize tesseract.\n");
          return returnString;
      }
      api-&gt;SetVariable("tessedit_char_whitelist", variables);
  
      // Open input image with leptonica library
      api-&gt;TesseractRect(gray.data, 1, gray.channels() * gray.size().width, 0, 0, gray.cols, gray.rows);
      // Get OCR result
      outText = api-&gt;GetUTF8Text();
      return outText;
  }
  
  // The one below works fantastic
  
  String imgToString(const char* variables, const char* filename) {
      char *outText;
  
      tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
      if (api-&gt;Init(NULL, "eng")) {
          String returnString = "Could not initialize tesseract.\n";
          fprintf(stderr, "Could not initialize tesseract.\n");
          return returnString;
      }
      api-&gt;SetVariable("tessedit_char_whitelist", variables);
  
      // Open input image with leptonica library
      Pix *image = pixRead(filename);
      api-&gt;SetImage(image);
      // Get OCR result
      outText = api-&gt;GetUTF8Text();
      return outText;
  }
  </code></pre>