Exemplo n.º 1
0
def cognitive_ocr_proc(bot, update):
    user = update.message.from_user
    photo_file = bot.get_file(update.message.photo[-1].file_id)
    photo_file.download("test_photo.jpg")
    #logger.info("Photo of %s: %s" % (user.first_name, 'test_photo.jpg'))
    output = ocr.OCR('test_photo.jpg')
    update.message.reply_text(output)
    return ConversationHandler.END
Exemplo n.º 2
0
 def choosePreProcess(self, image):
     o = ocr.OCR()
     img = self.basicPreProcess(image)
     score1 = o.getImageScore(img)
     img = self.fullPreProcess(image)
     score2 = o.getImageScore(img)
     print('score1: ' + str(score1))
     print('score2: ' + str(score2))
     if score1>score2:
         method = self.basicPreProcess
     else:
         method = self.fullPreProcess
     return method
Exemplo n.º 3
0
def main(imageName):
    fsize = os.path.getsize(imageName)
    fsize /= 1024 * 1024
    print(fsize)
    if fsize > 1.:
        compressImage(imageName)
    imgOCR = ocr.OCR(imageName)
    print(type(imgOCR))
    print(json.dumps(imgOCR, indent=2))
    infoList = []
    for line in imgOCR["data"]["block"][0]["line"]:
        infoList.append(line["word"][0]["content"])
    genExcel(infoList, "1.excel")
Exemplo n.º 4
0
def identify_stake():
    if request.method == 'POST':
        if 'imgData' in request.values:
            ocr_obj = ocr.OCR(request.values['imgData'])
            data = ocr_obj.identify_stake()
            print data
            return jsonify(ocr=data)
        else:
            data = {'stake': ''}
            return jsonify(ocr=data)
    else:
        #dummy data for dev
        data = {'stake': '25.00'}
        return jsonify(ocr=data)
Exemplo n.º 5
0
def analyze_bet():
    if request.method == 'POST':
        if 'imgData' in request.values:
            ocr_obj = ocr.OCR(request.values['imgData'])
            data = ocr_obj.analyze_bet()
            print data
            return jsonify(ocr=data)
        else:
            data = {'time': '', 'selection': '', 'odds': ''}
            return jsonify(ocr=data)
    else:
        #dummy data for dev
        data = {'time': '14:35', 'selection': 'Kauto Star', 'odds': '21/20'}
        return jsonify(ocr=data)
Exemplo n.º 6
0
 def __init__(self, rootPath):
     self.__rootPath = rootPath
     self.__heights = [364, 444, 524, 604, 684, 764, 844]
     self.__widths = [4, 124, 244, 364, 484, 604]
     self.__mid_h = [399, 479, 559, 639, 719, 799, 879]
     self.__mid_w = [59, 179, 299, 419, 539, 659]
     self.__round_h = 70
     self.__round_w = 405
     self.__widthSize = 115
     self.__heightSize = 75
     self.__OCR = ocr.OCR()
     self.__state = np.zeros((7, 6), dtype=np.int)
     self.__prevState = np.zeros((7, 6), dtype=np.int)
     self.__gameRound = 0
     self.__util = utils.Utils(rootPath)
Exemplo n.º 7
0
    def __init__(self):
        self.logger = logging.getLogger(self.__class__.__name__)
        self.ocr = ocr.OCR()
        self.wb = query.WebQuery()
        self.data = {}
        self.running = False
        self.exiting = False

        signal.signal(signal.SIGINT, self.signal_handler)
        signal.signal(signal.SIGTERM, self.signal_handler)
        signal.signal(signal.SIGHUP, self.signal_handler)

        self.t = threading.Thread(target=self.getInput)
        self.t.setDaemon(True)
        self.t.start()

        # start main capture loop
        self.run_loop()
