gpt-4-0314· openai
Suzhen/CodeChat
基于paddleocr识别营业执照,已经识别出文字的位置的情况下,已经生成图片中文字位置的框图,怎么进一步识别文字所在位置中的文字,写出代码方案
- User
基于paddleocr识别营业执照,已经识别出文字的位置的情况下,已经生成图片中文字位置的框图,怎么进一步识别文字所在位置中的文字,写出代码方案
- Assistant
在已经识别出文字的位置且生成了图片中文字位置的框图的情况下,可以使用PaddleOCR的识别模型来识别文字位置中的文字。以下是一个示例代码方案:
import cv2 import paddleocr import numpy as np def extract_text_boxes(img, box_list): cropped_imgs = [] for box in box_list: pts = np.array(box, dtype=np.int32) x_min, x_max = np.min(pts[:, 0]), np.max(pts[:, 0]) y_min, y_max = np.min(pts[:, 1]), np.max(pts[:, 1]) cropped_img = img[y_min:y_max, x_min:x_max] cropped_imgs.append(cropped_img) return cropped_imgs def main(): # 加载PaddleOCR预训练模型 ocr = paddleocr.PaddleOCR(use_angle_cls=True, lang='ch', rec_model_dir='path/to/rec_model_dir') # 读取营业执照图片 img = cv2.imread('path/to/business_license.jpg') # Retrieve bounding boxes from your previous step box_list = [...] # 请提供生成的文字位置框图 # 提取文字区域图片 cropped_images = extract_text_boxes(img, box_list) # 进行文字识别 for cropped_img in cropped_images: result = ocr.ocr(cropped_img, cls=True) for line in result: box, _, text = line print(f"Text: {text}") print(f"Box: {box}") if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.