예제 #1
0
def capture():

    import cv2

    cap = cv2.VideoCapture(0)

    count = 0
    while (True):
        ret, img = cap.read()
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        cv2.imshow("img", img)
        k = cv2.waitKey(30) & 0xFF

        if k == ord('q'):

            cv2.imwrite("C:/Users/pc1/Desktop/" + str(count) + "id.png", img)

            a = "C:/Users/pc1/Desktop/" + str(count) + "id.png"

            count = count + 1
        #break
        elif k == 27:
            break

    cap.release()
    cv2.destroyAllWindows()
    import ocrspace
    api = ocrspace.API()

    api = ocrspace.API('enter your OCR-API', ocrspace.Language.Croatian)

    api.ocr_file(a)

    a = api.ocr_file(open(a, 'rb'))
    textvalue.set(a)
예제 #2
0
 def __init__(self, image_adrs='', file_or_url=None):
     """
     :param image_adrs: path to an image given by the user
     :param file_or_url: str of the type of the image_adrs -> URL or FILE
     """
     self.api = ocrspace.API()
     self.file_or_url = file_or_url
     self.image_adrs = image_adrs
     self.txt_from_image = ''
예제 #3
0
파일: battery.py 프로젝트: jess0601/Yalebot
class Battery(ImageModule):
    DESCRIPTION = "Is your battery sinfully low?"
    PERCENTAGE_RE = re.compile(r"(\d+) *%")
    api = ocrspace.API()

    def response(self, query, message):
        source_url = self.get_source_url(message)
        string = self.api.ocr_url(source_url)
        print("Image text: " + string)
        string = string.replace("0/0", "%")
        percentages = self.PERCENTAGE_RE.search(string).groups()
        if len(percentages) > 0:
            percentage = int(percentages[0])
            if percentage > 50:
                return f"You good. ({percentage}%)"
            else:
                return f"CHARGE YA GOTDAMN PHONE ({percentage}%)"
        else:
            return "No percentage found."
예제 #4
0
def dataProcessing(url):
  ocrStuff = ocrspace.API(OCRKey, ocrspace.Language.English)
  rawData = ocrStuff.ocr_url(url).split('\r\n')
  FamilyNameIndex = [i for i, s in enumerate(rawData) if 'Family (C' in s][0]
  ActivityIndex = [i for i, s in enumerate(rawData) if 'Activity (?' in s][0]
  ParticipateIndex = [i for i, s in enumerate(rawData) if 'Participate' in s][0]

  myFamily = rawData[FamilyNameIndex + 1:ActivityIndex]
  myFamilyNamesOnly = []

  for i in myFamily:
    myStr = i.split('(')[0].replace("(","")
    myStr = myStr.rstrip()
    myFamilyNamesOnly.append(myStr.replace(" ","_"))

    myParticipation = rawData[ParticipateIndex + 1:-1]
  
  result = dict(zip(myFamilyNamesOnly, myParticipation))
  result = nameFixer(result)
  return result
예제 #5
0
import ocrspace

api = ocrspace.API()
print(
    api.ocr_url(
        'https://images-na.ssl-images-amazon.com/images/I/71ovNJN1URL._SL1244_.jpg'
    ))
print(
    api.ocr_url(
        'https://upload.wikimedia.org/wikipedia/commons/thumb/f/ff/Solid_blue.svg/225px-Solid_blue.svg.png'
    ))
예제 #6
0
Created on Sun Aug  4 00:06:17 2019

@author:

