Пример #1
0
def button(update, context):
    global query
    query = update.callback_query
    query.answer()
    query.edit_message_text(text="Selected Language is: {}".format(query.data))

    configuration = cloudmersive_ocr_api_client.Configuration()
    #Enter Your cloudmersive api key in place of  os.environ.get(...........)
    configuration.api_key['Apikey'] = os.environ.get("CLOUDMERSIVE_API", "")
    api_instance = cloudmersive_ocr_api_client.ImageOcrApi(
        cloudmersive_ocr_api_client.ApiClient(configuration))
    try:
        lang = query.data
        api_response = api_instance.image_ocr_post(filename, language=lang)
        confidence = api_response.mean_confidence_level
        context.bot.send_message(chat_id=chat_id,
                                 text="Confidence : " + str(confidence * 100) +
                                 "% \nExtracted text:\n")
        context.bot.send_message(chat_id=chat_id,
                                 text=api_response.text_result)
    except ApiException as e:
        context.bot.send_message(
            chat_id=chat_id,
            text=
            "Exception when calling ImageOcrApi->image_ocr_photo_to_text: %s\n"
            % e)
        try:
            os.remove('testing.jpg')
        except Exception:
            pass
    return button
def process_ocr(image):
    API_KeY = "a29a390d-f62b-4d96-8dc2-2c6039bf8626"
    api_instance = cloudmersive_ocr_api_client.ImageOcrApi()

    api_instance.api_client.configuration.api_key = {}
    api_instance.api_client.configuration.api_key['Apikey'] = API_KeY

    api_response = api_instance.image_ocr_post(image)
    return str(api_response)
Пример #3
0
def start(update, context):
    file_id = update.message.photo[-1].file_id
    newFile = context.bot.get_file(file_id)
    newFile.download("test.jpg")
    update.message.reply_text("Got Image")
    filename = "test.jpg"
    configuration = cloudmersive_ocr_api_client.Configuration()
    api = os.environ.get("API_KEY")
    configuration.api_key['Apikey'] = api
    api_instance = cloudmersive_ocr_api_client.ImageOcrApi(
        cloudmersive_ocr_api_client.ApiClient(configuration))
    api_response = api_instance.image_ocr_photo_to_text(filename)
    result = api_response.text_result + "\n"
    url = "https://www.google.com/search?q=" + api_response.text_result
    update.message.reply_text(f'{result}<a href="{url}">Click here</a>',
                              parse_mode=ParseMode.HTML)
Пример #4
0
def extract(image_file):
    api_instance = cloudmersive_ocr_api_client.ImageOcrApi()
    api_instance.api_client.configuration.api_key = {}
    api_instance.api_client.configuration.api_key[
        'Apikey'] = 'b0d87b4d-65ec-46ab-92de-73e12e187b41'
    try:
        # Converts an uploaded image in common formats such as JPEG, PNG into text via Optical Character Recognition.

        api_response = api_instance.image_ocr_post(image_file,
                                                   recognition_mode='Normal',
                                                   preprocessing='Auto')

        return api_response.text_result
    except ApiException as e:
        print("Exception when calling ImageOcrApi->image_ocr_post: %s\n" % e)
        return ''
