Spaces:
Runtime error
Runtime error
Update utility/utils.py
Browse files95 unmodified lines969798991001011026 unmodified lines1091101111121131141151161171181198 unmodified lines12812913013113213313495 unmodified linesreturn final_image# Function for OCR with PaddleOCR, returning both text and bounding boxesdef ocr_with_paddle(img_path):final_text = ''boxes = []6 unmodified linescls_model_dir=os.path.join(os.environ['PADDLEOCR_HOME'], 'whl/cls/ch_ppocr_mobile_v2.0_cls_infer'))# Perform OCR on the imageresult = ocr.ocr(img_path)# Load image with OpenCVimg = cv2.imread(img_path)# Iterate through OCR resultsfor line in result[0]:8 unmodified lines# Save the image with drawn boxes in memory (as a variable)img_with_boxes = img # This image can be used later or saved to disk if neededreturn final_text, img_with_boxes# Function to draw bounding boxes around text#def draw_boxes(image, boxes):95 unmodified lines969798991001011026 unmodified lines1091101111121131141151161171181191201218 unmodified lines13013113213313413513695 unmodified linesreturn final_image# Function for OCR with PaddleOCR, returning both text and bounding boxesdef ocr_with_paddle(img):final_text = ''boxes = []6 unmodified linescls_model_dir=os.path.join(os.environ['PADDLEOCR_HOME'], 'whl/cls/ch_ppocr_mobile_v2.0_cls_infer'))# Check if img is a file path or an image arrayif isinstance(img, str):# If img is a file path, load the imageimg = cv2.imread(img)# Perform OCR (Note: You might need to adapt this based on how PaddleOCR handles input images)result = ocr.ocr(img)# Iterate through OCR resultsfor line in result[0]:8 unmodified lines# Save the image with drawn boxes in memory (as a variable)img_with_boxes = img # This image can be used later or saved to disk if neededreturn final_text, boxes, img_with_boxes# Function to draw bounding boxes around text#def draw_boxes(image, boxes):
utility/utils.py+9-7