This is example code to extract chinese subtitles from images
"""

import ocrspace
import time

# limit of 500 number of times within 86400
# api = ocrspace.API()
# Or if you have an API key or desired language, pass those:
# ocrspace.Language.Croatian

api = ocrspace.API('erasedApiKey', 'chs')
filelist = []
myString = ""
with open('file.txt', 'r') as f:
    for lin in f:
        filelist.append(lin.strip())

for imagefile in filelist:
    currentText = api.ocr_file(imagefile).rstrip().replace("\n", "")
    # if image has two lines of text then join them as one
    currentText = " ".join(currentText.splitlines())
    # if unrecongizable text
    if currentText == "":
        currentText = 'no text here'
    time.sleep(4)
    with open("subtitle.txt", "a", encoding='utf-8') as resfile:
예제 #7
0
import ocrspace
api = ocrspace.API()
# Or if you have an API key or desired language, pass those:
api = ocrspace.API(open('ocr.key').read(), ocrspace.Language.Croatian)
# print(api.ocr_file('Capture.PNG'))
print(api.ocr_file('handouts/BITS_F311_1332.pdf'))
예제 #8
0
from flask import *
from flask_bootstrap import Bootstrap
import ocrspace
from adds import *
import os

API_KEY = '790b71df8188957'
app = Flask(__name__)
bootstrap = Bootstrap(app)
UPLOAD_FOLDER = '/files'
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'}
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
api = ocrspace.API(api_key=API_KEY, language=ocrspace.Language.Russian)


def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/work', methods=['GET', 'POST'])
def work():
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_file(file.filename):
            fish = bool(request.form.getlist('fish'))
예제 #9
0
    image = vision.Image()
    image.source.image_uri = uri

    response = client.text_detection(image=image)
    texts = response.text_annotations
    parsed_text = ''
    for text in texts:
        parsed_text = text.description
        break;
    if response.error.message:
        return response.error.message
    return parsed_text


ocr_space_key = 'e40860ac2688957'
api = ocrspace.API(ocr_space_key, ocrspace.Language.Croatian)

def ocr_with_library(url):
    api.ocr_url(url)

def ocr_space_url(url):
    payload = {'url': url,
               'apikey': ocr_space_key,
               'filetype': 'png'
               }
    r = requests.post('https://api.ocr.space/parse/image',
                      data=payload,
                      )
    return r.content.decode()

def processOCRQueue(queue_name):
예제 #10
0
# 2 - based on that capture, retrieve opp name, using OCR
# 3 - then look for a match in the excel file
#     if any info is available, it text-to-speeches
#     it out (as the game finishes to load or has just started)

###############################
#libraries
import pandas as pd
import pyscreenshot           #library for screenshots
import ocrspace               #library for OCR, it is online, i got a free license
from pynput import keyboard   #library for keyboard events
import pyttsx3                #library for text to speech

###############################
#Constants
OCR_API = ocrspace.API("d92462a6fd88957") #key to use API
MY_OWN_NAME = "FREDOKUN"                #my login
OPP_COL_TITLE = "Opponent"              #title containing the name
#File with meta data
OPP_FILE = 'M:/Installed Apps/blizz/Warcraft III/Opp-history.xlsx'
DATA_WORKSHEET = 'Data'                 #data worksheet
IM_BUFF = 'imBuff.png'                  #file generated with the screenshot
STR_DELIMITER = '\n'         #character in the returned string between player names
NOT_ABLE_TO_READ = "not able to read image"

###############################
#global counter
#because of keyboard events bug
pressAndReleaseCounter = 0

###############################
예제 #11
0
if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='Issue parking entrance permission.')
    parser.add_argument('pictures',
                        metavar='<picture path>',
                        type=str,
                        nargs='+',
                        help='Picture containing the car plate')
    parser.add_argument('-v',
                        dest='verbose',
                        action='store_const',
                        const=True,
                        default=False,
                        help='add verbosity')
    args = parser.parse_args()

    logger = ParkingLogger(db_name=parking_db,
                           collection_name=parking_log_collection)
    image_to_text_api = ocrspace.API(api_key=personal_user_api_key)

    for pic in args.pictures:
        car_plate = image_to_text_api.ocr_file(pic)
        if car_plate:
            issue_permission(logger, car_plate, verbose=args.verbose)
        else:
            logger.info(car_plate,
                        False,
                        reason="unable to extract the car plate",
                        verbose=args.verbose)