Пример #5
0
def ocr(imagefile):
    # create an instance of the API class
    api_instance = cloudmersive_ocr_api_client.ImageOcrApi(
        cloudmersive_ocr_api_client.ApiClient(configuration))
    image_file = imagefile  # file | Image file to perform OCR on.  Common file formats such as PNG, JPEG are supported.
    #language = '' # str | Optional, language of the input document, default is English (ENG).  Possible values are ENG (English), ARA (Arabic), ZHO (Chinese - Simplified), ZHO-HANT (Chinese - Traditional), ASM (Assamese), AFR (Afrikaans), AMH (Amharic), AZE (Azerbaijani), AZE-CYRL (Azerbaijani - Cyrillic), BEL (Belarusian), BEN (Bengali), BOD (Tibetan), BOS (Bosnian), BUL (Bulgarian), CAT (Catalan; Valencian), CEB (Cebuano), CES (Czech), CHR (Cherokee), CYM (Welsh), DAN (Danish), DEU (German), DZO (Dzongkha), ELL (Greek), ENM (Archaic/Middle English), EPO (Esperanto), EST (Estonian), EUS (Basque), FAS (Persian), FIN (Finnish), FRA (French), FRK (Frankish), FRM (Middle-French), GLE (Irish), GLG (Galician), GRC (Ancient Greek), HAT (Hatian), HEB (Hebrew), HIN (Hindi), HRV (Croatian), HUN (Hungarian), IKU (Inuktitut), IND (Indonesian), ISL (Icelandic), ITA (Italian), ITA-OLD (Old - Italian), JAV (Javanese), JPN (Japanese), KAN (Kannada), KAT (Georgian), KAT-OLD (Old-Georgian), KAZ (Kazakh), KHM (Central Khmer), KIR (Kirghiz), KOR (Korean), KUR (Kurdish), LAO (Lao), LAT (Latin), LAV (Latvian), LIT (Lithuanian), MAL (Malayalam), MAR (Marathi), MKD (Macedonian), MLT (Maltese), MSA (Malay), MYA (Burmese), NEP (Nepali), NLD (Dutch), NOR (Norwegian), ORI (Oriya), PAN (Panjabi), POL (Polish), POR (Portuguese), PUS (Pushto), RON (Romanian), RUS (Russian), SAN (Sanskrit), SIN (Sinhala), SLK (Slovak), SLV (Slovenian), SPA (Spanish), SPA-OLD (Old Spanish), SQI (Albanian), SRP (Serbian), SRP-LAT (Latin Serbian), SWA (Swahili), SWE (Swedish), SYR (Syriac), TAM (Tamil), TEL (Telugu), TGK (Tajik), TGL (Tagalog), THA (Thai), TIR (Tigrinya), TUR (Turkish), UIG (Uighur), UKR (Ukrainian), URD (Urdu), UZB (Uzbek), UZB-CYR (Cyrillic Uzbek), VIE (Vietnamese), YID (Yiddish) (optional)
    #preprocessing = 'preprocessing_example' # str | Optional, preprocessing mode, default is 'Auto'.  Possible values are None (no preprocessing of the image), and Auto (automatic image enhancement of the image before OCR is applied; this is recommended). (optional)

    try:
        # Convert a scanned image into words with location
        api_response = api_instance.image_ocr_photo_to_text(image_file,
                                                            language='HIN')
        print(api_response.text_result)
    except ApiException as e:
        print(
            "Exception when calling ImageOcrApi->image_ocr_image_lines_with_location: %s\n"
            % e)
Пример #6
0
def receive(update,context):
    filename = "photo.jpg"
    fileid = update.message.photo[-1].file_id
    received = context.bot.get_file(fileid)
    received.download(filename)
    update.message.reply_text("Image received!\n🥰\n")
    api_instance =cloudmersive_ocr_api_client.ImageOcrApi()
    api_instance.api_client.configuration.api_key = {}
    api_instance.api_client.configuration.api_key['Apikey'] = CLOUDMERSIVE_API_KEY
    try:
        api_response = api_instance.image_ocr_post(filename)
        sucs_percent = api_response.mean_confidence_level
        result = api_response.text_result
        update.message.reply_text("<b>Success Percentage :</b> "+str(sucs_percent*100)+"<b>%\nThe text from the Image :</b> \n"'<pre>'+str(result)+'</pre>', parse_mode = 'HTML')
    except Exception as e:
        print_exc
        update.message.reply_text("Gomen! Error Occured.\n<b>Error Details :</b> "+str(e),parse_mode='HTML')
Пример #7
0
def receipt():    
    api_instance = cloudmersive_ocr_api_client.ImageOcrApi()

    api_instance.api_client.configuration.api_key = {}
    api_instance.api_client.configuration.api_key['Apikey'] = 'API_KEY'

    data = json.loads(request.data)
    with open("receipt.jpg", "wb") as fh:
        fh.write(base64.b64decode(data))

    my_path = os.path.abspath(os.path.dirname(__file__))
    image_file = os.path.join(my_path, "receipt.jpg")

    try:
    # Convert a photo of a document into text
        api_response = api_instance.image_ocr_post(image_file)
    except ApiException as e:
         print("Exception when calling ImageOcrApi->image_ocr_photo_to_text: %s\n" % e)

    return jsonify(api_response.text_result)
