Generation

generate functionSun, 16 Apr 2023

输入一张包含文字内容的图像文件,其中的文字数字,并输出到txt文件中

def recognize_text(img): """Recognize text in the image. Args: img: The input image. Returns: Text in the image. """ img = img.convert('L') image = img.resize((200, 80)) image = np.array(image) # 二值化 threshold = 160 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) image = image.point(table, '1') # Normalize the image to 0 and 1. image = image * (1.0 / 255.0) # 黑白反转 image = 1 - image # 切割图片 image = image.reshape([1, 80, 200, 1]) image = image.astype(np.float32) # Predict. out_

Want to kickstart your project?Use the new AI Studio to create your code