Spaces:
Runtime error
Runtime error
Update utility/utils.py
Browse files95 unmodified lines96979899991001011026 unmodified lines1091101111121131141151161121131141151161171181191201218 unmodified lines13013113213113313413513695 unmodified lines return final_image
# Function for OCR with PaddleOCR, returning both text and bounding boxesdef ocr_with_paddle(img_path):def ocr_with_paddle(img): final_text = '' boxes = []
6 unmodified lines cls_model_dir=os.path.join(os.environ['PADDLEOCR_HOME'], 'whl/cls/ch_ppocr_mobile_v2.0_cls_infer') )
# Perform OCR on the image result = ocr.ocr(img_path)
# Load image with OpenCV img = cv2.imread(img_path) # Check if img is a file path or an image array if isinstance(img, str): # If img is a file path, load the image img = 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 results for 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 needed
return final_text, img_with_boxes return final_text, boxes, img_with_boxes
# Function to draw bounding boxes around text#def draw_boxes(image, boxes):utility/utils.py+9-7