text: const axios = require('axios');
  const tesseract = require("node-tesseract-ocr")
  const sharp = require("sharp")
  const binanceSymbols = require("./binance");
  const moment = require('moment');
  
  async function performOCR(imgBuffer){
      return await tesseract
          .recognize(imgBuffer, {
              lang: "eng",
              // oem: 1,
              // psm: 3,
          })
          .then((text) => {
              return text;
          })
          .catch((error) => {
              console.log(error.message)
          })
  }
  
  function readText(imgBuffer, extract, threshold){
      let pro = sharp(imgBuffer).pause();
      if(extract){
          pro.extract(extract).pause();
      }
      if(threshold){
          pro.threshold(threshold).pause();
      }
      return pro.toBuffer().then((buffer) => {
          return performOCR(buffer);
      })
      .catch((error) => {
          console.log(error.message);
      })
  }
  
  async function recognize(input) {
      const isHTTP = typeof input === "string" && input.match(/^https?:\/\//);
      const start = moment().valueOf();
      if (isHTTP){
          const start = moment().valueOf();
          const response = await axios.get(input,  { responseType: 'arraybuffer' })
          input = Buffer.from(response.data, "utf-8");
          console.log(`Download: ${moment().valueOf() - start}ms`);
      }
      let imageText = await readText(input)
  
      const coins = imageText.ucWords();
      const len = coins.length;
      let hasAnyCoin = false;
      for (let i = 0; i < len; i++) {
          if(binanceSymbols.futures.includes(coins[i])){
              hasAnyCoin = true;
              break;
          }
      }
  
      if (!hasAnyCoin){
          const imgBuffer = await sharp(input)
              .sharpen(2,0,0.5)
              .withMetadata()
              .toBuffer();
          imageText = await performOCR(imgBuffer)
              .then((text) => {
                  console.log(`Sharp OCR At: ${moment().valueOf() - start}ms`);
                  return text;
              })
              .catch((error) => {
                  console.log(error.message)
              })
      }
      return imageText;
  }
  
  module.exports = {
      recognize,
  }