Exemplo n.º 8
0
 def readFile(self):
     # Files that we can't easily read are ignored
     if (self.type == "archive" or self.type == "misc."
             or self.type == "audio" or self.type == "video"
             or self.type == "complicated"):
         return None
     # .pdf: use tika instead of Pandoc
     elif (self.extension == "pdf"):
         return parser.from_file(self.path)["content"]
     # Python can read some files natively
     elif (self.extension == "txt" or self.extension == "srt"
           or self.type == "programming"):
         with open(self.path) as f:
             return f.read()
     # Images: use OCR script
     elif (self.type == "image"):
         return ocr.OCR(self.path)
     # Documents: use Pandoc
     else:
         output = pypandoc.convert_file(self.path, 'plain')
         return output
Exemplo n.º 9
0
    def __init__(self, config_file):
        self.logger = logging.getLogger(self.__class__.__name__)
        self.ocr = ocr.OCR(config_file)
        self.wb = query.WebQuery()
        self.data = {}
        self.running = False
        self.exiting = False

        # create working directories if they don't already exist
        self.create_directory(kResultsFolder)
        self.create_directory(kImagesFolder)

        signal.signal(signal.SIGINT, self.signal_handler)
        signal.signal(signal.SIGTERM, self.signal_handler)
        signal.signal(signal.SIGHUP, self.signal_handler)

        self.t = threading.Thread(target=self.getInput)
        self.t.setDaemon(True)
        self.t.start()

        # start main capture loop
        self.run_loop()
Exemplo n.º 10
0
# while True:
#     dcObj.Rectangle((int(left+first_art_x), int(top+first_art_y), int(left+first_art_x)+10, int(top+first_art_y)+10))
#     dcObj.Rectangle((int(left+art_info_left), int(top+art_info_top), int(left+art_info_left)+10, int(top+art_info_top)+10))
#     dcObj.Rectangle((int(left+art_info_left+art_info_width), int(top+art_info_top+art_info_height), int(left+art_info_left+art_info_width)+10, int(top+art_info_top+art_info_height)+10))
#     dcObj.Rectangle((int(left+scroll_keypt_x), int(top+scroll_keypt_y), int(left+scroll_keypt_x)+10, int(top+scroll_keypt_y)+10))
#     win32gui.InvalidateRect(hwnd, monitor, True)

# # star color=255,204,50
# scroll_fin_keypt_x = 358
# scroll_fin_keypt_y = 320

# margin near level number, color=233,229,220

# initialization
ocr_model = ocr.OCR(scale_ratio=game_info.scale_ratio,
                    model_weight=os.path.join(bundle_dir,
                                              'mn_model_weight.h5'))
art_id = 0
saved = 0
skipped = 0
failed = 0
star_dist = [0, 0, 0, 0, 0]
star_dist_saved = [0, 0, 0, 0, 0]

os.makedirs('artifacts', exist_ok=True)

input('请打开圣遗物背包界面,最好翻到圣遗物列表最上面。按回车继续')
print('---------------------------------')
if game_info.incomplete_lastrow:
    input(
        f'检测到圣遗物背包有{game_info.art_rows}行{game_info.art_cols}列,但最后一行不完整可能会影响自动翻页效果,建议更改分辨率到16:9'
Exemplo n.º 11
0
 def readimage(self, address):  # read character from image
     self.ocr = ocr.OCR()
     return self.ocr.readimage(address)
Exemplo n.º 12
0
    #                 plt.show()
    #             i+=1
    #     except tf.errors.OutOfRangeError:
    #         print('done!')
    #     finally:
    #         coord.request_stop()
    #     coord.join(threads)

    # run_training()
    # test('./test/30.png')
    # tf.reset_default_graph()

    # 测试准确率
    # start = time.clock()
    out = []
    ocr = ocr.OCR()
    i = 0
    for image in image_list:
        if (i == 7000):
            break
        out.append(ocr.test(image))
        # tf.reset_default_graph()
        i = i + 1
    # print_time()
    i = 0
    j = 0
    for i in range(len(label_list)):
        if (i == 7000):
            break
        if (out[i] == label_list[i]):
            j = j + 1