Пример #8
0
def search(update, context):
    filename = "test.jpg"
    file_id = update.message.photo[-1].file_id
    newFile = context.bot.get_file(file_id)
    print(update.message.photo)
    newFile.download(filename)
    update.message.reply_text("I got your image...\nJust wait few seconds...")
    api_instance = cloudmersive_ocr_api_client.ImageOcrApi()
    api_instance.api_client.configuration.api_key = {}
    api_instance.api_client.configuration.api_key[
        'Apikey'] = CLOUDMERSIVE_API_KEY
    try:
        api_response = api_instance.image_ocr_post(filename)
        print(api_response)
        update.message.reply_text(
            '`' + str(api_response.text_result) + '`',
            parse_mode=ParseMode.MARKDOWN,
            reply_to_message_id=update.message.message_id)

    except Exception as e:
        print_exc()
        update.message.reply_text("error occured" + e)
Пример #9
0
def convert_image(update, context):
    print(update.message)
    filename = "test.jpg"
    file_id = update.message.photo[-1].file_id
    newFile = context.bot.get_file(file_id)
    print(update.message.photo)
    newFile.download(filename)

    update.message.reply_text("I got image :)")
    # Simple image to string
    # try:
    #     #pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'
    #     extrated_string = pytesseract.image_to_string(Image.open(filename))
    # except Exception:
    #     print_exc()
    ''' CLOUDMERSIVE  cloud code  '''

    # try:
    #     # Recognize a photo of a receipt, extract key business information
    #     api_response = api_instance.image_ocr_photo_recognize_receipt(image_file, recognition_mode=recognition_mode, language=language, preprocessing=preprocessing)
    #     print(api_response)
    # except ApiException as e:
    #     print("Exception when calling ImageOcrApi->image_ocr_photo_recognize_receipt: %s\n" % e)
    ''' Cyberboy code for API '''

    api_instance = cloudmersive_ocr_api_client.ImageOcrApi()
    api_instance.api_client.configuration.api_key = {}
    api_instance.api_client.configuration.api_key[
        'Apikey'] = CLOUDMERSIVE_API_KEY
    try:
        api_response = api_instance.image_ocr_post(filename)
        print(api_response)
        confidence = api_response.mean_confidence_level
        update.message.reply_text("Confidence: " + str(confidence) +
                                  "\nExtracted text is : " +
                                  api_response.text_result)
    except ApiException:
        print_exc()
Пример #10
0
from telethon.tl import functions
from telethon.tl import types
from telethon.tl.types import *

from julia import *

from julia.events import register

client = MongoClient()
client = MongoClient(MONGO_DB_URI)
db = client["missjuliarobot"]
approved_users = db.approve

configuration = cloudmersive_ocr_api_client.Configuration()
configuration.api_key["Apikey"] = VIRUS_API_KEY
api_instance = cloudmersive_ocr_api_client.ImageOcrApi(
    cloudmersive_ocr_api_client.ApiClient(configuration))


async def is_register_admin(chat, user):
    if isinstance(chat, (types.InputPeerChannel, types.InputChannel)):
        return isinstance(
            (await
             tbot(functions.channels.GetParticipantRequest(chat,
                                                           user))).participant,
            (types.ChannelParticipantAdmin, types.ChannelParticipantCreator),
        )
    if isinstance(chat, types.InputPeerChat):
        ui = await tbot.get_peer_id(user)
        ps = (await tbot(functions.messages.GetFullChatRequest(chat.chat_id)
                         )).full_chat.participants.participants
        return isinstance(
Пример #11
0
from flask import session

import random
import string
import asyncio

import cloudmersive_ocr_api_client
from cloudmersive_ocr_api_client.rest import ApiException

# settigns
import settings
from werkzeug.utils import secure_filename
from flask.json import jsonify

# ocr con cloudmersive
api_instance = cloudmersive_ocr_api_client.ImageOcrApi()

api_instance.api_client.configuration.api_key = {}
api_instance.api_client.configuration.api_key["Apikey"] = os.environ.get(
    "API_KEY_OCR")

# configuracion de la app
app = Flask(__name__)
app.secret_key = os.urandom(42)
CORS(app)

# limite 16 megas del fichero
app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024
app.config["ALLOWED_IMAGE_EXTENSIONS"] = ["JPEG", "JPG", "PNG"]

CARPETA_SUBIDAS = os.path.abspath("static/images/archivos_subidos")